Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions bin/omarchy-boot-switch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# omarchy:summary=Move this machine from the Limine boot loader to systemd-boot, the boot loader Secure Boot needs
# omarchy:args=[--check] [--yes] | status | revert | install [--no-efi-register] [--no-fallback] [--prefer PKGBASE] [--initramfs PKGBASE=FILE]
# omarchy:args=[--available] [--check] [--yes] | status | revert | install [--no-efi-register] [--no-fallback] [--prefer PKGBASE] [--initramfs PKGBASE=FILE]
# omarchy:examples=omarchy-boot-switch --check | omarchy-boot-switch | omarchy-boot-switch status
# omarchy:requires-sudo=true

Expand Down Expand Up @@ -191,7 +191,10 @@ esp_space_needed() {
echo $(((kernels + 1) * uki_size + 32 * 1024 * 1024))
}

preflight() {
# What the machine is, as opposed to what can be put right before it moves:
# --available asks only this, without root, so the menu offers the switch
# wherever it could ever happen and --check explains the rest.
machine_fits() {
if omarchy-hw-aarch64-apple; then
problem "Apple Silicon boots through m1n1 and its own platform package, not Limine."
elif ! omarchy-hw-x86 && ! omarchy-hw-aarch64; then
Expand All @@ -207,9 +210,25 @@ preflight() {
esac
omarchy-cmd-present limine-entry-tool || problem "This machine doesn't boot Limine through limine-entry-tool, which the switch starts from."

# A snapshot boot mounts / as an overlay; its btrfs root is still underneath.
local fstype fsroot
read -r fstype fsroot < <(findmnt -n -o FSTYPE,FSROOT --mountpoint /)
[[ $fstype == "btrfs" ]] || snapshot_boot || problem "The root filesystem isn't the btrfs @ subvolume Omarchy installs."
}

snapshot_boot() {
grep -qE '(^| )rootflags=([^ ]*,)?subvol=/?@/[.]snapshots/[0-9]+/snapshot( |,|$)' /proc/cmdline
}

preflight() {
machine_fits
local fstype fsroot
read -r fstype fsroot < <(findmnt -n -o FSTYPE,FSROOT --mountpoint /)
[[ $fstype == "btrfs" && $fsroot == /@ ]] || problem "The root filesystem isn't the btrfs @ subvolume Omarchy installs."
if snapshot_boot; then
problem "This boot is a snapshot. Start the live system to switch."
elif [[ $fstype == "btrfs" && $fsroot != /@ ]]; then
problem "The root filesystem isn't the btrfs @ subvolume Omarchy installs."
fi
[[ $(findmnt -n -o FSTYPE --mountpoint "$ESP") == "vfat" ]] || problem "The EFI system partition isn't mounted at $ESP."
[[ -f /etc/snapper/configs/root ]] || problem "Snapper isn't set up, so there would be no snapshots to boot."
[[ -f $LOADER_SOURCE ]] || problem "systemd-boot isn't installed ($LOADER_SOURCE)."
Expand Down Expand Up @@ -783,6 +802,10 @@ run_preflight() {
}

case ${1:-} in
--available)
machine_fits
((${#problems[@]} == 0))
;;
--check)
if ((EUID != 0)); then exec sudo "$0" --check; fi
run_preflight && say "This machine can move to systemd-boot."
Expand Down Expand Up @@ -850,7 +873,7 @@ EOF
fi
;;
*)
echo "Usage: omarchy-boot-switch [--check] [--yes] | status | revert | install [--no-efi-register] [--no-fallback] [--prefer PKGBASE] [--initramfs PKGBASE=FILE]" >&2
echo "Usage: omarchy-boot-switch [--available] [--check] [--yes] | status | revert | install [--no-efi-register] [--no-fallback] [--prefer PKGBASE] [--initramfs PKGBASE=FILE]" >&2
exit 2
;;
esac
42 changes: 42 additions & 0 deletions bin/omarchy-update-secure-bootloader
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# omarchy:summary=Move this machine to systemd-boot, the boot loader Secure Boot needs, for good
# omarchy:requires-sudo=true

set -euo pipefail

if [[ $(omarchy-boot-backend) == "systemd-boot" ]]; then
# Finishes a switch that is waiting on its last boot, or says it's done.
omarchy-boot-switch
else
echo ""
echo "⚠️ WARNING: This is a one-way street."
echo ""
echo "Omarchy moves this machine from the Limine boot loader to systemd-boot."
echo "Once systemd-boot has proved it starts the machine, Limine is removed"
echo "and the switch can't be undone."
echo ""
echo "systemd-boot is the boot loader Secure Boot needs. Switching makes it"
echo "possible to turn on Secure Boot in a future Omarchy release, and with it"
echo "Easy Anti-Cheat for games like Fortnite."
echo ""
echo "Snapshots taken before the switch can't be booted from systemd-boot, so"
echo "they are deleted when it finishes. Other systems in Limine's menu may"
echo "leave the boot menu (the check below names them): make sure the firmware's"
echo "boot menu can start them before you switch."
echo ""
echo "The first boot on systemd-boot is a trial: if it doesn't come up, a reset"
echo "brings back Limine."
echo ""

if ! omarchy-boot-switch --check; then
exit 1
elif gum confirm "Switch to the secure bootloader? There is no going back."; then
omarchy-boot-switch --yes
if gum confirm "Reboot now to start the trial?"; then
omarchy-system reboot
fi
else
echo "Aborted. No changes made."
fi
fi
4 changes: 4 additions & 0 deletions default/i18n/en/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,10 @@
"update.omarchy": {
"label": "Omarchy"
},
"update.bootloader": {
"label": "Secure Bootloader",
"description": "Move to systemd-boot for Secure Boot"
},
"update.channel": {
"label": "Channel"
},
Expand Down
1 change: 1 addition & 0 deletions default/omarchy/omarchy-menu.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@

// Update
"update.omarchy": {"icon":"","iconFont":"omarchy","label":"Omarchy","action":"omarchy-launch-floating-terminal-with-presentation omarchy-update"},
"update.bootloader": {"icon":"󰒃","label":"Secure Bootloader","description":"Move to systemd-boot for Secure Boot","when":"[[ $(omarchy-boot-backend) == \"limine\" ]] && omarchy-boot-switch --available","action":"omarchy-launch-floating-terminal-with-presentation omarchy-update-secure-bootloader"},
"update.channel": {"icon":"󰔫","label":"Channel"},
"update.kernel": {"icon":"","label":"Kernel","when":"(( $(omarchy-kernel list | wc -l) > 1 ))","provider":"kernels"},
"update.config": {"icon":"","label":"Config","title":"Reset to default"},
Expand Down
4 changes: 3 additions & 1 deletion docs/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The pipeline:

## The switch

Update > Secure Bootloader (`omarchy-update-secure-bootloader`) is how a person starts it: a one-way warning, then `--check`, one confirmation and `--yes`. The row shows only where `omarchy-boot-switch --available` passes, which asks without root what the machine is: its platform, UEFI, not an Intel Mac, not already switched, Limine through `limine-entry-tool`, a btrfs root. Everything that can be put right first (booted into a snapshot, the ESP, snapper, owner setup, a running transaction, this version's initramfs hooks, free space) is left to `--check`, so the row never vanishes over something with a remedy and the terminal says what it is.

`omarchy-boot-switch` records its phase in `$STORE/state`.

- **`staged`.**
Expand Down Expand Up @@ -72,7 +74,7 @@ The pipeline:

`omarchy-boot-backend` recognises such a machine by `omarchy-boot-systemd`'s snapper plugin, even where the store isn't mounted (a factory clone). A factory reset of it runs the same install in the clone, into a fresh `@omarchy-boot-next` store that replaces the old owner's `@omarchy-boot` once the clone is at `@`; the old owner's images leave the ESP then too. BIOS installs keep Limine: systemd-boot can't start on BIOS firmware. `OMARCHY_ISO_BOOT_LOADER=limine` keeps a UEFI install on Limine.

Nothing offers the switch yet: no update prompt and no menu entry. `omarchy-boot-switch` runs it for anyone who asks. Once the Microsoft-signed shim ships, an update will offer it as "Upgrade to Secure Boot", together with the shim and Omarchy-signed kernels. `omarchy-boot-notify`, a user service at login, shows what the root side recorded (`notice_*` in the state).
Update > Secure Bootloader offers the switch to anyone who looks for it; no update prompts for it. Once the Microsoft-signed shim ships, an update will offer it as "Upgrade to Secure Boot", together with the shim and Omarchy-signed kernels. `omarchy-boot-notify`, a user service at login, shows what the root side recorded (`notice_*` in the state).

## Restore

Expand Down