Linutronix / elbe

Embedded Linux Build Environment
https://elbe-rfs.org
GNU General Public License v3.0
170 stars 59 forks source link

hybrid x86_64 bookworm image not working in uefi-bios mode #406

Open estergl opened 7 months ago

estergl commented 7 months ago

Hi,

i have build hybrid bookworm image with the following XML configuration and i wanted to test the grub 2.12-1~bpo12+1 from the bookworm backports. (Elbe version : 14.6.1)

      <gpthd variant="image-uefi">
          <name>target.img</name>
          <size>8400MB</size>
          <grub-install>--efi-directory=/boot/efi --boot-directory=/boot/efi/EFI/BOOT --bootloader-id=grub</grub-install>
          <partition>
            <size>200MB</size>
            <name>EFI</name>
            <label>EFI</label>
            <bootable>true</bootable>
          </partition>
          <partition>
            <size>1MiB</size>
            <name>BIOS</name>
            <label>BIOS</label>
            <biosgrub>true</biosgrub>
          </partition>
          <partition>
            <size>8GB</size>
            <name>ROOT</name>
            <label>ROOT</label>
          </partition>
      </gpthd>

.........
  <fstab>
      <bylabel>
        <label>EFI</label>
        <mountpoint>/boot/efi</mountpoint>
        <fs>
          <type>vfat</type>
        </fs>
      </bylabel>
      <bylabel>
        <label>ROOT</label>
        <mountpoint>/</mountpoint>
        <fs>
          <type>ext2</type>
          <tune2fs />
          <passno>0</passno>
        </fs>
        <options>ro</options>
        <nofstab/>
      </bylabel>
      .......
      .......
      <pkg variant="image-uefi">efibootmgr</pkg>
      <pkg variant="image-uefi">grub-efi-amd64-bin</pkg>  <!-- grub-efi-amd64 conflicts with grub-pc, so install grub-efi-amd64-bin and grub-pc -->
      <pkg variant="image-uefi">grub-pc</pkg>
      <pkg version="6.1.*">linux-image-rt-amd64</pkg>
      .......

The device booted in LEGACY-BIOS boot mode, but not in UEFI-BIOS boot mode. I always get a black screen and can not boot into grub console. The device always boots into BIOS. I'm currently looking for why it doesn't boot in UEFI. After the device booted into legacy mode, I checked the following things:

~$ efibootmgr
EFI variables are not supported on this system.
~$ modprobe efivars
modprobe: FATAL: Module efivars not found in directory /lib/modules/6.1.0-18-rt-amd64
~$  modprobe efivarfs
modprobe: ERROR: could not insert 'efivarfs': No such device
~$  mount -t efivarfs efivarfs /sys/firmware/efi/efivars
mount: /sys/firmware/efi/efivars: mount point does not exist.
       dmesg(1) may have more information after failed mount system call.
~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.1.0-18-rt-amd64 root=PARTLABEL=ROOT ro splash quiet efi=runtime panic=5

The same configuration always works for me with the buster setup.

I would like to clarify a few things here.

  1. Does the small MBR partition have to be defined in the first place or does it make no difference where the esp or mbr partitions are defined?
  2. I had to separate esp partition and install all grub modules on the esp because I have dual copy (A/B) scheme to update the device. The firmware must always boot into the ESP from the hard drive where the first stage grub.cfg (/boot/efi/EFI/BOOT/grub/grub.cfg) is located. This should then load the environment variable from /boot/efi/EFI/BOOT/grub/grubenv and use the environment variables to decide which root file system should be booted. The first stage grub.cfg looks for root file system by label then sets the grub environment variable root to (hdX,gptY). And then the actual second stage (hdX,gptY)/boot/grub/grub.cfg should be sourced from the selected root file system (RootfsA -> (hdX,gpt3)/boot/grub/grub.cfg or RootfsB -> (hdX,gpt4 )/boot/grub/grub.cfg) where the kernel and initrd images are loaded. The first stage grub.cfg file must be called first in both legacy bios mode and uefi bios mode because the decision as to which rootfs to select takes place there. And I need all grub modules (search.bylabel, loadfont, regexp, echo, all_video etc.) in first stage grub.cfg file to implement this mechanism. Is this the correct configuration and implementation with Elbe to achieve this A/B mechanism with Grub bootloader?
t-8ch commented 7 months ago

Does the small MBR partition have to be defined in the first place or does it make no difference where the esp or mbr partitions are defined?

It should not matter. (Except for limitations in your systems firmware)

Is this the correct configuration and implementation with Elbe to achieve this A/B mechanism with Grub bootloader?

This looks reasonable. But there is no one correct way to implement this. It all depends on your requirements.

Did you check that the ESP is big enough? (Unfortunately the elbe error reporting needs some work)

If you post a minimal reproducer XML I can try to take a look.