Configuring USB HD to Boot Multiple ISOs using GRUB

Hello all,

I work in a dedicated server environment where it's very common to need an install or rescue disc for various Linux distributions and FreeBSD. What I'm trying to do is create an external USB drive that can be configured with GRUB (or any bootloader that will do what I need) to boot ISOs from the drive using a menu at boot. I already have a fairly good idea of how I can do this and have already done some testing:

I used Knoppix to create an initial partition, sda1, for GRUB and installed it cleanly. It now boots to the GRUB menu, but I am having trouble with how to have GRUB then pass the booting responsibilities to the ISO bootloader. I'm first trying this with the CentOS binDVD ISO as it's the one most commonly used where I work. I initially thought I would be able to just copy the ISO contents to a seperate partition and point to the ISO boot loader using the "kernel" option in GRUB - but I haven't been successful with this as I'm not sure what file this is or if it can even be configured like that.. I'm thinking what I need to do, since (and I'm no expert on this) bootable CDs have their their own boot sectors, is use dd to copy the ISO bit by bit to the seperate partition so that the boot sector remains intact, and I can then just use the GRUB "chainloader" option to pass it off to the ISO.

Now for the questions...

1.) If my idea to use dd sounds reasonable, does anyone know the best way to issue the command to best copy the ISO to the partition so that GRUB will find it seamlessly? (The options seem a bit arcane to me.)

2.) If I'm way of course with this, what other options are there that will permit me to have multilple ISO images on the drive that I can boot from?

Thanks in advance!
Who is Participating?
Found this method for having multiple isos on a CD:

It involves a 'hacked' initrd, but the 'hacking' has already been done for you, so provided you can get the USB bit working, then this method should be just 'putting the pieces in the right place';)

(   (()
(`-' _\
 ''  ''
Duncan RoeSoftware DeveloperCommented:
You have done extremely well to boot off USB at all. What is your BIOS model #? if you don't mind me asking. And how do you configure it to boot from the USB? Is the external drive flash or IDE (with USB to IDE convertor)?
See for some pointers. That asker accepted he couldn't do what he wanted.
As far as dd is concerned: ls -l of the ISO file shows you its size on disc (its actual size rounded up to a multiple of 4K usually). You can loop-mount it and do a df to get its size in KB. Let's say it is <size> KB.
  dd if=<iso_path> of=<raw_device> bs=1024 count=<size>
If you do this to a USB flash, possibly it might boot straight away. You might have to settle for multiple flash drives, one for each OS. Can you have multiple partitions on a flash drive? - I thought they were like floppies.
If you wanted access to multiple distros, then you could look at thing like Xen and VMWare.....

..but you are wanting to have access to the main system's hardware with the tools from the distro, which makes this type of process a non-starter! This leaves 3 options:

1.    A seperate drive for each distribution - nice and easy.
2.    Pick one distribution, and just keep adding more tools and then remastering the cdrom. This can be done by making a copy of the iso onto your hard drive, mounting it as a -o loop device, and then addiing extra tools as necessary. Once happy, make a new iso from the revised configuration and reburn. It should be relatively easy to do this.
3.    Install the isos on the USB flash, and 'fake' the directory tree from grub in order to make the correct iso get booted:)....and as we like a challenge, lets have a closer look at this one.

You've succeeded in getting as far as the grub boot loader, which I'm impressed with, now you need to create a seperate entry for each iso. For the purposes of this setup, I'll deal with 2 isos only, but the concept is relatively easy to extend. grub.conf file:
title iso1
        root (hd0,0)
        kernel /vmlinuz-2.6.9-22.iso1.EL ro root=LABEL=/iso1/ rhgb quiet
        initrd /initrd-2.6.9-22.iso1.img
title iso2
        root (hd0,0)
        kernel /vmlinuz-2.6.9-22.iso2.EL ro root=LABEL=/iso2/ rhgb quiet
        initrd /initrd-2.6.9-22.iso2.img

Now here's the clever bit:

You need to customise your initrd:

cp /boot/initrd.img /tmp/initrd.gz
gunzip /tmp/initrd.gz
mkdir /tmp/a
mount -o loop /tmp/initrd /tmp/a

Now you can edit (customise) the linuxrc file to mount any iso that you want as the root fs! You will need to look at the initrd for the liveCD concerned and probably start splicing bits of the code together. However, this bit is less than 20 lines of bash shell code, and reasonably easy to understand. NB You will need a different (customised) initrd for different types of live CD, although Knoppix derivatives all seem to use the same approach. You may also need to customise the /etc/fstab setup in the distributions that you are mounting. The following is the linuxrc from my setup: with comments

echo "Loading jbd.o module"
insmod /lib/jbd.o
echo "Loading ext3.o module"
insmod /lib/ext3.o                                     #May need different modules if using FAT rather than ext2/3
echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating block devices
mkdevices /dev
echo Creating root device
mkrootdev /dev/root
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount -o defaults --ro -t ext3 /dev/root /sysroot       # This is the key bit - Will need to mount -o loop iso image
                                                                            # and insert in the correct place. Look at approach used for
                                                                            # knoppix
pivot_root /sysroot /sysroot/initrd                            # swap in the new / filesystem
umount /initrd/proc

Not tried doing this, but I reckon it should be possible using the above information.

Have fun:)

(   (()
(`-' _\
 ''  ''

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Duncan RoeSoftware DeveloperCommented:
You can't write to an iso9660 filesystem even if it *is* loop-mounted - I've tried. You need to tar-copy the iso to a regular directory tree and write to that, then mkisofs when done (including isolinux to make it bootable).
Personally I avoid initrd - it's great for a distributor but as an end-user configuring your own system you really don't need it. Just put what you need in the kernel.
I considered and rejected the idea of multiple distros on the one flash drive - you don't have proper filesystem support behind you - you only have grub and once grub chains into the ISO you don't even have that. I can't absolutely say it wouldn't work, just don't like the chances.
raw-copy of a distro to the device has the best chance, I believe. That means a flash for each distro.
dthomas53Author Commented:

Sorry for misleading...I was initially testing with VMware as I didn't have my USB drive on-hand. And yes, after much discussion with other techs and online researching I'm quickly finding out how hard it is to get USB drives to boot (if at all). I don't intend to give up just yet though...does this seem like an impossible task? I would've thought this would be fairly common practice for large collocation companies needing rescue discs, considering what a nuisance it is to keep track of 10+ distros, some with up to 4 CDs (?).

>considering what a nuisance it is to keep track of 10+ distros, some with up to 4 CDs (?).

Rescue discs tend to be small single CD distros. It's relatively easy to find one distro that you like ,and just add any extra tools to it that you think that you want. BAsically, you end up tracking 1 CD and add (recompile as required) the tools that you want on it.

>You can't write to an iso9660 filesystem even if it *is* loop-mounted - I've tried

This is because the the iso contains a full file structure...which is why you have to loop mount, and work with a copy of the file structure, and then create a completely new iso from the modified directory - Although this was highlighted in point 2, I can see that there is the potential for confusion.

VMWare, is however a great place to test theindividual distros, and you can install the distro rapidly from the iso image (avoiding burning times/hassle etc).

(   (()
(`-' _\
 ''  ''

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.