Making a bootable USB drive for Linux

There may be no such thing as a free lunch, but I am a firm believer that there is such thing as a free thumb drive.  The other day, a vendor rep showed up unexpectedly at my office for a quick chat.  He gave me his business card and a USB drive with some information about his company, Silicon Mechanics.   The thumb drive was only 512 MB, so I copied the information he gave me and decided to create a disk that I could use to boot several different OSes on.

I generally use Knoppix as repair/investigation platform, but the default size was a little big and I didn’t feel like re-packaging my own (perhaps down the road I’ll play with that and write a post about it).  Instead I opted for Damn Small Linux (DSL), which is Knoppix-based (thus Debian-based) and weighs in at a mere 50 MB.  In addition, I also wanted to be able to boot the installer for Red Hat Enterprise Linux so that I wouldn’t have to burn a new CD every time I lost my old one.

The first step is to make the USB drive ready to rumble.  There are several different ways you can go about this, but I’m going to pick using SYSLINUX, which requires a FAT (DOS) partition.  One reason for using this method is that a pre-packaged DSL bundle is available for it, and the Red Hat media includes SYSLINUX config.  The other reason is that FAT partitions are pretty widely supported.  I can use the drive on Linux, Solaris, Mac OS X, and Windows without having to install any extra drivers. Using FAT also gives you another choice to make:  FAT-16 or FAT-32.  I chose 16 because I like rocking it old school.  Anyway, since the drive is already a single partition, I create the new file system like so:

/sbin/mkfs.msdos -i bootUSB /dev/sda1

I should point out that if you’re using this as a guide, please make sure you’re using the right device.  If /dev/sda1 is your hard drive, life is about to get very unpleasant for you.

Once the file system is created, you’re ready to rock.  Now you’ll need to mount it.   Wherever you’d like is okay, I generally go with /mnt.  The next step is to download DSL.  You can get it from the DSL home page (www.damnsmalllinux.org).  You’re looking for a filename like dsl-4.4.10-embedded.zip.

Once you’ve got the file downloaded, you need to extract it.  Assuming you mounted your thumb drive to /mnt, this command will do the trick:

unzip dsl-4.4.10-embedded.zip -d /mnt

The last step is to make the drive bootable.  This is where SYSLINUX comes in.  To make the drive bootable, all you need to do is:

syslinux /dev/sda1

Now you can use your thumb drive to boot any machine that supports it in the BIOS.  Most machines made in the past few years appear to.  With older machines, it’s a bit more hit-and-miss.

Now, having DSL on a thumb drive is helpful to me, but not as helpful as it would be if I also had some Red Hat boot images.  Since I do Linux installs at work off an HTTP server, I only need the initial boot image, not the full installation media.  So I created a directory on the root of the USB drive called ‘rhel’ to keep the necessary files in.  All you need are the kernel (vmlinuz) file and the initial ramdisk (initrd.img).  By adding a few lines to the ‘syslinux.cfg’ file on the USB drive, I could now boot to the Red Hat versions I needed:

LABEL rh53c
KERNEL rhel/rh53cik
APPEND initrd=rhel/rh53cird.img
LABEL rh53c-64
KERNEL rhel/rh53cxk
APPEND initrd=rhel/rh53cxrd.img

(note that I renamed files so that they would peacefully coexist.  ‘rh’ for Red Hat, ’53’ for version 5.3, ‘c’ for Client (there is also a “Server” version of RHEL 5), ‘i’ for i386 and ‘x’ for x86_64 architectures, and then ‘k’ for kernel and ‘rd’ for ramdisk).

That was simple enough, and it does not require re-running the syslinux program.  If I wanted to, I could include as many different boot options as the drive would hold.  But that’s not the only thing that can be done by editing syslinux.cfg.  By default, pressing F2 or F3 gives boot options for DSL.  I wanted to make sure that if I forgot what I labeled my Red Hat boot options, they’d still be available to me, so I added another line in syslinux.cfg:

F4 f4

This simply tells the syslinux boot loader that when I’m at the boot screen, if I press F4, I want to see the contents of the file ‘f4’.  Of course I could have given it any other name, but f4 was short and sweet.  Anyway, the contents of f4 are just:

Other OS options:

  rh53c                         Red Hat 5.3 client (i386) boot image
  rh53c-64                      Red Hat 5.3 client (x86_64) boot image

It is also possible to change the picture that loads when you get to the boot screen.  Any small (I’d guess 640×480 is the maximum size) 16-bit PNG image will do.  Now I have a customized, and incredibly useful tool.  And there’s still plenty of room left on the drive to store reference files or non-standard programs I might need.  The SYSLINUX project wiki is so far not very informative, but the man page is rather helpful.  I’ll probably play with some more options as I have time to read that page and do some experiments.

syslinux also supports booting things like FreeDOS.  While this wouldn’t be all that helpful to me in most situations, there is one scenario where it would be valuable.  Dell seems to only like distributing BIOS updates for the Windows platform, unless you want to make a boot floppy.  Since many systems no longer come with floppy disks, booting to FreeDOS and running the DOS-based BIOS update would be really handy.  Unfortunately, as of this writing I have not been able to make it work.  I think I’m getting close though, and since this post is nearly a thousand words long already, I’ll go ahead and publish it and then write a follow-up when I do get it working.

The Pen Drive Linux site was helpful in getting me going down the right path, thanks!

2 thoughts on “Making a bootable USB drive for Linux

Leave a Reply

Your email address will not be published. Required fields are marked *