How do you make a USB drive that is bootable for most PCs?

I apologize for the title. I had no idea how to put my situation into a single legitimate question for the title. I will gladly change it if someone can give me a good suggestion.

My goal:

I want my custom Ubuntu USB drive (NOT a Linux live copy but an actual installation to the USB drive) to be able to boot on multiple machines the same way that a Linux live USB does. The Ubuntu USB boots on all of my PCs without issues regardless of UEFI settings.

I have done this before years ago (I didn’t have to deal with UEFI back then) and I have it working now to an extent.

What I have:

  • I have an Ubuntu live USB that contains the Ubuntu installer
  • I have a USB drive with a GPT partition table and the following layout:
    • A data partition (NTFS) that allows the drive to act as a normal USB drive when inserted into a running system
    • An ESP partition (fat32, 500MB) with the boot and esp flags that is used for UEFI boot (or maybe it isn’t in my case?)
    • An OS partition (ext4, 30GB) that I have Ubuntu 20 installed to
    • A swap partition
  • A 2 year old Dell Precision
  • A 3 year old Dell Precision
  • A 10 year old Dell Precision

What I’ve done:

  1. I attempted to install Ubuntu to my USB using my 2yr PC but was unable to due to the use of RST. Since this was my work PC and I have others on hand I moved on.
  2. I used my 10yr PC and successfully installed Ubuntu to my USB. Unfortunately the USB would not boot on my newer PCs without putting them into legacy boot mode.
  3. I added an ESP partition to my USB and used my 3yr PC to Install Ubuntu. I ran into two bugs in the Ubuntu installer. The installer will ask where to place the bootloader in UEFI mode despite what Ubuntu’s documentation says. Apparently this is a known bug and yes I double checked that I was in UEFI mode. The next issue is that if there are multiple ESP partitions (on multiple drives) the installer will use the first one it sees even if you tell it not to and to use the other one.
  4. I removed the hard drive from my 3yr PC and installed Ubuntu to my USB drive as if it were the actual hard drive.

Now my USB drive will boot on all of my PCs but there are some issues:

  • When it boots on my 2yr and 3yr PCs it complains that the USB does not have an entry on the ESP partition on the PCs hard drive. Not a huge deal, it will add one for you. Its annoying though and it doesn’t look good.
  • It will only boot on my 10yr PC but only if I manually select it from the boot menu (yes I’ve set the boot order). It also doesn’t seem to be stable (there are screen blackouts). (I understand the blackouts could be unrelated)

Summary:
The Ubuntu live USB has a single fat32 partition with the boot and lba flags set. It will boot (and run) on all of my PCs without issue and without having to change any settings. How can I make my USB able to boot this way? I feel like this should be possible since the Ubuntu live USB does it. However my knowledge of how Linux live works and how UEFI works novice at best.

Answer

Generally speaking, you should use a MBR/MSDOS partition table for maximum (backward) compatibility. It does NOT prevent you from creating an EFI system partition.

You can then install both the i386-pc and the x86_64-efi variant (well, perhaps even i386-efi for those rubbish machine with 32-bit UEFI) of grub to the drive by specifiying --target explicitly when grub-install.

Leave a Reply

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