Skip to content

Instantly share code, notes, and snippets.

@owenthewizard
Last active September 8, 2017 18:53
Show Gist options
  • Save owenthewizard/b6c84fa3a149fb10d88e3e8f893ae13a to your computer and use it in GitHub Desktop.
Save owenthewizard/b6c84fa3a149fb10d88e3e8f893ae13a to your computer and use it in GitHub Desktop.
Script to add kernels in /boot (or another EFI directory) to efibootmgr.
#!/bin/bash
# update-efibootmgr.sh
# Update UEFI boot entries using efibootmgr
# TODO: remove old entries, could use efibootmgr -v?
set -eu
set -o pipefail
distro="Funtoo Linux"
efidir="/boot"
partuuid=$(blkid -o value $(findmnt / -o source | tail -n1) | tail -n1)
disk=$(findmnt --target=/boot -o source | tail -n1)
part=${disk##*/}
part=${part#*sd[a-z]}
disk=${disk%[1-9]*}
for kernel in ${efidir}/vmlinuz*; do # Add kernels in $efidir
kernel=${kernel#${efidir}/}
efibootmgr -q -c -d ${disk} -p ${part} -L "${distro} ${kernel#vmlinuz-}" \
-l /${kernel} -u root=PARTUUID=${partuuid} rw
efibootmgr -q -c -d ${disk} -p ${part} -L "${distro} ${kernel#vmlinuz-} (Rescue)" \
-l /${kernel} -u root=PARTUUID=${partuuid} rw init=/bin/bash
done
efibootmgr # print boot entries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment