Creating a multi-os LiveUSB thumb drive with GRUB2

In the beginning…

… there was a LiveCD. Then, there was dd and USB sticks. Now, there are a few GUI options out there to help you go from Live ISO to LiveUSB stick. However, only a few will help you do multiple distros on the same stick; xboot and yumi come to mind, but they’re windows only.

Having recently come into an extra 64GB USB Thumb Drive (Sandisk Cruzer), I figured I finally have time / space to create a multiboot USB stick that will allow me to “be prepared” with both Live environments and install capabilities. I managed to cram all of the following into a single USB stick with a single GRUB2 menu:

  • Darick’s Boot and Nuke (DBAN)
  • SystemRescueCD
  • Backtrack 5R3 KDE (32 and 64)
  • Fedora 17 KDE Live (32 and 64)
  • Fedora 17 LXDE Live (32 and 64)
  • Fedora 17 XFCE Live (32 and 64)
  • Ubuntu 12.04 Live (32 and 64)
  • CentOS 6.3 DVD1 (32 and 64)

I feel like this thumb drive has me prepared for the following situations:

  • Fixing PCs at family events (it’s inevitable)
  • Installing CentOS on spare PCs for use as servers
    • or occasionally, on my fileserver which had a bad disk for root
  • My occasional forray into BackTrack, which is a lot of fun to play with
  • Creating more unordered lists on my blog

Click below and I’ll share what I’ve learned, some examples, and even my current grub.cfg.

Some tips on creating your own

Installing Grub, using stock entries for DBAN, SystemRescueCD, and Ubuntu

I started off with this post over at PenDriveLinux.com and worked my way up from there. I used his method to create the initial grub installation on the USB drive, and the DBAN and Memtest86 entries in his example grub.cfg can be used directly. The Ubuntu entries are also still valid for Ubuntu 12.

This also introduced me to a concept I didn’t know existed: You can use an ISO like a disk in grub via the loopback command and the (loop) drive it creates. This makes it possible to reach inside the ISO to get the kernel and initrd. Unfortunately, this doesn’t work for Fedora, so we’ll cover that in a minute.

Backtrack 5 configuration

Next I wanted BackTrack on there, since I like to have it around but not enough to carry a dedicated USB stick / CD for it. Caveat: The initrd for Backtrack doesn’t include Lupin, which is what provides the “iso-scan/filename” kernel option. Forunately, an article over at thoughtcrime.org.nz has us covered – he’s got instrutions and a script to patch the initrd. I didn’t bother to put the initrd.patched.gz back inside the iso because I could smell victory nearby and didn’t want to get bogged down learning / fine tuning mkisofs. So, we use the ISO but we leverage an initrd that is not inside the iso. The grub2 entry looks like this:

menuentry "BT5R3 - 32 - Default" {
 insmod vbe
 loopback loop /isos/backtrack/BT5R3-KDE-32.iso
 linux (loop)/casper/vmlinuz file=(loop)/preseed/custom.seed boot=casper nopersistent rw text splash vga=791-- iso-scan/filename=/isos/backtrack/BT5R3-KDE-32.iso
 initrd /isos/backtrack/bt5r3-32-initrd-patched.gz
}

If you wanted to emulate ALL of the available options from the stock backtrack 5 grub menu, just mount the iso and take a look at the isolinux.cfg file. The “append” entries are what get added as kernel options, so you just make them part of your “linux” line in grub.cfg.

Now, about fedora…

Fedora insists on being a problem child. You probably had this all mapped out in your head – i’ll have my /boot directory with grub, then an /isos/distribution organization with all the .ISO files. Fedora doesn’t work like that. You actually have to extract the /LiveOS directory out of the ISO. Since i’m running multiple versions of Fedora on this same thumb drive, i copied out /LiveOS from each ISO and renamed it. Here’s an example of the grub entry for one of them – just change it for each variant you want. And again, if you want to emulate all the stuff that’s in the stock boot menu, take a look at /isolinux/isolinux.cfg and season your grub.cfg to taste.

menuentry "Fedora 17 Live - KDE - 64" {
 linux /isos/fedora/fedora17-kde-64/vmlinuz0 rootfstype=auto root=UUID=3112-6410 live_dir=/isos/fedora/fedora17-kde-64/ ro liveimg quiet rhgb rd.luks=0 rd.md=0 rd.dm=o
 initrd /isos/fedora/fedora17-kde-64/initrd0.img
}

One more thing: See that root=UUID=####-#### entry? You’ll need to customize that. Here’s how I found the UUID of my thumb drive:

  1. Connect the USB stick to my linux workstation
  2. Issue dmesg and see what the device name is – for example, /dev/sdc
  3. Issue ls -al /dev/disk/by-uuid/ and see which one points to /dev/sdc
  4. Put that UUID in the kernel argument.

CentOS also needs some special love

Centos will happily boot from the USB stick and then completely forget how it got there. It will want to find a CD in the drive by default, which you don’t have / want. It does, however, support installation from a hard drive, which is exactly what your USB stick is. However, it’s not enough to just point the installer to the .ISO file, it also needs the install.img file. I found that the best way to accomodate it was to

  • put the .ISO in a directory like /isos/centos32
  • extract the images folder from the .ISO and put it in the same place (ie, /isos/centos32).

Since CentOS doesn’t appear to have updated their docs for version 6, you can use the RHEL 6 doc instead.

When you get to the installer, choose hard drive installation, and point it to /isos/centos32 (or whatever you named it).

And finally, my grub.cfg

This is my current grub.cfg. You can scrutinize it and figure out what I was thinking and then roll your own version.

# This grub.cfg file was created by Lance http://www.pendrivelinux.com
# Suggested Entries and the suggestor, if available, will also be noted.

set timeout=10
set default=0

menuentry "DBAN ISO" {
 loopback loop /isos/util/dban-2.2.7_i586.iso
 linux (loop)/DBAN.BZI nuke="dwipe" iso-scan/filename=/dban-2.2.7_i586.iso silent --
} 
#menuentry "Memtest 86+" {
# linux16 /memtest86+.bin
#}
menuentry "SystemRescueCD" {
 loopback loop /isos/util/systemrescuecd-x86-3.0.0.iso
 linux (loop)/isolinux/rescue32 isoloop=/isos/util/systemrescuecd-x86-3.0.0.iso setkmap=us docache dostartx
 initrd (loop)/isolinux/initram.igz
}
menuentry "BT5R3 - 32 - Default" {
 insmod vbe
 loopback loop /isos/backtrack/BT5R3-KDE-32.iso
 linux (loop)/casper/vmlinuz file=(loop)/preseed/custom.seed boot=casper nopersistent rw text splash vga=791-- iso-scan/filename=/isos/backtrack/BT5R3-KDE-32.iso
 initrd /isos/backtrack/bt5r3-32-initrd-patched.gz
}
menuentry "BT5R3 - 64 - Default" {
 insmod vbe
 loopback loop /isos/backtrack/BT5R3-KDE-64.iso
 linux (loop)/casper/vmlinuz file=(loop)/preseed/custom.seed boot=casper nopersistent rw text splash vga=791-- iso-scan/filename=/isos/backtrack/BT5R3-KDE-64.iso
 initrd /isos/backtrack/bt5r3-64-initrd-patched.gz
}
menuentry "CentOS 6.3 - 32" {
 loopback loop /isos/centos32/CentOS-6.3-i386-bin-DVD1.iso
 linux (loop)/isolinux/vmlinuz
 initrd (loop)/isolinux/initrd.img
}
menuentry "CentOS 6.3 - 64" {
 loopback loop /isos/centos64/CentOS-6.3-x86_64-bin-DVD1.iso
 linux (loop)/isolinux/vmlinuz
 initrd (loop)/isolinux/initrd.img
}
menuentry "Fedora 17 Live - KDE - 32" {
 linux /isos/fedora/fedora17-kde-32/vmlinuz0 rootfstype=auto root=UUID=3112-6410 live_dir=/isos/fedora/fedora17-kde-32/ ro liveimg quiet rhgb rd.luks=0 rd.md=0 rd.dm=o
 initrd /isos/fedora/fedora17-kde-32/initrd0.img
}
menuentry "Fedora 17 Live - KDE - 64" {
 linux /isos/fedora/fedora17-kde-64/vmlinuz0 rootfstype=auto root=UUID=3112-6410 live_dir=/isos/fedora/fedora17-kde-64/ ro liveimg quiet rhgb rd.luks=0 rd.md=0 rd.dm=o
 initrd /isos/fedora/fedora17-kde-64/initrd0.img
}
menuentry "Ubuntu 12 Live - 32" {
 loopback loop /isos/ubuntu/ubuntu-12.04.1-desktop-i386.iso
 linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/isos/ubuntu/ubuntu-12.04.1-desktop-i386.iso noeject noprompt --
 initrd (loop)/casper/initrd.lz
}
menuentry "Ubuntu 12 Live - 64" {
 loopback loop /isos/ubuntu/ubuntu-12.04.1-desktop-amd64.iso
 linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/isos/ubuntu/ubuntu-12.04.1-desktop-amd64.iso noeject noprompt --
 initrd (loop)/casper/initrd.lz
}

2 comments

  1. Frank says:

    I cam here looking to be able to boot 2 Linux installations which are sitting on a HD attached to my machine via USB. However I got lost before paragraph six :)

    You sure are determined.

    • bschaefe says:

      Frank,

      I try to stay high level in order to allow folks to experiment and play for themselves. I don’t see a whole lot of value in putting too much detail in my step-by-step instructions, since software evolves at a rapid pace.

      There are some utilities out there that will create multi-distro boot disks, but they don’t work as well as understanding the boot process and customizing it to fit your needs. As it is, the major distros don’t really support this type of thing because it’s not all that common.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax