Linux

How to create a multiboot USB disk

Some multiboot USB software may have additional features or options, such as the ability to customize the boot menu or add additional utilities to the USB drive. Be sure to refer to the documentation for the specific software that you are using for more information.


How to create a multiboot USB drive?

 

  1. First, you will need a USB drive with at least 8GB (recommended 64GB or more if you want a lot of ISOs on the disk) of storage space.
  2. Download and install a multiboot USB software on your computer. There are several options available, such as YUMI (Your Universal Multiboot Installer), XBOOT, Ventoy, and SARDU (Shardana Antivirus Rescue Disk Utility).
  3. Once the software is installed, launch it and select the USB drive that you want to use as the multiboot drive.
  4. Next, you will need to select the operating system(s) or bootable media that you want to include on the USB drive. The software will typically provide a list of options, such as different versions of Windows, Linux distros, and bootable antivirus utilities, like:
  5. Once you have selected the desired operating systems and bootable media, the software will begin the process of creating the multiboot USB drive. This may take some time, depending on the size of the selected operating systems and the speed of your USB drive.
  6. When the process is complete, you can use the multiboot USB drive to boot into any of the included operating systems or utilities by selecting the appropriate option from the boot menu.

It’s worth noting that some multiboot USB software may have additional features or options, such as the ability to customize the boot menu or add additional utilities to the USB drive. Be sure to refer to the documentation for the specific software that you are using for more information.

What if you don’t trust the software written by others for the multiboot USB?

Well.. you can also create your own, using Python:

import os
import shutil

# Replace '/dev/sdb' with the path to your USB drive
usb_drive = '/dev/sdb'

# Create a list of tuples containing the name and path of each operating system or bootable utility that you want to include on the USB drive
operating_systems = [('Windows 10', '/path/to/windows.iso'),
('Ubuntu', '/path/to/ubuntu.iso'),
('Antivirus Utility', '/path/to/antivirus.iso')]

# Unmount the USB drive
os.system(f'sudo umount {usb_drive}')

# Format the USB drive as fat32
os.system(f'sudo mkfs.fat -F 32 {usb_drive}')

# Mount the USB drive
os.system(f'sudo mount {usb_drive} /mnt')

# Copy each operating system or utility to the USB drive
for name, iso_path in operating_systems:
shutil.copy(iso_path, f'/mnt/{name}.iso')

# Unmount the USB drive
os.system(f'sudo umount {usb_drive}')

print('Multiboot USB drive created successfully!')

This script uses the os and shutil modules to perform the following tasks:

  1. Unmount the USB drive
  2. Format the USB drive as fat32
  3. Mount the USB drive
  4. Copy each operating system or utility to the USB drive
  5. Unmount the USB drive

To use this script, you will need to install Python and the required modules on your computer. You will also need to modify the usb_drive and operating_systems variables to match your specific setup.

To install Python and the required modules

On Windows:

  1. Download the latest version of Python from the official Python website (https://www.python.org/downloads/). Be sure to select the version of Python that is compatible with your operating system (e.g., 32-bit or 64-bit).
  2. Double-click the downloaded installer file to launch the Python installer.
  3. Follow the prompts to complete the installation process. Be sure to select the “Add Python to PATH” option when prompted, as this will allow you to run Python from the command prompt.
  4. Open the command prompt and enter the following command to install the required modules:
pip install os shutil

On Ubuntu, Fedora, and Manjaro

  • Open a terminal and enter the following command to update the package manager’s package index:

sudo apt update (Ubuntu)
sudo dnf update (Fedora)
sudo pacman -Sy (Manjaro)

  • Install Python and the required modules using the following command:
sudo apt install python3 python3-pip (Ubuntu)
sudo dnf install python3 python3-pip (Fedora)
sudo pacman -S python python-pip (Manjaro)

Note: This will install the latest version of Python and the pip module, which you can use to install the required modules.

  •  Once the installation is complete, you can install the required modules by running the following command:
pip3 install os shutil

Later edit:

Here is a version of the same python script, but this time with a GUI using the tkinter module, which allows you to select multiple ISO images for various operating systems and copy them to the USB drive, adding the corresponding entries to the multiboot menu, and also displaying the available storage space on the USB drive in real time:
import os
import shutil
import tkinter as tk

# Function to create the multiboot USB drive
def create_multiboot_usb():
# Get the device name of the USB drive
device = device_entry.get()

# Unmount the USB drive
os.system(f"umount {device}")

# Create a new GPT partition table
os.system(f"parted {device} mklabel gpt")

# Create a new partition for the multiboot bootloader
os.system(f"parted {device} mkpart primary fat32 1MiB 551MiB")

# Set the boot flag on the new partition
os.system(f"parted {device} set 1 boot on")

# Create a new partition for the operating systems
os.system(f"parted {device} mkpart primary ext4 551MiB 100%")

# Format the boot partition with FAT32
os.system(f"mkfs.vfat -F32 '{device}1'")

# Format the operating system partition with ext4
os.system(f"mkfs.ext4 '{device}2'")

# Mount the boot partition
os.system("mkdir boot")
os.system(f"mount '{device}1' boot")

# Mount the operating system partition
os.system("mkdir os")
os.system(f"mount '{device}2' os")

# Install the multiboot bootloader
os.system(f"grub-install --target=i386-pc --boot-directory=boot {device}")

# Generate the configuration file for the multiboot bootloader
with open("boot/grub/grub.cfg", "w") as f:
f.write("# Set the default boot entry\n")
f.write("set default=0\n\n")
f.write("# Set the timeout in seconds\n")
f.write("set timeout=5\n\n")

# Add a menu entry for each selected ISO image
for i, iso in enumerate(selected_iso_list):
f.write(f"menuentry '{iso}' {{\n")
f.write(" set root=(hd0,1)\n")
f.write(" chainloader (hd0,1)/isos/{iso}\n")
f.write("}\n\n")

# Copy the selected ISO images to the operating system partition
os.makedirs("os/isos", exist_ok=True)
for iso in selected_iso_list:
shutil.copy(iso, "os/isos")

# Unmount the USB drive
os.system("umount boot")
os.system("umount os")

# Remove the mount directories
os.system("rmdir boot")
os.system("rmdir os")

# Function to select ISO images
def select_isos():
# Open a file selection dialog
selected_isos = tk.filedialog.askopenfilenames(title="Select ISO Images", filetypes=[("ISO files", "*.iso")])

# Add the selected ISO images to the list
for iso in selected_isos:
iso_list.insert("end", iso)
selected_iso_list.append(iso)

# Update the available storage space label
update_storage_label()

# Function to remove selected ISO images
def remove_selected_isos():
# Remove the selected ISO images from the list
for iso in iso_list.curselection():
iso_list.delete(iso)
selected_iso_list.pop(iso)

# Update the available storage space label
update_storage_label()

# Function to update the available storage space label
def update_storage_label():
# Get the total size of the selected ISO images
total_size = sum(os.path.getsize(iso) for iso in selected_iso_list)

# Get the available storage space on the USB drive
available_space = shutil.disk_usage(device_entry.get())[2]

# Update the label
storage_label.config(text=f"{total_size // 10**6}MB / {available_space // 10**6}MB")

# Create the GUI
root = tk.Tk()
root.title("Multiboot USB Creator")

# Create the device name entry field
device_label = tk.Label(root, text="Device name:")
device_entry = tk.Entry(root)

# Create the select button
select_button = tk.Button(root, text="Select ISO Images", command=select_isos)

# Create the list to display the selected ISO images
iso_list = tk.Listbox(root)

# Create the remove button
remove_button = tk.Button(root, text="Remove Selected", command=remove_selected_isos)

# Create the available storage space label
storage_label = tk.Label(root)

# Create the create button
create_button = tk.Button(root, text="Create", command=create_multiboot_usb)

# Create the result label
result_label = tk.Label(root)

# Add the GUI elements to the window
device_label.pack()
device_entry.pack()
select_button.pack()
iso_list.pack()
remove_button.pack()
storage_label.pack()
create_button.pack()
result_label.pack()

# Initialize the list of selected ISO images
selected_iso_list = []

# Run the GUI
root.mainloop()
To use this script, enter the device name of the USB drive (e.g. /dev/sdb) in the entry field, and click the “Select ISO Images” button to select the ISO images for the operating systems that you want to include on the USB drive. The selected ISO images will be displayed in the list, and the available storage space on the USB drive will be displayed in real time. You can use the “Remove Selected” button to remove any unwanted ISO images from the list. When you are ready, click the “Create” button to create the multiboot USB drive. The script will then create the multiboot USB drive and display a success message when it is finished.

Please also check my tutorial on “How to create a multiboot USB drive in Linux with bash