How to make your own bootstick

If you do much with computers, like setting up operating systems, adjusting partitions or getting them working again when they go wrong, you may accumulate a fair bundle of CDs – and as not every computer has a CD drive these days, you may also have some USB sticks. However, you might wonder if there is any way to carry less... such as just one USB stick that includes everything you want.

After much tinkering, I managed to get one to work. These instructions assume you use a Debian-based system to create the stick, but you will find it similar with any Linux and may find it possible to use other systems, following these guidelines.

First, decide what you want

You will need to decide what to put on your stick, and of course, what size stick you need to hold it all. I am using a 1GB stick at present, but a bigger one will allow more to be added.

There are a few caveats:

  1. Not everything you want to put on the stick will necessarily work, even if it works fine when burned to a CD or put directly on the stick.

  2. Sometimes, the obvious way will fail and you will need to add more – this is notably the case with Debian install CDs which cannot find themselves when booted in this way and you need to use hard disk images as well to make it work. I have not yet overcome this problem with the Debian wheezy installer.

In general, though, this technique will work if what you want is available as CD images or hard disk images.

My personal boot stick includes the Ultimate Boot CD, grml64 and the Debian squeeze installer for amd64 systems. A small amount of useful syslinux features are also present.

Prepare your stick

Obtain your stick and insert it into a USB port. If it mounts, go to a shell (probably best as root) and umount /media/LABEL, for example.

Look in dmesg to see the device name allocated... on my system it is usually /dev/sdf, and this will be assumed for the rest of this example, for the stick itself. Do cfdisk /dev/sdf, for example. If that says the partition table is corrupt, do cfdisk -z /dev/sdf to start from a blank partition table.

If there is just one partition present, taking up all the space, and it is a W95 FAT32 (LBA) partition (type 0C) and is bootable, you can Quit cfdisk. Otherwise, delete any partitions present, create a new type 0C partition taking all the space, and mark it bootable, then Write the partition table to the stick.

Next, do mkfs.vfat -n Bootstick /dev/sdf1 to format the partition. It may mount automatically when done – if so, umount it. Do syslinux /dev/sdf1. Mount the partition either manually or by removing and replacing the stick. The file ldlinux.sys should now be present on it.

Now, cd /media/Bootstick. Any iso images you wish to boot will need to go here – ubcd511.iso and grml64-full_2012.05.iso in my case. For anything else, involving hard disk images, create a folder for each and put all the files you need for that in there. In my case I have the folder “debian”, containing debian-6.0.5-amd64-businesscard.iso, initrd.gz and vmlinuz.

Now, back in /media/Bootstick, create the folder syslinux. Do cp /usr/lib/syslinux/{menu.c32,reboot.c32,poweroff.com,memdisk} /media/Bootstick/syslinux. (If you are NOT using the Ultimate Boot CD as part of this, you may want to include hdt.c32 as well.)

In /media/Bootstick/syslinux, create the file syslinux.cfg – the one below is mine, adjust it to suit your requirements:

# Config file for Syslinux -
# Default entry
DEFAULT hdd
PROMPT 0        # Change to 1 if you do not want to use a menu
TIMEOUT 0       # 0 = disabled, value in 1/10 seconds

# Menu Configuration
# Either menu.c32 or vesamenu32.c32 must be copied to /boot/syslinux 
UI menu.c32
#UI vesamenu.c32

# Refer to http://syslinux.zytor.com/wiki/index.php/Doc/menu
MENU TITLE Phil's Boot Stick (August 2012)
MENU COLOR border       30;44   #40ffffff #a0000000 std
MENU COLOR title        1;36;44 #9033ccff #a0000000 std
MENU COLOR sel          7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel        37;44   #50ffffff #a0000000 std
MENU COLOR help         37;40   #c0ffffff #a0000000 std
MENU COLOR timeout_msg  37;40   #80ffffff #00000000 std
MENU COLOR timeout      1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07        37;40   #90ffffff #a0000000 std
MENU COLOR tabmsg       31;40   #30ffffff #00000000 std

# boot Ultimate Boot CD image
LABEL ubcd
        MENU LABEL Ultimate Boot CD 5.1.1
        LINUX memdisk
        INITRD ../ubcd511.iso
        APPEND iso
# boot GRML 64-Bit image
LABEL grml64
        MENU LABEL Grml64 Live System - May 2012
        LINUX memdisk
        INITRD ../grml64-full_2012.05.iso
        APPEND iso
# boot Debian squeeze amd64 installer
LABEL debian
        MENU LABEL Debian squeeze amd64 installer
        LINUX ../debian/vmlinuz
        INITRD ../debian/initrd.gz
        APPEND initrd=initrd.gz ramdisk_size=12000 root=/dev/rd/0 rw
# reboot
LABEL reboot
        MENU LABEL Reboot
        COM32 reboot.c32
# Power off system
LABEL off
        MENU LABEL Power Off
        COMBOOT poweroff.com

Note: poweroff.com only works on APM systems – it may fail on more modern ones.


Testing

Test the stick by booting it on a machine, and try each option, but not to the point where it may destroy data, if there is anything on the hard disk of the machine you are using. If anything doesn't work, you will either need to work out a way to make it work, or you should exclude it in the future.

If the stick fails to boot at all, it may have a corrupted MBR. If so, on the system where you generated the stick, insert it and do install-mbr /dev/sdf. Then try it again. If it still fails, do syslinux /dev/sdf1 again.