Thursday, December 4, 2008

Fedora 10 LiveCD on USB Disk

The following steps will setup a flash disk for usage as a live media without using any third party applications. I have tested this with Fedora 10 - it should work for almost any distribution which has a live-cd version. The pre-requisites are as follows:
1.Have sufficient disk space on the destination media - Fedora 10 required approximately 770MB after installation.
2. A linux distribution with a functional copy of grub - Fedora boots using grub.
  1. Grab the live cd ISO from http://fedoraproject.org/en/get-fedora
  2. Create a mount point mkdir temp
  3. Mount the iso on this folder mount -o loop F10-i686-Live.iso temp
  4. Format your flash disk in your favorite filesystem - I chose EXT2 since it is a non journaled and widely supported FS. That should prevent you from using maybe ReiserFS mke2fs -I 128 /dev/sdb1 Note: I decided to have a partition table and I have only one disk in my desktop. You have to figure out whether /dev/sdb1 is truly the partition to hold your live media. Note 2: I chose to downgrade the inode size from the fedora default of 256 to the more common 128
  5. Mount the new filesystem somewhere mount /dev/sdb1 /media/b1
  6. Copy the complete ISO filesystem to your flash drive cd temp && cp -rv . /media/b1
  7. Copy the grub binaries cp -rv /boot/grub /media/b1/
  8. Install grub on the flash MBR by running the following commands in grub
    • map (hd0) (hd1) # This swaps your first disk with the second for grub
    • map (hd1) (hd0) # This swaps your second disk with the first for grub
    • root (hd1,0) # Your boot partition is the first partition of your second disk
    • setup (hd1) # Install grub in the MBR of your second disk
  9. Hit Control-D to come out of grub
  10. The ISO has a grub.conf but it wont exactly work out of the box - copy it to get a default template and to be similar to what it would have looked like if you booted off the CD. cp temp/EFI/boot/grub.conf /media/b1/boot/grub/grub.conf
  11. Edit the grub.conf and make the following changes
    • Delete rootfstype=iso9660
    • Replace root=CDLABEL=F10-i686-Live with root=/dev/sdb1 (If your number of hard disks are more than one or you keep plugging in and out media disk set a label to the fielsystem on the USB disk and use that label after root=CDLABEL=[your new label])
  12. Save and quit the grub.conf file
To elaborate the following things happened in the grub installation
  1. We installed grub in the MBR of the second disk and told it which partition to look for the boot loader
  2. We asked grub to assume that it is booting off the first disk (using the map command) - this is necessary because when the BIOS hands it over to grub the USB disk is the first hard disk
  3. Next once the kernel is loaded in memory the USB disk is the second disk it sees since the hard disk in the desktop/laptop is the first one it recognizes. Hence we set root=/dev/sdb1

Note: LiveCD implies a version of your distribution which doesn't require installation on your local hard disk. Technically any distribution released as a squashfs should work.