Simple method to create a UEFI-bootable USB drive

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post please read how to get help
Post Reply
User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Simple method to create a UEFI-bootable USB drive

Post by pbear » Mon Aug 21, 2017 10:29 pm

Note: This isn’t a support request. Rather, I’m passing along something I discovered in my travels which might be of interest to others. I’m going to break it up into three posts: background, method and comments.

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 which 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.
Last edited by pbear on Fri May 11, 2018 11:39 pm, edited 5 times in total.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Mon Aug 21, 2017 10:33 pm

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. (Don’t 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:

Image

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 machine’s 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).
Last edited by pbear on Mon Apr 23, 2018 9:24 pm, edited 7 times in total.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Mon Aug 21, 2017 10:34 pm

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.
Last edited by pbear on Tue Aug 22, 2017 3:01 am, edited 1 time in total.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
administrollaattori
Level 13
Level 13
Posts: 4916
Joined: Tue Sep 03, 2013 4:51 am
Location: Finland
Contact:

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

Post by administrollaattori » Tue Aug 22, 2017 1:16 am

http://puolanka.info/goto/to-make-an-uefi-bootable-usb/
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

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Tue Aug 22, 2017 3:03 am

Cool. I'll give that a try also.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
catweazel
Level 14
Level 14
Posts: 5189
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

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

Post by catweazel » Tue Aug 22, 2017 3:22 am

pbear wrote:Cool. I'll give that a try also.
You could also try this: viewtopic.php?f=42&t=229086
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Tue Aug 22, 2017 11:47 am

Thanks, but persistence isn't the same thing by a long shot.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Tue Aug 22, 2017 5:22 pm

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.
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

User avatar
pbear
Level 5
Level 5
Posts: 521
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

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

Post by pbear » Tue Sep 05, 2017 11:07 am

FWIW, have three drives still going strong after a couple weeks (replaced the 2.0 flash drive, though, with another old Seagate running Cinnamon).
Time flies like an arrow. Fruit flies like a banana.
Running Mate 18.3 64 bit (by upgrade from 18.1-2)

Post Reply

Return to “Installation & Boot”