I routinely need to use several live CDs or installation disks while working and having fun: SystemRescueCD (which I use mostly to backup/restore Windows installations), Ubuntu Desktop and Netbook Remix for showing off and installation, Ubuntu Server and Debian Netinstall. And of course, I like to try our new ones from time to time.
The problems I’m facing are these:
- my laptop (netbook) does not have a CD drive, so I need to find a computer who has one, transfer the ISO file, find a CD, burn it. I’m too lazy for that.
- most of the computers I’m trying to boot don’t have a CD drive either.
- creating a bootable stick out of a ISO file is possible with usb-creator or unetbootin, but it takes too long, erases my stick and (in case of unetbootin) does not execute the original boot menu.
- I know there are GRUB 2 tricks to boot a ISO file that exists (unpacked) on a USB stick or HDD, but it requires hacking and converting the CD’s isolinux menu to GRUB). Not for me.
What I’m trying to get is this:
- have all the CD’s on the stick, and my documents intact there too.
- have a boot manager that allows me to select which distribution to boot next.
- execute the original boot menu (the isolinux.cfg file).
- low maintenance effort (everything should be easily bash-scriptable).
- if possible, re-create a bootable CD from the files.
The first thing to do was, of course, to partition the USB stick. I created using cfdisk 4 primary partitions (more on this later) of enough size to fit the CD data. My stick was /dev/sdc in this case, make sure you get the right one or you might kill some innocent data!
First, I made sure any bootloader and the partition table are erased (possibly not needed).
# dd if=/dev/zero of=/dev/sdc bs=512 count=63
Then, off to create the 4 partitions with:
# cfdisk /dev/sdc
I created 4 new partitions (as my USB stick is 4 GB, 3 of them are 720 MB for the first 3 CDs and one is the rest of the space, where I will also keep my documents). All the partitions are primary, and I set up the type as 06 (DOS FAT-16). I wrote the partition table and then exit.
Now, my 4 partitions are /dev/sdc1 to /dev/sdc4 and I need to format them (I also gave them nice labels):
# mkfs.vfat -n SysResCD /dev/sdc1
# mkfs.vfat -n UbuntuDsk /dev/sdc2
# mkfs.vfat -n UbuntuNRmx /dev/sdc3
# mkfs.vfat -n UbuntuSvr /dev/sdc4
Next step is to copy the files from the ISO files to the USB stick:
# cd /tmp
# mkdir 1 2 3 4
# mount /dev/sdc1 1
# mount /dev/sdc2 2
# mount /dev/sdc3 3
# mount /dev/sdc4 4
When copying files from ISO files, I preffer mc (Midnight Commander), which can enter ISO files as archives, but of course you can just mount the ISO files with the loop option of mount:
# cd /tmp
# mkdir iso1 iso2 iso3 iso4
# mount -o loop /location/of/iso1.iso iso1
# mount -o loop /location/of/iso2.iso iso2
# mount -o loop /location/of/iso3.iso iso3
# mount -o loop /location/of/iso4.iso iso4
After copying the files (from /tmp/iso1 to /tmp/1 and so on), the next step is to make the partitions bootable. The bootloader I choose to use is syslinux, and the reason is very simple: syslinux uses the exact same configuration files as isolinux, so it will allow us to boot from USB with the exact interaction as from the CD.
Syslinux looks for the config file in another location (the root of the filesystem), and the name of the file is syslinux.cfg (isolinux’s is isolinux.cfg). So we need to move all the configuration files of isolinux (which are in either /boot/syslinux or /syslinux) to the root of each partition and then change the name of isolinux.cfg to syslinux.cfg:
# cd /tmp/iso1/boot/isolinux
or
# cd /tmp/iso1/isolinux
(dependind on the case)
# mv -f * /tmp/iso1
# cp /tmp/iso1/isolinux.cfg /tmp/iso1/syslinux.cfg
(we cp and not nv the cfg file because sometimes it is referenced again from the menu system).
Repeat the steps for all four partitions.
There are two more steps to do for making the USB stick bootable: installing the syslinux bootloader into each partition and installing a MBR bootloader on the stick:
# syslinux /dev/sdc1
# syslinux /dev/sdc2
# syslinux /dev/sdc3
# syslinux /dev/sdc4
And the most difficult part is at the end! We need to find a MBR bootloader that can chainload another bootloader, located in the partition’s boot sector. Sounds easy (and most of the common bootloaders claim to do this), but I’ve tried a lot of them and I have mixed results.
For the moment I failed to find a MBR bootloader that can load syslinux when installed on a extended partition (I don’t really know if it’s syslinux’s fault of the bootloaders’ that I tried). So this is why I told you to make 4 primary partitions.
I am currently using install-mbr from the Debian/Ubuntu package mbr, which is dead-simple to install:
# install-mbr -T /dev/sdc -i=a -e=1234 -v /dev/sdc
The downside is that it does not produce any menu, when it boots it displays a simple prompt like this:
1234:
Then it waits for user input and will boot the corresponding partition, which of course will load that partition’s syslinux/isolinux menu.
I also succesfully used lilo instead of install-mbr, and lilo can show a menu. You need this configuration file:
prompt
timeout=60
other=/dev/sdc1
label=SysResCD
other=/dev/sdc2
label=UbuntuDsk
other=/dev/sdc3
label=UbuntuNRmx
other=/dev/sdc4
label=UbuntuSvr
The command to install lilo on the MBR of the stick is this:
# lilo -S /dev/null -C /path/to/lilo.conf -b /dev/sdc
And that’s it, you should now have a USB stick that boots either to the 1234: prompt or to a lilo menu and allows you to choose from one of the four partitions, where you can place any bootable CD content. And since all the original files are still unchanged, I can also re-create the ISO if I need to.
The problems with this approach are:
- only 4 systems can be booted from the same stick, because the bootloaders are not smart enough.
- some installation systems will be confused if they are not running from a “real” CD. Ubuntu Server, for example. I will post a howto for this soon.
I will follow-up with another post that will script this approach and hopefuly also with another boot manager, after I finish my testing.
You have any tips and tricks for making this system better (good boot manager would be good!) ? Write them on the comments!
PS: For my Romanian readers, there’s a new post of NOVIT news’ selection, that you can read here!
Image credit: zone41.
No related posts.







[...] my previous post about booting CDs from a USB stick, I did find a solution to my problem, which is the need to have readily available a few bootable [...]
[...] you’ve read my previous post about booting multiple CDs from a USB stick and the one before it, you know that I need to have multiple live or installer CDs with me almost all the time, and [...]