Skip to content

Instantly share code, notes, and snippets.

@emilcarr
Created March 15, 2021 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilcarr/17eca4aff30abd6c854745461ece2c70 to your computer and use it in GitHub Desktop.
Save emilcarr/17eca4aff30abd6c854745461ece2c70 to your computer and use it in GitHub Desktop.
Create an EFI Stub bootloader for those times GRUB refuses to behave.

EFI Stub

Sometimes GRUB refuses to behave. In those cases, unless you are dual booting, you can make an EFI Stub to boot directly into linux. You must be using an EFI system partition.

Setup

Install efibootmgr

Arch Linux:

# pacman -S efibootmgr

Debian:

# apt install efibootmgr

Usage

Get distribution name:

DIST=$(lsb_release -a | awk '/Description/ {print $2}')

Create a directory in /boot/EFI:

# mkdir /boot/EFI/$DIST

Copy linux and initramfs images to this directory:

# cp /vmlinuz /boot/efi/EFI/$efidir
# cp /initrd.img /boot/efi/EFI/$efidir

Create kernel and initramfs post install scripts to do this automatically:

/etc/initramfs/post-update.d/ (debian only ? )

#!/bin/sh

DIST=$(lsb_release -a | awk '/Description/ {print $2}')

echo "Copying initrd.img to /boot/efi/EFI/$DIST for EFIStub"
cp /initrd.img /boot/efi/EFI/$DIST

/etc/kernel/postinst.d/

#!/bin/sh

DIST=$(lsb_release -a | awk '/Description/ {print $2}')

echo "Copying vmlinuz to /boot/efi/EFI/$DIST for EFIStub"
cp /vmlinuz /boot/efi/EFI/$DIST'

Finally, create the EFI stub:

# UUID=$(blkid -s UUID -o value $part)
# efibootmgr --create --gpt --disk $disk --part $num --label "$label" --loader "\EFI\\$DIST\vmlinuz" --unicode "initrd=\EFI\\$efidir\initrd.img root=UUID=$UUID rw quiet" --verbose

Where:

  • $part is the linux root partition name (eg /dev/nvme1n1p2)
  • $label is the label you want the EFI stub to have in the BIOS
  • $disk is the device containing the EFI partion (eg /dev/nvme1n1)
  • $num is the partition number of the EFI partition (eg 1 = /dev/nvme1n1p1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment