2

Question: How can I manually boot Linux on EFI systems with Grub?

Where I'm stuck: I'm trying to install a custom kernel, root file system, and grub on an x64 computer. The USB stick has an equivalent installation script and boots, but when I attempt to install the eMMC on the x64 device it displays "Boot option restore". This is a reboot loop and I suspect it has something to do with the way I use Grub.

The images (not mine):

Main screen:

Boot Option Restoration

Available options:

Boot Option Restored

The (simplified) code:

#! /bin/bash
set -e

# Create GPT, partition 1, type BIOS boot, bootable flag
(echo -e "g\nn\n1\n\n+128M\nt\n4\nM\na\nM\nw\n") | fdisk /dev/mmcblk0
sleep 1
mkfs.vfat -N BOOT /dev/mmcblk0p1

# Create partition 2
(echo -e "n\n2\n\n\nY\nw\n") | fdisk /dev/mmcblk0
sleep 1
mkfs.ext4 -F -L ROOTFS /dev/mmcblk0p2

dd if=rootfs of=/dev/mmcblk0p2 conv=fsync
mount /dev/mmcblk0p2 /mnt
mount /dev/mmcblk0p1 /mnt/boot/efi
cp vmlinuz-custom /mnt/boot

chroot /mnt <<-EOF
        mount -t proc none /proc
        mount -t sysfs none /sys
        mount -t devtmpfs none /dev

        # This could be moved out of the chroot, but for is use this.
        update-initramfs -c -k custom

        umount /proc /sys /dev
EOF

grub-install --target=x86_64-efi --removable --recheck \
        --root-directory=/mnt \
        --efi-directory=/mnt/boot/efi \
        --boot-directory=/mnt/boot/efi/EFI \
        --bootloader-id=grub /dev/mmcblk0;

cat > /mnt/boot/efi/EFI/grub/grub.cfg <<-EOF
insmod gzio
insmod part_msdos
insmod part_gpt
insmod ext2
insmod normal
        
search.fs_label BOOT grub
search.fs_label ROOTFS rootfs
        
set prefix=/bogus  # Unavailable prefix (prefix required by Grub)
        
sleep 1
linux (\$rootfs)/boot/vmlinuz-custom root=UUID=$(blkid -o value -s UUID /dev/mmcblk0p2) i915.force_probe=* swiotlb=65536 module_blacklist="pinctrl_elkhartlake,dp83867"
initrd (\$rootfs)/boot/initrd.img-custom
boot
EOF

Already checked:

  • UUIDs seem to be correct in Grub
  • Installation script USB and EMMC are not the same but equivalent.
  • Reset BIOS options to default settings
  • All commands seem to execute correctly

2 Answers 2

1

I can't remember fully, but I think it had something to do with writing Grub. Try to remove --removable. I used it to create the USB and it seems that using it twice seem not to play twice. Also try to remove --recheck.

Eventually I moved EFI-only where my kernel lives on the EFI partition. Through efibootmgr this is handled way better than Grub.

0

I experienced the same blue screen, on a laptop with only Linux (no Windows). In your opinion, to which part of the system does that blue screen belong ? To the BIOS/UEFI (e.g., to the hardware), or to GRUB ?

What I did, in detail :

  • I installed Debian on a SSD, but the ESP (EFI) partition on a USB stick (don't ask me why, it's just for some tests)
  • At first boot everything went fine
  • Then I removed the USB stick containing the ESP partition, and the laptop didn't boot. That was expected, given that it had no more ESP partition
  • Then I plugged in again the USB stick, and it didn't boot either. That was unexpected.

After having read this, I started the process over, but this time I did dpkg-reconfigure grub-efi-amd64 immediately after having Debian installed, and I answered yes to the question Force extra installation to the EFI removable media path ?.

Now it works, but with that extra blue screen :

  • I remove the USB stick with the EFI partition, the laptop doesn't boot. Expected
  • I plug the USB stick back in, now it boots, but shows the blue screen. If I select Continue boot it boots grub, and then Debian.

There is very few information on the web regarding that blue screen. Could you please share your thoughts about it ? Where does it come from, and why does it show ?

2
  • You should've posted is as a new question, but here some thoughts for you: by default on the ESP efi/boot/bootx64.efi is ran. On Debian systems, this runs efi/debian/grubx64.efi, which in turn finds and loads the kernel on your SSD. MOK is "machine owner key", thus not part of the BIOS. This post has some information about MOK. When you have this problem, generally I think you need to reinstall Grub on your system due to faulty configuration. Good luck!
    – Bayou
    Dec 27, 2022 at 12:15
  • Thanks. The blue screen seems to be part of Grub (see github.com/system76/firmware-open/issues/216, someone located the blue screen's text in Grub's source code). In my case all I had to do is select "Always continue boot" to get rid of that blue screen in the subsequent boots. Now my system behaves exactly like I want it to (a Debian distro with EFI and /boot partitions on a USB stick).
    – ChennyStar
    Dec 28, 2022 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .