Multiboot USB Notes
Since I needed to build a new USB stick, a quick Googling was in order to see if the state-of-the-art had changed, since I scratched the UEFI+MBR multiboot itch. And people have! With colours!
It looks like aguslr’s multibootusb project has taken the generalization much farther than I ever would have; GRUB is pretty flexible…
Note these steps are NOT compatible with Secure Boot! Make sure you disable it before using the drive. (It’ll bootload into grub, look okay, but nothing is functional!)
Automatic
If you trust a script to do it all for you, the makeUSB.sh
script will do it
all. If you don’t, then read on…
Manual Steps
Since the instructions rely on the ArchWiki to get a proper bootable USB set up, and those instructions are fairly lousy…
Set Up the USB Drive
We’ll need the following Ubuntu packages. They should already be installed.
- gdisk
- grub-pc-bin
- grub-efi-amd64-bin
First, wipe the USB drive to make sure we’re on a clean slate:
$ sudo dd if=/dev/zero of=/dev/sdc bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB, 512 MiB) copied, 0.134964 s, 4.0 GB/s
$ sync
Unplug and replug the drive.
On running gdisk
, it’ll probably complain, as we just “corrupted” the disk…
sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.3
Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!
Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!
Warning! One or more CRCs don't match. You should repair the disk!
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: damaged
Found invalid MBR and corrupt GPT. What do you want to do? (Using the
GPT MAY permit recovery of GPT data.)
1 - Use current GPT
2 - Create blank GPT
Your answer: 2
Create three partitions. The values taken are as suggested on the ArchWiki.
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-15794126, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-15794126, default = 15794126) or {+-}size{KMGTP}: +1M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF02
Changed type of partition to 'BIOS boot partition'
Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-15794126, default = 4096) or {+-}size{KMGTP}:
Last sector (4096-15794126, default = 15794126) or {+-}size{KMGTP}: +50M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to 'EFI System'
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-15794126, default = 106496) or {+-}size{KMGTP}:
Last sector (106496-15794126, default = 15794126) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'
This should leave us with the following partitions:
Command (? for help): p
Disk /dev/sdc: 15794160 sectors, 7.5 GiB
Model: USB Flash Drive
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EAA36968-DD45-467C-815E-EE433EF4B872
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 15794126
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02 BIOS boot partition
2 4096 106495 50.0 MiB EF00 EFI System
3 106496 15794126 7.5 GiB 0700 Microsoft basic data
Okay, lets get the partitions set up properly…
Command (? for help): r
Recovery/transformation command (? for help): h
WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,
just hit the Enter key at the below prompt and your MBR partition table will
be untouched.
Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 1 2 3
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N
Creating entry for GPT partition #1 (MBR partition #1)
Enter an MBR hex code (default EF):
Set the bootable flag? (Y/N): N
Creating entry for GPT partition #2 (MBR partition #2)
Enter an MBR hex code (default EF):
Set the bootable flag? (Y/N): N
Creating entry for GPT partition #3 (MBR partition #3)
Enter an MBR hex code (default 07): 0B
Set the bootable flag? (Y/N): Y
Recovery/transformation command (? for help): x
Expert command (? for help): h
Expert command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
Finally it’s time to format the partitions:
$ sudo mkfs.fat -F32 /dev/sdc2
mkfs.fat 4.1 (2017-01-24)
$ sudo mkfs.fat -F32 /dev/sdc3
mkfs.fat 4.1 (2017-01-24)
And install GRUB on the data partition (sdc3), and EFI on the ESP partition (sdc2)
$ mkdir /tmp/usbdat /tmp/usbefi
$ sudo mount /dev/sdc2 /tmp/usbefi
$ sudo mount /dev/sdc3 /tmp/usbdat
$ sudo mkdir /tmp/usbdat/boot
$ sudo grub-install --target=i386-pc --recheck --boot-directory=/tmp/usbdat/boot /dev/sdc
Installing for i386-pc platform.
Installation finished. No error reported.
$ sudo grub-install --target=x86_64-efi --removable --recheck --boot-directory=/tmp/usbdat/boot --efi-directory=/tmp/usbefi
Installing for x86_64-efi platform.
Installation finished. No error reported.
$ sudo umount /tmp/usbefi
$ sudo umount /tmp/usbdat
$ sudo rmdir /tmp/usbefi /tmp/usbdat
Whew. Now that GRUB is installed, we can deal with installing a GRUB config and getting ISOs onto the disk.
Install MultiBoot USB
Unplug and replug the USB drive, to make sure the partitions are all loaded properly. If you have automounting, the data partition should mount.
Follow the steps on aguslr’s GRUB config install page.
$ git clone https://github.com/aguslr/multibootusb
Cloning into 'multibootusb'...
remote: Enumerating objects: 5227, done.
remote: Total 5227 (delta 0), reused 0 (delta 0), pack-reused 5227
Receiving objects: 100% (5227/5227), 4.22 MiB | 7.76 MiB/s, done.
Resolving deltas: 100% (3254/3254), done.
$ export mntusb=/media/usb partusb=/dev/sdc3
$ mkdir -p $mntusb/boot/{grub/mbusb.d/,isos}
$ cd multibootusb && cp -rf mbusb.cfg mbusb.d $mntusb/boot/grub/
$ cd multibootusb && cp -f grub.cfg.example $mntusb/boot/grub/grub.cfg
At this point I also modified mbusb.cfg
to put /isos
at the top level.
ISOs
Now download all the ISOs you desire into boot/isos
, no cfg changes needed!