Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Configuring USB HD to Boot Multiple ISOs using GRUB

Posted on 2006-07-06
Medium Priority
Last Modified: 2013-12-05
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!
Question by:dthomas53
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 35

Expert Comment

by:Duncan Roe
ID: 17066912
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 http://www.experts-exchange.com/Operating_Systems/Linux/Q_21875183.html 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.
LVL 22

Expert Comment

ID: 17068998
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:)

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

LVL 35

Expert Comment

by:Duncan Roe
ID: 17069386
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.
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.


Author Comment

ID: 17071568

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 (?).

LVL 22

Expert Comment

ID: 17071615
>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).

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

LVL 22

Accepted Solution

pjedmond earned 2000 total points
ID: 17075271
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';)

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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question