Page 1 of 1

Simple method to create a UEFI-bootable USB drive

Posted: Mon Aug 21, 2017 10:29 pm
by pbear
[Note: I've since rolled up this thread into a tutorial: Full Install to USB Drive: Three Options. The tutorial covers the method described here, updated for LM19. It also covers the rEFInd method (mentioned below) and basic install on a BIOS system.]

Spent the last month searching for a way to create a USB drive which boots in UEFI.* If someone here has posted a solution previously, I wasn’t able to find it. The problem is that a bug in Ubiquity ends up modifying the main boot loader even if one specifies Grub should be installed to the USB drive. One solution apparently is to disconnect the internal hard drive, but that isn’t feasible for me because it’s a laptop. Several workarounds have been proposed, e.g., Nicholas Dionysopoulos, Ubuntu Help and Ubuntu Forum, but all of them are complicated and somewhat risky.

* For context, my primary Mint install is single boot to an old Toshiba laptop (BIOS, originally Win7). The object of the current exercise is to add Mint to my other laptop, an HP 15 which uses UEFI. This is mainly for testing purposes, so I don’t want to do conventional dual boot. HP doesn’t support legacy boot on a single session basis, so all I’m allowed to do is change the entire system back and forth, which I’m not willing to do on a daily basis. Also, in conversations with friends considering Linux, I’ve found them reluctant to try dual boot because of the unwind issues. Especially on a machine with USB 3.0, a bootable USB drive would solve that problem very nicely.

After sifting through what seemed like endless blogs and forums, I tumbled across a two-year-old post on the Ubuntu forum (#45) by someone called msavini which describes exactly what I want, a relatively simple solution that most importantly doesn’t require me to bollix then fix the Windows boot loader. Rather, Mint is installed to the USB drive in BIOS or legacy boot, then the EFI boot loader is installed manually from Terminal. As an added bonus, the USB drive can be booted in either UEFI or BIOS, which happens to be particularly convenient for me, as I have one of each.

Addendum: A couple months after posting this thread, I learned of another strategy, described by fabien85 in this post. With this method, the live session can be booted in UEFI. Mint is then installed to the target drive without the Grub bootloader; instead, an alternate boot manager called rEFInd is installed manually. (Importantly, rEFInd is installed only to the external drive, not the internal.) I've tried the method (my write-up here), it works great and is no more difficult than the one described below. Main advantage is there's no mucking about with switching to BIOS mode for installation. OTOH, the USB drive will boot only in EFI, i.e., BIOS boot compatibility is lost. So, which strategy to use depends on which of those things one values most.

Re: Simple method to create a UEFI-bootable USB drive

Posted: Mon Aug 21, 2017 10:33 pm
by pbear
Based on msavini’s post, here’s what I did. I’ve reworded things slightly and made it more general. For the original text, see link above. All together, this only added about fifteen minutes to the install time, half that for manual partitioning which many folks do anyway.

1. Using a BIOS computer or legacy boot,* start live session for version intending to install. Turn off screensaver and display shutoff. Set up internet connection. Attach USB drive to which planning to install.

* Legacy boot is a compatibility mode on UEFI computers which makes them perform like BIOS machines. Can be accessed at startup or (usually) by using Shift-Restart: Troubleshoot: Advanced Settings. The steps to access vary by manufacturer, though. For more info, see How-To Geek and PCWorld.

2. With GParted, create a new partition table on USB drive, specifying gpt type. Set up four partitions. #1: 2MB (unformatted, at very bottom of drop down menu); #2: 200MB (fat32); #3: [remaining space after swap] (ext4); #4: 4GB [or as appropriate] (linux-swap). Also, set flag for #1 as bios-grub. If using a hard drive (recommended for long term use), separate home and/or data partitions also could be created. Alternatively, if the drive is large enough, can create a multi-boot drive, where swap and/or data partitions are shared.

3. Initiate install to USB drive using the “Something Else” option. (Let installer unmount partitions when asked.) Select #3; click Change; Use as: Ext4 system (but don’t tick the format box, we did that in Step 2) and select mount point as root (“/”). Select USB drive (sdb or sdc, depending on whether used a DVD or flash drive to boot live session) for grub (note: select the drive, not one of the partitions). Double-check not making any changes to internal hard drive. Run install (confirm format of swap), selecting other options as preferred.

4. When install completes, choose continue session, then shutdown and remove installation medium. Boot from the newly-formatted USB drive, again using BIOS or legacy boot. Turn off screensaver and display shutoff. Internet connection should have been passed forward during installation; if not, set up again.

5. Open Terminal. Install GParted (included by default in the live version but not the installed one); open and mark partition #2 (/dev/sdb2) with the “boot” and “esp” flags; close GParted.

6. Now run, one line at a time:

Code: Select all

$ sudo apt-get install grub-efi-amd64-bin
$ sudo mkdir -p /mnt/esp
$ sudo mount /dev/sdb2 /mnt/esp
$ sudo grub-install --efi-directory /mnt/esp --boot-directory /boot --target x86_64-efi --removable /dev/sdb
[Installing for x86_64-efi platform.]
[Installation finished. No error reported.]
$ sudo umount /mnt/esp
$ sudo rm -r /mnt/esp
To illustrate, this is what the partition table for a 64GB flash drive looked like when finished:


7. If the USB drive will be booted on a Windows machine, an incompatibility in how the two systems manage time will cause the USB to reset the clock, which then (quite annoyingly) has to be set back manually in Control Panel after every USB boot. (This is an issue with all dual boot scenarios.) Per ELTP, the simplest solution is to run timedatectl set-local-rtc 1 in Terminal, which causes the USB system to use local time (like Windows). You'll get a warning about RTC not being able to manage daylight savings time changes; don't worry about it, the main system will manage those.

8. Shut down; reboot, confirming USB drive still works in BIOS. Shut down and boot on an EFI machine (or by resetting boot mode).

Re: Simple method to create a UEFI-bootable USB drive

Posted: Mon Aug 21, 2017 10:34 pm
by pbear
I’ve now run this successfully three times, once installing Ubuntu 16.04.3 to a Lexar 64GB USB 3.0 flash drive (that’s its partition table above); second, installing Mint to a similar flash drive, except only 2.0; third, installing Mint to an old Seagate 232GB USB 2.0 hard drive I had hanging around. For the sake of consistency, I used the same install path for Mint as my Toshiba, i.e., install MATE 18.1, then upgrade to 18.2, update all packages and update kernel to 4.4.0-92, all of which went through with both boot loaders modified appropriately. Whether the systems will hold up in the long run remains to be seen, but it’s an encouraging beginning.

So far, the only bug I’ve run into is that the USB 2.0 flash drive won’t boot on the 3.0 port of the HP; returns “error: no such partition” three times. (Redid the install, actually, on the chance had made a mistake, but get the same error message.) Will boot on the HP’s 2.0 port, though, and on the Toshiba (which only has 2.0 ports). Also, I should mention that, while the USB 2.0 flash drive works, it's very slow; to my mind, unacceptably so. Perhaps a better 2.0 drive would perform better. Interestingly, the 2.0 Seagate boots fine on the 3.0 port, indeed from a hub attached to the port (have to do it that way, as it’s so old it requires a Y-cable to draw enough power). Unsurprisingly, the 3.0 flash drive also boots fine from the hub.

Anyhoo, I thought this might be of interest to folks. If anyone tests the method, please post whether it worked for you. Also, if anyone sees ways in which the method can be improved, I’d love to hear about it.

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Aug 22, 2017 1:16 am
by kukamuumuka
1. Use fat32 filesystem in the USB

2. Mount USB and go into USB using file browse or Terminal

3. Make efi and efi/boot folders
mkdir -p efi/boot

4. Go to efi/boot
cd efi/boot

5. Make USB UEFI-bootable
grub-mkimage -o bootx64.efi -p /efi/boot -O x86_64-efi \
fat iso9660 part_gpt part_msdos \
normal boot linux configfile loopback chain \
efifwsetup efi_gop efi_uga \
ls search search_label search_fs_uuid search_fs_file \
gfxterm gfxterm_background gfxterm_menu test all_video loadenv \
exfat ext2 ntfs btrfs hfsplus udf

5. Make a grub.cfg file

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Aug 22, 2017 3:03 am
by pbear
Cool. I'll give that a try also.

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Aug 22, 2017 3:22 am
by catweazel
pbear wrote:Cool. I'll give that a try also.
You could also try this: viewtopic.php?f=42&t=229086

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Aug 22, 2017 11:47 am
by pbear
Thanks, but persistence isn't the same thing by a long shot.

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Aug 22, 2017 5:22 pm
by pbear
On review, I think trying to create and maintain a grub.cfg file is beyond my current skill set. For the time being, I'll stick with the method described above. Have bookmarked this one for future reference. Also, of course, it may be of great use to someone else.

Re: Simple method to create a UEFI-bootable USB drive

Posted: Tue Sep 05, 2017 11:07 am
by pbear
FWIW, have three drives still going strong after a couple weeks (replaced the 2.0 flash drive, though, with another old Seagate running Cinnamon).