Installing CentOS LiveCD to a USB flash drive

I had a request from a client to set up Linux on a USB flash drive so that they can easily go from machine to machine and boot up the box fairly easily to run some benchmarks. It took some time to figure it out but once I did, I had it down to a science. The requirements were to have a portable Linux install on a USB falsh drive that would work on all hardware including MAC which I was told required EFI. The idea is that the client can take their desktop with them. No matter what computer we plug the USB flash drive into, we can easily boot the computer off of it. Any files that were saved to the desktop should be there on the next boot. It also needed to have a 32 and 64 bit version. By default I go with CentOS as it has never done me wrong. CentOS7 is only available in 64 bit. In order to keep things simple we used CentOS6 for both the 32 and 64 bit versions. I created the drives via a CentOS7 Desktop. I recommend using a 8GB or 16GB drive and NOT larger. I say this because if you want to take an image of the flash drive or write it back it will take that much longer. Below are the steps taken to set up the flash drives.

  1.  cd /usr/src ; http://mirror.san.fastserv.com/pub/linux/centos/6/isos/x86_64/CentOS-6.7-x86_64-LiveCD.iso
  2. Insert the flash drive and verify the drive letter with fdisk -l. We don’t want to over write the wrong disk. For our example we will use /dev/sdx. Once inserted make sure the system did not auto mount the disk. If it did un-mount it umount -l /dev/sdx
  3. Create the partition with parted
    1.  parted /dev/sdx
    2. toggle 1 boot
    3. quitf
  4. Write the image to the USB drive:  livecd-iso-to-disk –delete-home –home-size-mb 4094 –format –reset-mbr –efi –unencrypted-home –overlay-size-mb 4094 /usr/src/CentOS-6.7-x86_64-LiveCD.iso /dev/sdx1
    This will:

    1. –delete-home = Delete the home directory if there is one.
    2. –home-size-mb = This sets the home directory to 4094MB.
    3. –format = Format the device
    4. –reset-mbr = Reset the master boot record
    5. –efi = Enable EFI
    6. –unecrypted-home = Leave the home disk un-encrypted. Over all the best idea is to encrypt it.
    7. –overlay-size-mbb = Set the overlay size. If this is not set then anything saved to the disk (i.e. the desktop or any dir part of the running OS) will not be saved.

When ever I create a bootable flash drive I always take an image of it. This is useful for instance if we want to create it later with out going through all of the above steps. We use the dd command to do this. WARNING: Be very careful when using dd. Putting the disks in the wrong order can cause you to lose the entire disk.

To take an image of the disk do: dd if=/dev/sdx of=/usr/src/centos_6_desktop_2016-04-20-at-1700.iso. The next time we need a key we can simply copy our image back to a USB key with. dd if=/usr/src/centos_6_desktop_2016-04-20-at-1700.iso of=/dev/sdx.

EDIT: The above is for CentOS 6. Below is what would be ran if it was done in CentOS 7:

livecd-iso-to-disk –format –reset-mbr –efi –overlay-size-mb 4094 –home-size-mb 4094 –delete-home –unencrypted-home /root/CentOS-7-x86_64-LiveKDE-1708.iso /dev/sdX1

 

Leave a comment

Leave a Reply