Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
dual csm/uefi boot - from usb stick
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Mon Dec 23, 2019 6:00 pm    Post subject: dual csm/uefi boot - from usb stick Reply with quote

So over the years I had a "rescue" USB stick with a custom Gentoo installation to help me debug broken installations, it was legacy BIOS/CSM only.
Now that more and more systems boot solely UEFI I want to upgrade this so that it also boots via UEFI.
I succeeded in a working installation via UEFI boot on an internal disk of a system.
I succeeded in a working installation via UEFI boot solely on USB stick (EFI boot partition and root partition).

So I have my stick, with a shiny new EFI boot partition containing EFI/gentoo/grubx64.efi, but when I try to use it on another system it is not recognized. Thinking about this, well, yes, efibootmgr does store the boot sequence somewhere on the system. But USB boot sticks that are used for first time installation are always recognized by UEFI as bootable. So I'm stuck now, does a portable UEFI boot only work for ISO install images?

1) How to make my rescue system on USB stick recognizable for UEFI boot on every system I plug it into?
2) And how to make it then dual BIOS/UEFI bootable? Just install legacy Grub into protective MBR created by gdisk and it will work, or some more magic needed?

Thank you for any hints in the right direction - I'm rebooting, remounting, patching and retrying the whole day now.... :-/
Back to top
View user's profile Send private message
nick_gentoo
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jan 2019
Posts: 108

PostPosted: Mon Dec 23, 2019 8:53 pm    Post subject: Reply with quote

I could give a hint for the UEFI part. From what I found out earlier this year, the UEFI boot works for a removable drive if the bootloader has a standard name and is placed in a standard location. It should be at
Code:
EFI/BOOT/BOOTX64.efi

I suppose you could simply re-place and rename your EFI/gentoo/grubx64.efi and the computer should boot if it is set to boot from USB.
How did you install the bootloader on the stick? grub-install has the --removable option that does exactly this.
Back to top
View user's profile Send private message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Tue Dec 24, 2019 3:10 pm    Post subject: Reply with quote

Just copying&renaming the grubx64.efi file does not work, but yes, a grub-install with --removable works!
Thank you - as with every problem it is quite easy if you know how :-)

Now on to the second problem, to *also* make this CSM/BIOS bootable.
gdisk makes a protective MBR over the whole disk, so from sector 1 to the end. Thats usually a good idea.
Unfortunately a "grub-install --target=i386-pc /dev/sda" complains with:

Quote:

grub-install: warning: this GPT partition label contains no BIOS boot partition: embedding won't be possible
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.


Hmm... actually the first real partition (here the EFI system part) starts at sector 2048. Install of Grub into the MBR usually worked on old systems by hiding the rest of Grub in the sectors before 2048. This should work similarly here, because the space is free?
So this needs a protective MBR that does not destroy the GPT table but shows Grub where it can put its binary?
Back to top
View user's profile Send private message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Tue Dec 24, 2019 8:28 pm    Post subject: Reply with quote

On a GPT disk Grub definitely wants its own BIOS Boot Partition and places its binary there:
https://www.gnu.org/software/grub/manual/grub/html_node/BIOS-installation.html

I'm not yet sure from all the docs whether to grub-install into MBR (/dev/sda) or this partition (/dev/sdaX),
and if a hybrid MBR needs a boot flagged entry, or not... hm...
Back to top
View user's profile Send private message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Tue Dec 24, 2019 9:21 pm    Post subject: Reply with quote

So I have now in GPT:
Code:
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            8191   3.0 MiB     EF02  BIOS boot partition
   2            8192          131071   60.0 MiB    EF00  EFI System
   3          131072        59725790   28.4 GiB    8300  Linux filesystem


and the hybrid MBR is:
Code:
Number  Boot  Start Sector   End Sector   Status      Code
   1                     1         2047   primary     0xEE
   2                  2048         8191   primary     0xEF
   3                  8192       131071   primary     0xEF
   4      *         131072     59725790   primary     0x83


grub-install -v --target=i386-pc --recheck /dev/sda
...runs ok

...but trying to boot this setup on BIOS - it does not boot :-(
(Putting the "boot" tag on another MBR partition is not different)

What is the last piece missing?
Back to top
View user's profile Send private message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Wed Dec 25, 2019 4:34 pm    Post subject: Reply with quote

For reference, the hybrid partition docs of Gentoo: https://wiki.gentoo.org/wiki/Hybrid_partition_table

But after some searching, I also found:
https://www.linuxquestions.org/questions/linux-hardware-18/grub-can%27t-boot-a-gpt-external-usb-drive-tells-me-device-not-found-4175657952/page4.html
"This is a Grub problem due to the lack of an xhci module for USB3 support."
So in the GPT/MBR hybrid case Grub is somehow unable to access stuff on pure USB3 (xhxi) controllers, this appears to be unimplemented :-/

Testing this with a pure MBR partition table (needed to wipe start with zeros first):
Code:
Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048    81919    79872   39M ef EFI (FAT-12/16/32)
/dev/sda2       81920 61734911 61652992 29,4G 83 Linux


..boots under UEFI as well as CSM legacy mode. Testing sample of one currently.

Open problem: With UEFI all is fine. With CSM/DOS boot Grub menu shows, then screen goes blank and kernel messages don't show, and somewhere during boot process the boot messages show up again. So if a boot ever fails I would not see the error message, that's bad

Ugly: the 39M partition is so large because of minimum size of FAT32, but for max compatibility UEFI really wants FAT32 there? The BOOTX64.EFI file on this partition is only ~230kb ... that's wasteful...
Back to top
View user's profile Send private message
nick_gentoo
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jan 2019
Posts: 108

PostPosted: Wed Dec 25, 2019 6:28 pm    Post subject: Reply with quote

mortonP wrote:
Ugly: the 39M partition is so large because of minimum size of FAT32, but for max compatibility UEFI really wants FAT32 there? The BOOTX64.EFI file on this partition is only ~230kb ... that's wasteful...

Nice to hear that you have some progress :)
Based on this, also FAT12 and FAT16 should be supported. The actual UEFI standard is here and chapter 13.3 is the relevant one.
Back to top
View user's profile Send private message
mortonP
n00b
n00b


Joined: 22 Dec 2015
Posts: 34

PostPosted: Wed Dec 25, 2019 8:48 pm    Post subject: Reply with quote

"EFI encompasses the use of FAT32 for a system partition, and FAT12 or FAT16 for removable media."
so if the standard says so...

From https://www.rodsbooks.com/efi-bootloaders/principles.html
"Some users, however, have found that some EFIs have bugs that cause problems with FAT32 ESPs that are under 512MiB (537MB) in size."

From https://wiki.archlinux.org/index.php/Partitioning#Choosing_between_GPT_and_MBR
"It is recommended to always use GPT for UEFI boot, as some UEFI implementations do not support booting to the MBR while in UEFI mode."
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum