Outcome: To create a USB stick that contains multiple GNU/Linux (Linux) distributions using syslinux as the boot loader.
I love to play around with different Linux distributions; I find certain ones to be better suited at certain tasks, but having to switch between, and carry around, a key chain full of USB stick is not really practical, or something I can afford.
Thankfully, syslinux allows me to easily create a single, multi distribution USB stick, which is my little geeky life saver: whenever I’m asked to do a bit of repair work on a friends computer, I can bring along a single stick full of maintenance goodness; and also, if I’m away from home and don’t have my laptop with me, I can boot up my beloved, live version of Arch Linux customised with all my usual programs and files (see my ‘howto’ if you’re interested).
I’m going to assume that you are sitting in front of an Arch Linux box to create the USB; however, these instructions will, well should, work no matter what operating system you are using (read: *nix); I will try to point out any OS specific points.
The process is quite simple. It basically amounts to: formatting the stick, installing syslinux and the MBR, copying the distribution over, and creating a configuration file.
First, install syslinux with your package manager to your OS. We are not installing syslinux to the disk, just grabbing the files so we have them to hand:
(root)#: pacman -S syslinux
The syslinux files will be installed to /usr/lib/syslinux; some distributions may install them to /lib/syslinux.
Next, plug in your USB stick. You’ll want to completely format it, and create at least one partition with FAT32, marked ‘bootable’, which is where the distros shall live (I’ve not had much luck with ext, yet).
If you create more than one partition, make sure that this FAT32 distro partition is the first.
On my 8GiB USB, I’ve created two partitions: the first being a 4GB FAT to hold the distros, and the second being an encrypted (Luks+Ext4) partition where I can hold my private data.
I’ll assume you are aware on how to partition a disk using *nix tools such as fdisk and cfdisk.
If not, gparted and qtparted makes the process quite simple, but if you get stuck just leave a comment.
Once complete, mount the first partition of the USB and create a directory called “syslinux” at the root of it.
(root)#: mount /dev/sdX1 /mnt/
(root)#: mkdir /mnt/syslinux
Install syslinux to the first partition of the USB:
(root)#: syslinux -d syslinux -i /dev/sdbX1
Now install the MBR (Master Boot Record) to the USB itself (not the partition. ie. don’t add a number after sdX).
The MBR file we need is located in the same place where syslinux was installed earlier (/usr/lib/syslinux/mbr.bin):
(root)#: dd conv=notrunc bs=440 count=1 if=/usr/lib/syslinux/mbr.bin of=/dev/sdX
That takes care of syslinux, well for the most part. Now you want to copy over the Linux distributions you want.
I’ll assume you’ve downloaded some Linux ISOs.
Once you have, you’ll want to mount the ISO somewhere so you can get to it’s files. I’ll assume here that distro.iso is the distribution you’ve downloaded, and /media will be the mount point.
(root)#: mount -t iso9660 -o loop,ro distro.iso /media
If you take a look in /media, you’ll see the contents of the ISO file. Now here is where it starts to get a little tricky.
Each distribution will have their own way of laying out the files. Normally you will have a folder which contains OS files (such as the kernel, initrd, and the filesystem(s) in a squashfs format), and a folder which contains all the syslinux/isolinux related files.
Create a new directory at the root of your USB with a brief name of the OS your are going to copy over, for example for BackTrack:
(root)#: mkdir /mnt/backtrack
Now copy over everything from mounted ISO file, to this newly created folder.
If there is a syslinux or isolinux folder at the root of the mounted ISO you can ignore copying that over, but if you are unsure just copy everything, so, again using BackTrack as an example:
(root)#: cp -r /media/* /mnt/backtrack
Do this process for all the distributions: creating a new directory at the root of the USB, mount the ISO, and copy the files over.
All that is required now is to create a syslinux.cfg file which is the configuration file for the menu you see when you boot the USB.
You can either have a basic command line based boot loader (probably not what you want), or a pretty GUI so you can easily select the distribution to boot.
In order to have a GUI menu, you need to copy the vesamenu.c32 from the syslinux installation path, to the syslinux folder on the USB (/mnt):
(root)#: cp /usr/lib/syslinux/vesamenu.c32 /mnt/syslinux
For the syslinux.cfg, you can use this one obtained from the Arch Linux Wiki.
Save this to the syslinux directory on the USB.
What you need to do is copy the relevant syslinux entries from all ISOs, paste it into the syslinux.cfg you’ve just placed on the USB, and modify the paths slightly.
For some distributions, this is a straight forward process, for others, if they use complex syslinux menus, it can require a bit of searching and thought.
When you mount the ISO, have a look for a syslinux/isolinux directory. It can sometimes be located within a boot folder, or sometimes, as in the case of BackTrack, at the root.
Once you’ve found it, you’ll then want to look for the relevant file which has the menu entries.
Again, for some distributions, such as BackTrack, the syslinux.cfg will be what you are looking for; others maybe using isolinux so you’ll have to look for an isolinux.cfg file; for others, there may be many files and it may be unclear as to which ones contain the menu entries.
You will need to go through all the *.cfg files and look for the entries that is responsible booting the system, and contain references to the kernel (normally called vmlinuz), and the inital RAM disk (normally called initrd).
For BackTrack, the syslinux.cfg has multiple entries for booting into different modes (normal, fallback, stealth, etc).
Copy one, or all if you want them, of the entries to the the syslinux.cfg file on your USB (/mnt/usb/syslinux.cfg).
As we have created multiple directories on the USB to hold each distribution, you’ll want to modify the paths to the lines calling the kernel, initrd (and any thing else it expects) to fit in with our layout.
This will normally just amount to appending a forward slash ‘/ along with the name of the directory you created to the beginning of the kernel and initrd paths.
For example. With BackTrack, this is one of the entries from the original syslinux.cfg that came from the mounted ISO:
menu label BackTrack Text – Default Boot Text Mode
append file=/cdrom/preseed/custom.seed boot=casper initrd=/casper/initrd.gz text splash vga=791–
As all the files for BackTrack are now stored within the new folder (‘backtrack), all references to the files it needs has to be changed.
Here’s the working, modified version:
menu label BackTrack Text – Default Boot Text Mode
append live-media-path=/backtrack/casper boot=casper initrd=/backtrack/casper/initrdf.gz text splash vga=791–
Note here that I’ve added an extra line (“live-media-path”), you will not need to add this most distribution; BackTrack (and some other Debian based ones) are a little picky in the way they boot, and that is just a quick fix.
Do the same process for each distribution: mount the ISO, find the syslinux entries, and copy them to your syslinux.cfg.
That should be it. Reboot your machine with the USB stick in, make sure your BIOS is set to boot from it, and all should work.
If not, feel free to post a comment and I’ll give you a hand.