Making a USB Key Bootable


When I needed to make a USB key (aka. USB pen drive, or USB memory stick) bootable under Linux I found a number of pages on the Internet that listed the steps needed. Some of these pages required you to do some steps from DOS and/or used the syslinux command.

I did not want to boot DOS in order to get the job done. I wanted to do everything from Linux. I tried the procedures which made use of the syslinux command but I didn't get consistent results. Sometimes my USB key was bootable and sometimes it wasn't.

I felt there had to be a better way to do this that used the same commands one would normally use to make a standard hard drive bootable. After a bit of experimentation and testing, I came up with the procedure detailed below.

The procedure

The information below provides an overview of the steps you need to follow in order to create a bootable ext2 based file system partition on a USB key. It is not an exact command by command set of instructions. You are expected to have some familiarity with Linux and the commands that will be used.

The information below is based on the assumptions that your USB key is seen by the operating system as /dev/sdz and you have a directory /media/usbdisk that will be used as the mount point for the filesystem that be created on the USB memory stick.

Run 'fdisk /dev/sdz' and create at least one partition. Remember to mark it as bootable. The following steps will assume the bootable partition is the first one (ie. /dev/sdz1).

Now that you have a bootable partition, run the following commands:

mke2fs /dev/sdz1
mount /dev/sdz1 /media/usbdisk
grub-install --no-floppy --root-directory=/media/usbdisk /dev/sdz
cd /media/usbdisk/boot/grub
rm fat_stage1_5 ffs_stage_1_5 iso9660_stage_1_5
rm jfs_stage_1_5 minix_stage_1_5 reiserfs_stage_1_5
rm ufs2_stage_1_5 vstatfs_stage_1_5 xfs_stage_1_5
cd -

At this point, the only remaining stage1_5 file in /media/usbdisk/boot/grub should be the one named 'e2fs_stage1_5'.

Remastering a CD/DVD for use on a USB key

The following information is a brief overview of what needs to be done in order to remaster a bootable CD, or DVD, image for use on a USB key.

Delete (or don't copy) the stage1, stage2, and *stage1_5 files from the /boot/grub directory of the ISO being remastered for a USB key prior to copying the ISO files over to the USB key.

In the grub directory, create a symlink called menu.1st which points to grub.conf. Add bootusb1 or bootusb2 to the kernel command line of the grub.conf file in /boot/grub.