Monday, March 31, 2008

Installing etherboot in USB flash drive

There are a lot of tutorials on the internet on how to make a bootable USB flash disk on linux system, unfortunately a lot of them didn't work for me. The following process explains the steps i took to get myself a bootable usb drive.

Most of the steps here is taken (copy paste) from the Damn Small Linux wiki page at
http://www.damnsmalllinux.org/wiki/index.php/Installing_to_a_USB_Flash_Drive

Before starting with the tutorial, please backup all your files into a harddrive.

  • Begin by determining the location of your flash drive. It will be something like /dev/sda
   fdisk -l
  • Check your syslinux version and upgrade it if you want FAT32 support. (Syslinux 2.11 works for FAT16; Syslinux 3.35 works for FAT32) Compile & install the latest syslinux from http://www.kernel.org/pub/linux/utils/boot/syslinux/ ( in the EU go to http://www.eu.kernel.org/pub/linux/utils/boot/syslinux/)
  • If you need to wipe the MBR on the Flash Disk, do it with a command like below. This shouldn't be necessary unless there's another funky bootloader in the MBR (like, if you were experimenting with another bootable USB linux distro).

BE *VERY* CAREFUL NOT TO WIPE YOUR HARD DRIVE'S MBR HERE!!!

Replace sdX with the path to your USB drive

   dd if=/dev/zero of=/dev/sdX bs=512 count=1


Then install http://ms-sys.sourceforge.net/ and put another MBR in its place. The ubuntu repo has ms-sys so it can be easily installed

   sudo aptitude install ms-sys
ms-sys -s /dev/sdX
  • Run fdisk on /dev/sdX, so it looks like this:
    Device Boot      Start         End      Blocks   Id  System
/dev/sdX1 * 1 1021 253177 b W95 FAT32

Use d to delete existing partitions until none remain. Use n,p,1 to create a new primary partition. Use a to make it bootable. Use t,b to make it W95 FAT32. Don't forget to hit 'a' to make it bootable!

Use 'w' to save the changes and exit

Incase you dont see a /dev/sdX1 file, remove the USB and reinsert it.

  • Create a FAT16 or FAT32 partition on the pendrive: ("-F 32" will create a FAT32 partition; "-F 16" will make a FAT16 one)
 mkfs.vfat -F 32 /dev/sdX1
  • Mount the pendrive & unzip the dsl-embedded.zip file onto this.
  • Unmount the pendrive
  • Next use syslinux to make it bootable, also syslinux is in the ubuntu repo
 sudo aptitude install syslinux
syslinux -s /dev/sdX1

This should give you a bootable usb disk, to install etherboot in the usb, we need the kernel.
  • Download the kernel file from http://rom-o-matic.net,
  • Make sure you select the LILO/GRUB/SYSLINUX loadable kernel format (.zlilo)
  • Mount the disk
 mount /dev/sdX1 /media/disk
  • Copy the downloaded etherboot file to mount in a dos filename format, eg linux
 cp ./eb-5.4.3-rtl8139.zlilo /media/disk 
  • Create a syslinux.cfg configuration file in the USB flash disk
 echo "default linux" > /media/disk/syslinux.cfg
There will now be three files inside /media/disk,
 ls /media/disk
ldlinux.sys linux syslinux.cfg
  • Thats it, unmount the disk and it should be ready.
 umount /media/disk