Files
omarchycn/bin/omarchy-setup-direct-boot
f8c235a5e4 Read /boot as root when looking for the Omarchy UKI (#6653)
* Find the Omarchy UKI as root when setting up direct boot

/boot is mounted with dmask=0077 on encrypted installs, so the
unprivileged find returned nothing and direct boot always reported that
no UKI was present.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Check for the legacy UKI as root when refreshing limine

The unprivileged file tests were always false on encrypted installs, so
the stale <machine-id>_linux.efi was never cleaned up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-09 13:17:28 +02:00

62 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Add or remove an EFI boot entry for the Omarchy UKI, allowing the system to boot directly
# omarchy:requires-sudo=true
if [[ ! -d /sys/firmware/efi ]]; then
echo "Error: System is not booted in UEFI mode" >&2
exit 1
fi
if ! efibootmgr &>/dev/null; then
echo "Error: efibootmgr is not available or not functional" >&2
exit 1
fi
bios_vendor=$(cat /sys/class/dmi/id/bios_vendor 2>/dev/null)
case "${bios_vendor,,}" in
*"american megatrends"*)
echo "Error: American Megatrends firmware may not safely support custom EFI entries" >&2
exit 1
;;
*apple*)
echo "Error: Apple firmware uses its own boot manager" >&2
exit 1
;;
esac
existing_entry=$(efibootmgr | grep -E "^Boot[0-9A-Fa-f]+\*? Omarchy([[:space:]]|$)" | head -1)
if [[ -n $existing_entry ]]; then
boot_num=$(echo "$existing_entry" | sed -n 's/^Boot\([0-9A-Fa-f]\+\).*/\1/p')
if gum confirm "Disable direct boot (remove Omarchy EFI entry)?"; then
echo "Removing EFI boot entry $boot_num"
sudo efibootmgr --bootnum "$boot_num" --delete-bootnum >/dev/null
fi
exit 0
else
uki_file=$(sudo find /boot/EFI/Linux/ -name "omarchy*.efi" -printf "%f\n" 2>/dev/null | head -1)
if [[ -z $uki_file ]]; then
echo "Error: No Omarchy UKI found in /boot/EFI/Linux/" >&2
exit 1
fi
boot_source=$(findmnt -n -o SOURCE /boot)
disk=$(echo "$boot_source" | sed 's/p\?[0-9]*$//')
part=$(echo "$boot_source" | grep -o 'p\?[0-9]*$' | sed 's/^p//')
if gum confirm "Setup direct boot (so snapshot booting must be done via bios)?"; then
echo "Creating EFI boot entry for $uki_file"
sudo efibootmgr --create \
--disk "$disk" \
--part "$part" \
--label "Omarchy" \
--loader "\\EFI\\Linux\\$uki_file"
fi
fi