Outcome: To create a USB stick that contains multiple GNU/Linux (Linux) distributions using syslinux as the boot loader.
Last Update: 18th February 2014
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. The mtools package is also required.
Arch Linux (root)#: pacman -S syslinux mtools
Debian (root)#: apt-get install mtools
The syslinux files will be installed to /usr/lib/syslinux/bios/, some distributions may install them to /usr/lib/syslinux/, or /lib/syslinux.
For this tutorial, I’ll assume they are located within /usr/lib/syslinux/bios.
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 (either: /usr/lib/syslinux/mbr.bin, or /usr/lib/syslinux/bios/mbr.bin, or /lib/syslinux/mbr.bin):
(root)#: dd conv=notrunc bs=440 count=1 if=/usr/lib/syslinux/bios/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.
There are a number of other files which syslinux depends on, so I strongly recommend you copy everything from the syslinux directory to the USB (you can copy just the ones you need if you know which). Again, these files may be located in /usr/lib/syslinux, /usr/lib/syslinux/bios, or /lib/syslinux/, so adjust the command as necessary.
(root)#: cp /usr/lib/syslinux/bios/* /mnt/syslinux
Next, we need to create the syslinux.cfg file which holds all the entries for the distributions on the USB. You can use this one (obtained from the Arch Linux Wiki) as a good starting point.
Save this to the syslinux directory on the USB (/mnt/syslinux/syslinux.cfg).
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.