1

Is it possible to create a multiboot USB for Linux distributions, purely from Linux, without third party software?

NOTE: this is a self-answered question. I wanted to share my methods with the Linux community.

0

Using Linux Mint 19 64 bits as host OS. It's quite safe to assume that similar distros and releases, like Ubuntu for example, will behave the same.

We will need:

  • A USB at least 8GB (Nowadays two Linux ISO images don't fit a 4GB USB)
  • ISO images of Linux. In this case, Ubuntu 19.04 and Debian 10. This images are just as examples. Other distros or releases fit this guide, including tools like Clonezilla or GParted.

The process

  1. Install grub-efi-amd64 for GRUB EFI compatibility.

    sudo apt install -y grub-efi-amd64
    
  2. Format the USB with msdos partition table. The partition has to be FAT formatted. Mark the partition as bootable.

  3. Mount the USB. Take a note of: wich device is, i.e. /dev/sdc1, and the path it is mounted on, i.e. /media/foo/USB/. From now on, I will use those two examples for the guide.

  4. Install GRUB:

    dirs=(bin dev etc lib lib64 proc sbin sys usr)
    for dir in "${dirs[@]}"; do
      mkdir /media/foo/USB/$dir && sudo mount --bind /$dir /media/foo/USB/$dir
    done
    
    sudo chroot /media/foo/USB/
    
    # chroot environment
    # first we install grub efi
    
    grub-install --force --removable --target=x86_64-efi --efi-directory=/ /dev/sdc1
    
    # now we install grub i386
    
    grub-install --force --removable --target=i386-pc --boot-directory=/ /dev/sdc
    
    # exit the chroot
    
    exit
    

WARNING!! Be very careful with the next command, since you could remove binded directories and harm you system. Use tab completion for the paths instead of typing them.

for dir in "${dirs[@]}"; do
  sudo umount /media/foo/USB/$dir && rm -rf /media/foo/USB/$dir
done
  1. Mount the ISOs, and copy the file /boot/grub/grub.cfg into /media/foo/USB/boot/grub. Change the names, i.e. ubuntu.cfg and debian.cfg

  2. Copy the ISOs in the USB.

GRUB configuration:

  1. Create under /media/foo/USB/grub the file grub.cfg and put the following content there:

    set root='(hd0,1)'
    configfile /boot/grub/grub.cfg
    
  2. Create under /media/foo/USB/boot/grub the file grub.cfg and put the following content there:

    menuentry 'Ubuntu 19' {
      configfile /boot/grub/ubuntu.cfg
    }
    
    menuentry 'Debian 10' {
      configfile /boot/grub/debian.cfg
    }
    

Configure ubuntu.cfg

Edit the file /media/foo/USB/boot/grub/ubuntu.cfg and add the following lines at the top:

set iso_path=/ubuntu-19.04-desktop-amd64.iso # the name of the ISO
loopback loop $iso_path

Replace all the occurrences of the string /casper/ with (loop)/casper/

Replace all the occurrences of the string vmlinuz with vmlinuz iso-scan/filename=$iso_path

Configure debian.cfg

Edit the file /media/foo/USB/boot/grub/debian.cfg and add the following lines at the top:

set iso_path=/debian-live-10.2.0-i386-lxqt+nonfree.iso # the name of the ISO
loopback loop $iso_path

Replace all the occurrences of the string /live/ with (loop)/live/

Replace all the occurrences of the string /d-i/ with (loop)/d-i/


We are now ready to test if the USB works properly, just boot your machine with the USB attached, and depending on the BIOS/EFI you will have different options to select between BIOS or EFI boot, or just the option to boot from USB in older machines.


For the sake of simplicity, and because this method is moderately advanced, I omit lots of details which I assume the user will be able to sort out. Anyway, suggestions, critics, improvements are welcome. This answer can be edited to add GRUB configurations for other Linux systems if you ask.

With the same method for Windows installers.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.