Creating a Linux multi-os installation USB-stick

Introduction

If you, like me, are tired of burning the latest version of your favorite Linux distribution to a CD/DVD every time a new version comes out, this multi-os installation stick might solve the problem for you.

The main differences between this solution and many other USB installation sticks are:

  • It supports installation of multiple OS:s
  • It loads and boots the entire ISO file of the selected OS from the stick. Other solutions, like syslinux, requires you to open and copy files from the ISO when creating the USB stick, instead of just putting the whole ISO there instead.

What you need

  • A computer with Linux installed.
  • Linux should have GRUB2 (not GRUB/GRUB Legacy) installed. GRUB2 is required to boot ISO images directly from disk. This feature is not available on earlier versions of GRUB.
  • An USB stick
  • Minimal/Network installation images of all distributions you want to be able to install

Prepare Gentoo Host

Install the necessary packages:

# emerge -av grub dosfstools

Since GRUB2 is still under development, GRUB Legacy is the standard bootloader for Gentoo. To install GRUB2, follow this guide:

http://dev.gentoo.org/~scarabeus/grub-2-guide.xml

Finally, you might also want to mount iso files on your host computer. For that you need the loop driver (CONFIG_BLK_DEV_LOOP). If you configured it as a module, load it by typing:

# modprobe loop

Prepare Ubuntu Host

Install the necessary packages:

# apt-get install dosfstools

Formatting the USB stick

Plug in the USB-stick in your computer and check what device file it was assigned to:

# fdisk -l

Assuming the USB-stick was located on /dev/sdb, unmount if needed to:

# umount /dev/sdb1

Next, clear the partition table and boot sector on the disk:

# dd if=/dev/zero of=/dev/sdb count=1024

Create a new VFAT partition with 512B sectors:

# fdisk -b 512 /dev/sdb

Use default values for size:

Command (m for help): n
Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3923967, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3923967, default 3923967):
Using default value 3923967

Change type:

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Make it bootable:

Command (m for help): a
Partition number (1-4): 1

Quit fdisk:

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

Format the disk and give it a nice label (e.g. “MultiOSInstallDisk”):

# mkfs.vfat -n MultiOSInstallDisk /dev/sdb1

Install GRUB

Mount the device

# mount /dev/sdb1 /mnt

Install GRUB:

# grub-install --no-floppy --root-directory=/mnt /dev/sdb

Note: On some system, grub-install can also be named grub2-install.

# grub2-install --no-floppy --root-directory=/mnt /dev/sdb

Configure GRUB (copy and paste the following code into your terminal):

https://gist.github.com/3046193#file_multiosboot.sh

Note: You can edit the file /mnt/boot/grub/grub.cfg to your liking, e.g. by adding additional ISO files.

Note2: On some systems, the /mnt/boot/grub directory can also be named /mnt/boot/grub2. In that case, change the above command from

Download ISOs

Create a directory to hold the ISOs:

# mkdir /mnt/boot/iso && cd /mnt/boot/iso

Download the files:

# wget -c -O ubuntu-12.04-desktop-amd64.iso http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/mini.iso
# wget -c -O debian-6.0.5-amd64-netinst.iso http://cdimage.debian.org/debian-cd/6.0.5/amd64/iso-cd/debian-6.0.5-amd64-netinst.iso
# wget -c -O install-amd64-minimal-20120621.iso ftp://ftp.df.lth.se/pub/gentoo/releases/amd64/autobuilds/current-iso/install-amd64-minimal-20120621.iso

Unmount:

# sync
# umount /mnt

Reboot and enjoy

Note: It’s a bit tricky to know what parameters and options to add to an entry in grub.cfg. One way of figuring it out is to mount and look at the ISO file:

# mount -o loop <path to ISO file> <path to directory to mount on>

You might also be lucky and find some pointers here:

References

http://thermsnotes.blogspot.se/2011/11/grub2-loopback-multiboot-usb.html

http://www.panticz.de/MultiBootUSB/

http://en.gentoo-wiki.com/wiki/Gentoo_minimal_CD_on_USB_stick

This Post Has 5 Comments

  1. Wow. Hard core is sure nice from time to time, but Unetbootin really does the job most of the time if all you want is your ISO on a bootable USB stick (acting as HDD, not CD drive, I’ve had issues with that).
    I can’t remember the last time i actually used CD as install medium for Linux. Windows 7 however has failed me the last two times I tried (one Home and one Premium – installer looks the same …) but it did give me a nice run down memory lane – waiting for a physical medium to spin, make sound etc.

    1. Your right, UNetbootin is a nice tool for creating a bootable USB-stick from a Linux ISO file. However, the solution I presented has a some advantages:

      1. You’re not limited to the distributions supported by UNetbootin
      2. You can add more than one distribution to the USB-stick
  2. This is a cool way to use your usb. let’s say u have a decent 8 GB usb, ubuntu just gona take 2 GB of them, then with 6GB left, u can add more intro that u want like mint, backtrack 5R3 etc….

    Thank you for such an easy to follow post !

  3. just skimmed over this, will read fully when I’m home, just wanted to check if this will work for non-linux installation disks too? I’d like to stick all of my system install/repair disks on one drive so I can do call-outs with a smaller set of kit
    I have a 32GB flash drive and want to get Windows XP, Vista, 7 and 8 OEM images and the latest Gparted and Ubuntu all on it.
    A mere novelty, rather than anything massively helpful but it’ll speed up prep time (and install time, running from flash rather than disk).

  4. Thanks for the nice article buddy. Just what i was looking for, well explained.

Leave a Reply

Close Menu