www.rodneybeede.com "I would love to change the world, but they won't give me the source code" - unknown
 Navigation

Booting the Linux From Scratch LiveCD from a usb key drive - Last Modified 2008-10-14 16:45 UTC - Created 2008-10-14 16:45 UTC

So I have a laptop with no DVD drive. I wanted to try out Linux From Scratch (LFS), but I couldn't build it without the LiveCD.

I decided to try running the ISO from a usb drive. I found some instructions on how to boot from a usb drive on the LFS LiveCD Documentation page, but they aren't the most clear on how to make the USB drive bootable with grub.

It took me a while to get grub to install on the usb drive. I discovered that you must have at least one partition on the device for it to work. The instructions on the LFS site recommended using grub4dos if you want to create the disk from Windows, but I found it easier to simply boot from an existing Linux distro (I used System Rescue CD) and install grub that way.

Here are the steps (tested with version x86-6.3-r2160 of LFS)

  1. Boot from an existing Linux distro
  2. Download the LFS LiveCD iso from http://www.linuxfromscratch.org/livecd/download.html
  3. Insert your flash disk but don't mount it
  4. Partition your usb disk (ERASING ALL DATA) with the command echo ",,b,*" | sfdisk /dev/sdX
    1. sdX should be replaced with the block device name of your usb drive
    2. Use the command dmesg if you need help finding it
  5. Ignore the "If you created or changed a DOS..." message
  6. Format the newly partitioned disk with mkfs.vfat /dev/sdX1
  7. Create a folder for mounting the new disk with mkdir /mnt/lfs-usb
  8. Mount the new partition with mount /dev/sdX1 /mnt/lfs-usb
  9. Create a directory to mount the LFS LiveCD iso with the command mkdir /mnt/iso
  10. Mount the iso with the command mount -o ro,loop lfslivecd-x86-6.3-r2160.iso /mnt/iso
    1. Change lfslivecd-x86-6.3-r2160.iso to match the iso file you downloaded
  11. mkdir /mnt/lfs-usb/boot
  12. cp /mnt/iso/boot/isolinux/linux /mnt/lfs-usb/boot
  13. cp /mnt/iso/boot/isolinux/initramfs_data.cpio.gz /mnt/lfs-usb/boot
  14. umount /mnt/iso
  15. cp lfslivecd-x86-6.3-r2160.iso /mnt/lfs-usb/lfslivecd.iso
    1. Change lfslivecd-x86-6.3-r2160.iso to match the iso file you downloaded
  16. echo "lfslivecd-x86-6.3-r2160" > /mnt/lfs-usb/VERSION
    1. This is just to record what version you have
    2. Change lfslivecd-x86-6.3-r2160 to match the name of the iso
  17. mkdir /mnt/lfs-usb/boot/grub
  18. cp /boot/grub/{stage1,stage2,fat_stage1_5} /mnt/lfs-usb/boot/grub
  19. Create a file named /mnt/lfs-usb/boot/grub/menu.lst with the following content
    default 0
    
    title LFS USB
    root (hd0,0)
    kernel /boot/linux root=iso:/dev/disk/by-uuid/48F4-6515:/lfslivecd.iso rootfstype=vfat rootdelay=20
    initrd /boot/initramfs_data.cpio.gz
    
    1. You must change the UUID (48F4-6515 above) to match your disk UUID
    2. Use the command blkid to determine the UUID
  20. Unmount your usb key with umount /mnt/lfs-usb
  21. Start grub with the command grub
  22. Determine your grub device mapping name for your usb key with the grub command find /lfslivecd.iso
  23. Enter the grub command root (hdX,Y)
  24. You should get a response "Filesystem type is fat, partition type 0xb
  25. Enter the grub command setup (hdX)
    1. Note that you do NOT include the Y partition number
  26. Enter the grub command quit
  27. You are done. Try booting from the key now