Sunday, May 23, 2021

Five ways to generate a random text on Linux

Just for fun- listing some ways to generate a random text in Linux.

1. Using builtin RANDOM function in bash. It generates random number less than 32767. Concat two of these numbers and convert the first 8-bytes of result into a base64 value. Gives a mix of upper and lowercase plus digits:
bjha@dell-3460:~$ echo ${RANDOM}${RANDOM} | head -c8 | base64
MzE3MTgyNzA=

2. Using /dev/urandum. Pick first 8-bytes of random data and encode as base64:

bjha@dell-3460:~$ head -c8 /dev/urandom | base64
OiC6S52snTk=

3. Similar to the previous one, but, using dd cmd instead of head. Read 8-bytes from urandum and base64 encode it:

bjha@dell-3460:~$ dd if=/dev/urandom bs=8 count=1 | base64
fB1s3WlcqdY=
...

4. Using date cmd. Print the date as epoch seconds (%s) and base64 encode the result

bjha@dell-3460:~$ date '+%s' | base64
MTYyMTc4NzczMwo=

5. Using uuidgen cmd

bjha@dell-3460:~$ uuidgen

7be03091-e088-4cef-ab2a-e484ac63d336 

          Friday, July 03, 2020

          Migrating (Disk Cloning) from HDD to a smaller SSD with Dual Boot Setup

          Okay! This is a post after a long hiatus. Covid-19 pandemic and lockdown provided enough spare time to do some upgrade on my six year old Dell Latitude. It has a dual boot setup with Ubuntu 18.04 and Windows 10 Pro on different partitions.

          My existing HDD was a 1TB sata drive harvested from another old laptop that I had upgraded a few years ago. This HDD had  six partitions roughly as follows. None of the partitions were exhausted in space.


          1. UEFI Boot - 512M (If you are not using UEFI boot, then this post will not work)
          2. ext4 - Ubuntu - 600G
          3. Microsoft Reserved (msftres) - 512M
          4. Windows Recovery (NTFS) - 1024M
          5. NTFS - Main Windows - 300G
          6. Unallocated - nnnM


          I wanted to migrate to a a new 500G SSD. Obviously, I had to shrink the partitions appropriately to accommodate in the new smaller SSD. I followed the steps mentioned here Ubuntu Howto.



          In this post no point of repeating above steps all over again. I will only mention things that didn't work and I had to adjust or redo.

          1. Ensure you have Ubuntu Live USB and Windows 10 recovery USB handy
          2. Partition #3 and #4 above is not needed and can be deleted altogether
          3. Msdos MBR doesn't allow more than four primary partitions. Learnt hard way!!
          4. On new SSD (step#7 in the above article link) don't choose Msdos MBR in Diskpart. Use GPT (Guid Partion table). 
            1. I had to use gdisk to convert MBR to GPT 
          5. Mark first UEFI Partition as bootable in Diskpart
          6. Leave at least 1M unallocated space at the end of the new SSD for GPT to write metadata. Learnt it hard way.
          7. Fix Grub2- I was unable to boot successfully at first attempt with new SSD. Use Boot-Repair to fix the issue
          8. I had to fix boot for windows 10 also. Use windows 10 recovery with diskpart and bootrec to fix windows 10 boot issues.
          9. Have plenty of patience and another device with internet connectivity to research issues :-)

          That's all. Post questions and comments, if you want to know more

          Cheers!


          Wednesday, March 13, 2019

          Note to Self- No Personal Home Directory Encryption

          As of Ubuntu 16.04 LTS  on my Dell

          bjha@bjha-Latitude-3460:~$ uname -a
          Linux bjha-Latitude-3460 4.15.0-46-generic #49~16.04.1-Ubuntu SMP Tue Feb 12 17:45:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

          home directory encryption using ecryptfs doesn't work cleanly. It interferes with hibernation and suspend, weird login behaviour (correct password doesn't work in Gnome after wakeup) etc. Some of the issues are well discussed over the internet. The pain involved to get it right is not worth the return. Better off with full-disk encryption or something similar if a strong security measure is needed.

          How to stop using this feature?

          Following link discusses some steps. However, it didn't work for me cleanly. Had to rebuild my home directory from a secondary backup. Also, refer this link how to stop using encrypted swap.