[Solved] Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post please read how to get help
Post Reply
User avatar
slipstick
Level 6
Level 6
Posts: 1000
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

[Solved] Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by slipstick »

This is specifically aimed at pbear, but others welcome to comment.

pbear - I have just read your most excellent tutorial on how to install to an external USB drive:
viewtopic.php?f=42&t=287353

I want to install to an external USB HDD with gpt partitioning - UEFI mode. I have to admit your 'Unflag/Reflag" method makes me a bit nervous, and I don't really want to install rEFInd, so I wonder if there isn't an even simpler way. Note - I haven't yet done much thinking on this, so I'm probably missing something which you'll see immediately. I already have my partitions set up on the USB drive. I know that in the efi partition the bootloader is stored in the "Ubuntu" folder along with a small "grub.cfg" file which is just a pointer to the real "/boot/grub/grub.cfg" file in the installed OS. For example, here's the "/boot/efi/EFI/Ubuntu/grub.cfg" from my internal HDD:

Code: Select all

search.fs_uuid a3e65c35-55b4-4515-81c6-8d2b94627f57 root hd0,gpt5 
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
So what would happen if I simply installed the system to my USB HDD using "ubiquity -b" without installing a boot loader, then just copied the entire "EFI/Ubuntu" folder from my internal HDD to the USB HDD EFI partition, set the boot and esp flags on that partition, and then modified the "grub.cfg" file to use the appropriate UUID and gpt partition number for the USB drive (not sure if hd0 should be changed or if there is any point to also copying over the fallback bootloader in "EFI/Boot)?

Do you think this could work, or am I missing something really obvious?


EDIT - I've been doing some reading since I posted this. It looks like for a removable device, the fallback bootloader in "EFI/Boot" is used. As there is no "grub.cfg" file in this folder, I assume that maybe the pointer to the grub.cfg file in the installed filesystem is incorporated within the "EFI/Boot/bootx64.efi" bootloader at installation? Easy to see why there is a separate pointer file in the "Ubuntu" folder - for secure boot to check the bootloader signature, the bootloader couldn't be modified at installation - the modified part gets put into the little "grub.cfg" file. Anyway, if the EFI/Boot/bootx64.efi file points to the grub.cfg in the root partition of the installed OS, it looks like the method I proposed here will not work. I'd appreciate your comments, though.
Last edited by slipstick on Fri Sep 18, 2020 10:04 pm, edited 2 times in total.
In theory, theory and practice are the same. In practice, they ain't.
pbear
Level 14
Level 14
Posts: 5397
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by pbear »

Honestly, I think you should just go ahead and do Unflag/Reflag. It's not difficult to fix the internal drive's boot loader, if it comes to that (which it won't). All you need to do is boot (with the USB attached), then run sudo grub-install /dev/sdx. Bingo, like magic, problem solved. It's Windows users for whom this is difficult, and then only because the answer is obscure (the procedure itself is simple).

Anyhoo, to answer your question, I spent a lot of time on the ubiquity -b solution, but installing the boot loader manually proved to be a super PITA. Indeed, I only figured it out after I had tumbled over the Unflag/Reflag method, so I didn't bother to incorporate it into the tutorial. OTOH, my understanding of Grub install has advanced since then. Moreover, LM20 might be easier than LM19 was, at least it is when going the other way (what I call Reverse Hybrid), which used to be damn difficult for the same reason as ubiquity -b.

Out of curiosity, I'll give it a shot when I get a chance, but might be a few days.
pbear
Level 14
Level 14
Posts: 5397
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by pbear »

Curiosity got the better of me, so went ahead and ran the trial. Went through, but more work than it's worth, IMHO.

Unpacking that a bit, I installed with ubiquity -b, having first set up the partition table. Then, still in the live session, I installed Grub to the USB drive using the chroot method (needed in order to generate the grub.cfg file). See tutorial. When I booted the USB drive, discovered fstab was actually referencing the internal drive's EFI partition, not the USB drive's. Notably, the USB drive's EFI partition was correctly flagged, so this appears to be a defect in the installer. Edited fstab, substituting in the correct UUID, and rebooted, which indeed worked. Obviously, you can and should fix fstab while still in the live session, rather than counting on being able to boot with it wrong (still can't figure out why that worked, actually).

I realize this isn't quite the strategy you proposed, but I was more confident it would work. Frankly, not something I'm inclined to add to the tutorial.
User avatar
slipstick
Level 6
Level 6
Posts: 1000
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

Re: Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by slipstick »

Thanks for your comments and running that test. I completely forgot that I would need to install grub in order to generate the /boot/grub/grub.cfg file. Having to chroot to do that makes the method way to complicated for me. I'm planning to install 19.3 on my USB drive, not yet ready to try 20. I was hoping to find a way that would work with secure boot. I have it disabled on my system, but might want to plug my USB drive into another machine that has secure boot enabled. But I don't have any definite need for that at present, so I won't worry about secure boot and just stick to the simple method. I'm still trying to get my head around all this, even though I've been using UEFI/gpt for 5 years. Anyway, I probably won't get around to doing this until Friday or the weekend.
In theory, theory and practice are the same. In practice, they ain't.
pbear
Level 14
Level 14
Posts: 5397
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by pbear »

Unflag/Reflag installs the full assortment of UEFI boot loaders, so secure boot compatible even if running the installer on a machine where secure boot is disabled. For that matter, so do the chroot instructions in my Grub tutorial.

I understand your hesitation. I felt the same way the first time I pulled the trigger on Unflag/Reflag. On the other hand, I hadn't yet found the simple repair for Windows, which is what runs on my UEFI machine. In the event, the installation went fine and I didn't have to repair anything.

If you want bullet-proof, the best answer is VirtualBox. Big learning curve, though, if you're not already familiar.
User avatar
slipstick
Level 6
Level 6
Posts: 1000
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

Re: Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by slipstick »

That's good news - somehow I had gotten the impression that it wouldn't work on a machine with secure boot enabled. Sound like Unflag/Reflag is the way to go.
In theory, theory and practice are the same. In practice, they ain't.
User avatar
slipstick
Level 6
Level 6
Posts: 1000
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

Re: [Solved] Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by slipstick »

Success - I used the Unflag/Reflag method. I had one little hangup. When I rebooted into my desktop, it booted to my old W7 system. From efibootmgr I could see that the boot entry that had been first in the boot order had been deleted (I had made a copy of the output of efibootmgr before I installed to the USB). Interesting that the one deleted was the Ubuntu entry using shimx64.efi even though I have been running with secure boot disabled - I think I disabled it when I received my computer (W7 installed in UEFI mode) and before I ever installed Mint (17.1 I think), but maybe I misremember. Anyway, there was still an entry for Ubuntu using grubx64.efi, so I just changed the boot order in the UEFI firmware and everything seems to be OK. Installed system on the USB HDD boots ok, too. Thanks for your help.
In theory, theory and practice are the same. In practice, they ain't.
pbear
Level 14
Level 14
Posts: 5397
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: [Solved] Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by pbear »

Glad it worked out.
slipstick wrote:
Fri Sep 18, 2020 10:13 pm
... the boot entry that had been first in the boot order had been deleted ...
That's odd. Anyhoo, you mentioned maybe restoring secure boot some day. You realize you can add an NVRAM entry with efibootmgr, right?
User avatar
slipstick
Level 6
Level 6
Posts: 1000
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

Re: [Solved] Re Tutorial: Full Install to USB Drive: Four options (Attn - pbear)

Post by slipstick »

I really don't have plans to re-enable secure boot on my system - I wanted the USB drive to work with other computers, such as maybe a friend running W10 who might have a problem and I wouldn't want to hassle with trying to disable secure boot on that system. No immediate plans for that though. At present the USB is a standby for HD failure in my desktop and to hold partition images (might try Foxclone instead of Clonezilla this time). I know that I can add NVRAM entries with efibootmgr, but haven't delved into the details. Will worry about that when/if I have a need. Thanks again.
In theory, theory and practice are the same. In practice, they ain't.
Post Reply

Return to “Installation & Boot”