Ubuntu, Fedora, Mint, Elementary and Others in One USB Flash – How To Create MultiUSB Drive

Kali Linux Multi USB Persistence

Introduction

Sometimes for the sysadmin and demonstration use cases is not enough a USB Flash with one Linux Distribution. Today the big USB Flash is cheap and time to want more. GUI applications like YUMI can’t build a bootable image from my images.

How to Linux boot? Here is a very basic sheme:

First step – BIOS/UEFI run their hardware specific tasks, initialize the basic system devices like a CPU, RAM and search bootloader in first sectors of HDD/SSD; second step – botloader(grub2, grub, Lilo) run the Linux kernel into memory; the next – kernel has a full control and can run some initialization services like a systemd or sysv.

Grub2 and other bootloaders also can read the filesystems (ext2, ext3, ext4, btrfs and others) and mount our iso-images as loopback-devices – “file as device”. With the MultiUSB drive we can:

  • all files on single partition – easy to use
  • all iso files can be in one directory
  • add/delete images is easy – the file tree under our control

Warning: all data in USB Flash drives will be destroyed.

Best Way – Grub2

Working 4 GB and more USB Flash are needed. Detect our device (/dev/sdb):

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb      8:16   1  14.7G  0 disk
├─sdb1   8:17   1   1.6G  0 part /run/media/paul/Linux Mint 17.2 MATE 64-bit
└─sdb2   8:18   1   2.3M  0 part

Create new partition table:

# parted /dev/sdx
(parted) mklabel msdos

Create new partition:


(parted) mkpart primary ext2 4MiB 100%
(parted) set 1 boot on

Install Grub2:

# mount /dev/sdx1 /mnt
# mkdir /mnt/boot
# grub2-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX

For UEFI (fat32 partition only):

# grub2-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removable

Finished double step – upload images to /boot directory:

// LiveCD images:
$ ls -a /boot/*iso
/boot/elementaryos-stable-0.3.1-amd64.20150903.iso
/boot/Fedora-Live-Workstation-x86_64-21-5.iso
/boot/linuxmint-17.2-mate-64bit.iso
/boot/tails-i386-1.5.iso
/boot/ubuntu-15.04-desktop-amd64.iso
/boot/xubuntu-14.04.3-desktop-amd64.iso

And setup Grub2 config:

cat /boot/grub2/grub.cfg
#
# /boot/grub/grub.cfg - Grub2 config
# Load modules
insmod part_msdos
insmod part_gpt
insmod ext2
insmod iso9660
insmod fat
#
# Get UUID of our USB Flash with `$ lsblk -f` command:
# 56f48195-f142-4df4-84cf-5a21f29177c4
#
search --no-floppy --fs-uuid --set=root 56f48195-f142-4df4-84cf-5a21f29177c4
#
menuentry 'Ubuntu_15.04' {
    set isofile='/boot/ubuntu-15.04-desktop-amd64.iso'
    loopback loop $isofile
    linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile locale=en_US.UTF-8
    initrd (loop)/casper/initrd.lz
}
#
menuentry 'elementaryos-0.3.1' {
    set isofile='/boot/elementaryos-stable-0.3.1-amd64.20150903.iso'
    loopback loop $isofile
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=en_US.UTF-8
    initrd (loop)/casper/initrd.lz
}
#
menuentry 'Xbuntu_14.04' {
        set isofile='/boot/xubuntu-14.04.3-desktop-amd64.iso'
        loopback loop $isofile
        linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile locale=en_US.UTF-8
        initrd (loop)/casper/initrd.lz
}

#
menuentry "Linux Mint 17.2" {
    set iso=/boot/linuxmint-17.2-mate-64bit.iso
    loopback loop $iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$iso noeject noprompt
    initrd (loop)/casper/initrd.lz
}
#
menuentry "Tails 1.5" {
    set isofile='/boot/tails-i386-1.5.iso'
    loopback loop $isofile
    linux (loop)/live/vmlinuz2 boot=live config findiso=${isofile} live-media=removable apparmor=1 security=apparmor nopersistent noprompt timezone=Etc/UTC block.events_dfl_poll_msecs=1000 noautologin module=Tails
    initrd (loop)/live/initrd2.img
}
#
    menuentry 'Fedora Workstation 21' {
    set isofile='/boot/Fedora-Live-Workstation-x86_64-21-5.iso'
    loopback loop $isofile
    linux (loop)/isolinux/vmlinuz0 root=live:CDLABEL=Fedora-Live-WS-x86_64-21-5 iso-scan/filename=$isofile rd.live.image
    initrd (loop)/isolinux/initrd0.img
}

Now we can unmount our USB Flash and trying to boot. Good luck!

Read more:

Programming with GNOME Builder: Review and Coding Practice

19 Years of KDE History: Step by Step

30 Years of Free Software Foundation: Best Quotes of Richard Stallman

GNOME 3.18 on Wayland 1.9: Complete Test Drive