I love LiveCD’s – they let you try out an operating system or Linux distro without messing with your current installation. Recently, I’ve become hooked on LiveUSB distro’s that allow you to boot off of a USB stick rather than a CD. I tried putting Backtrack on a 1 GB stick, and then DamnSmallLinux on a 64 MB stick. I started wondering if it would be possible to put several distributions on a larger stick, and then boot from one of your choice. It turns out that it is possible, and here’s how.
Things you will need
- an i386 computer running Linux (other architectures won’t work with the bootloader)
- ISO images of LiveCDs (or LiveUSBs) you want to run
- a large USB stick that can hold all the images
- Optional: QEmu can be installed to test the stick, or boot LiveCD’s from within your host OS.
Insert your USB stick. In a console, enter
dmesg | tail
You should see something similar to
sd 9:0:0:0: [sdc] Attached SCSI removable disk
My USB stick is therefore attached at /dev/sdc, although yours will probably be different. From here on out, I’ll refer to your drive as driveName. To make sure you have the right drive, as root, enter:
fdisk -l /dev/driveName
It should report the size of your USB stick.
We’re going to partition the USB stick for use with each LiveCD. This will destroy all data on the stick! Make sure you’re using the correct drive from above too, or you might accidentally wipe your hard drive!
As root, enter
You can enter p to show the current partitions. It should list a number of partitions. Delete each of them by entering d and entering each number.
When you’ve deleted them all, enter n for a new partition. Choose p for a primary partition, hit enter for the default, and enter +16M to make a 16 MB partition at the beginning of the drive. Enter a to make the partition bootable, and enter t to change the partition type. Enter 6 for the partition type.
Now you’re going to make an extended partition, and logical partitions for each of your ISO images. First, note the size in MB of all of your ISO images. Mine were 696, 784, 672, 697, and 200. You can find these in another terminal by running
ls -lh *.iso
in the directory containing your ISO images. When you use these numbers, you’ll want to add 5 MB to them to make sure they fit in the partition.
In fdisk, enter n for new partition, e for extended, and enter twice to fill the rest of the drive. Enter n, l for logical, enter for the default, and +sizeM, where size is the size of your first ISO image plus 5 MB. In my case, I ran +701M. Repeat this procedure for the remainder of your ISO files.
When you are done, enter p to make sure everything looks right. Your output should look similar to this:
Device Boot Start End Blocks Id System
/dev/sdc1 * 1 3 24066 6 FAT16
/dev/sdc2 4 488 3895762+ 5 Extended
/dev/sdc5 4 97 717824+ 83 Linux
/dev/sdc6 98 203 809984+ 83 Linux
/dev/sdc7 204 294 693248 83 Linux
/dev/sdc8 295 388 718848+ 83 Linux
/dev/sdc9 389 416 209920+ 83 Linux
If everything looks good, enter w to write the changes to the USB stick. If you messed up, you can enter q to quit and try again
Now we’re going to install the bootloader. Most Linux distributions use GRUB or LILO, which are great, but since we’re trying to boot ISO images off of a USB stick, we’re going to use something a little different. Gujin is an alternative bootloader that can boot all sorts of things, and will automatically scan your partitions to look for Linux kernels. It’s a handy piece of software, and if you find it useful, you should consider donating. (Disclaimer: I don’t know the author and make no money off of your donation)
First, format the first partition on your USB stick by entering
mkfs.msdos -F 16 /dev/driveName1
Then, download the
Gujin installer and unzip it. Enter the gujin-install directory and run
./instboot boot.bin /dev/driveName1 --disk=BIOS:0x80 -w
This will install the bootloader to the first partition. The -w option prints out useful debugging information.
At this point, your USB stick should be bootable. You can test it in another terminal by running
qemu -usb /dev/diskDrive
Your output should look similar to this:
Now, you’re ready to copy the ISO images onto your disk. Enter
fdisk -l /dev/diskDrive
and find the number of the first partition under ‘extended’ block. For example, mine above was sdc5. This is where the first ISO image will go. Make sure you’re using the right ISO image for the partition size, and enter
cat nameOfImage1.iso > /dev/diskImage5
to copy the ISO image to partition 5. When that finishes, similarly copy the other ISO images onto the other partitions.
cat nameOfImage2.iso > /dev/diskImage6
cat nameOfImage3.iso > /dev/diskImage7
You can test your USB stick in another terminal again by running
qemu -usb /dev/diskDrive
The full Gujin menu should now be displayed!
At this point, I had to scroll down a page (using Page Down). The options you want are listed with the code 0×80 and the ‘El Torito‘ option:
Press the appropriate key (F1, F2, etc.) to boot and you should see that CD’s particular GRUB screen!
If everything works, you should be able to boot any of your LiveCDs from USB.