Skip to content
Open
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
20 changes: 20 additions & 0 deletions bin/omarchy-boot-sync
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ bootable_snapshots() {
done | sort -rn | head -n "$MAX_SNAPSHOTS"
}

# Deleting a snapshot, snapper removes the files it wrote and then the
# directory, which the pin keeps it from doing: the pin stays behind, and the
# image it names with it. Drops the pins of snapshots that are gone, and their
# directories, except the highest-numbered one, which snapper keeps itself so
# a number is never used twice.
drop_deleted_pins() {
local dir num highest=0
for dir in "$(snapshots_dir)"/*/; do
num=$(basename "$dir")
if [[ $num =~ ^[0-9]+$ ]] && ((num > highest)); then highest=$num; fi
done
for dir in "$(snapshots_dir)"/*/; do
num=$(basename "$dir")
[[ $num =~ ^[0-9]+$ && -f $dir/omarchy-boot-image && ! -d $dir/snapshot ]] || continue
rm -f "$dir/omarchy-boot-image"
if ((num != highest)); then rmdir "$dir" 2>/dev/null || true; fi
done
}

snapshot_details() {
local info=$1 desc date
desc=$(info_field "$info" description)
Expand Down Expand Up @@ -426,6 +445,7 @@ cmd_sync() {
rm -rf "$STORE"/tmp/build.*
# Boot images no longer carry a splash; a store from before keeps none.
rm -f "$STORE/splash.bmp"
drop_deleted_pins

local ns preferred pkgbase kver image num dir file id
local -A profiles=() wanted=()
Expand Down
2 changes: 1 addition & 1 deletion docs/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ On systemd-boot, every kernel build is a boot image.
- **Published state.** `$STORE/entries` maps profile IDs to entry IDs. The sync sets `loader.conf`'s `default` to the preferred kernel's live entry (`omarchy-boot-sync prefer PKGBASE`, used by `omarchy-kernel set`).
- **Writing and cleanup.** Images are written beside the old file and renamed over it, after checking ESP space. The sync deletes only its own namespace's files, and never the image a pending one-shot boot points at.

A snapshot is pinned to the image that was current when it was taken (`/.snapshots/N/omarchy-boot-image`), not just to a kernel version. Rolling back from a broken kernel, initramfs or command-line change therefore boots the old ones. Images stay while a pin, the current pointer, the backup or a pending restore needs them.
A snapshot is pinned to the image that was current when it was taken (`/.snapshots/N/omarchy-boot-image`), not just to a kernel version. Rolling back from a broken kernel, initramfs or command-line change therefore boots the old ones. Images stay while a pin, the current pointer, the backup or a pending restore needs them. Snapper leaves the pin of a snapshot it deletes behind, since it only removes its own files; the next sync drops it.

The pipeline:

Expand Down
19 changes: 19 additions & 0 deletions test/shell.d/boot-sync-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ sync_boot
[[ -L $test_tmp/store/current/linux-omarchy ]] || fail "a root without kernels drops no current image"
pass "a root that shows no kernels keeps every current image"

# snapper deletes a snapshot's subvolume and info.xml but not the pin, so the
# snapshot's directory stays with the pin in it. The pin goes with the next
# sync, and the image only it named; the highest-numbered directory stays, as
# snapper keeps it to never reuse a number.
new_machine
add_image old linux-omarchy 7.1
add_snapshot "$test_tmp/top/@" 1 old
add_snapshot "$test_tmp/top/@" 2 live
rm -rf "$test_tmp/top/@/.snapshots/1/snapshot" "$test_tmp/top/@/.snapshots/1/info.xml"
sync_boot
[[ ! -e $test_tmp/top/@/.snapshots/1 && ! -d $test_tmp/store/images/old ]] ||
fail "a deleted snapshot's pin and the image only it named go" "$(find "$test_tmp/top/@/.snapshots" "$test_tmp/store/images" -maxdepth 2)"
grep -q "^snapshot-2"$'\t' "$test_tmp/store/entries" || fail "a snapshot that is still there keeps its entry" "$(cat "$test_tmp/store/entries")"
rm -rf "$test_tmp/top/@/.snapshots/2/snapshot" "$test_tmp/top/@/.snapshots/2/info.xml"
sync_boot
[[ -d $test_tmp/top/@/.snapshots/2 && ! -e $test_tmp/top/@/.snapshots/2/omarchy-boot-image ]] ||
fail "the highest-numbered snapshot's directory stays without its pin" "$(find "$test_tmp/top/@/.snapshots")"
pass "a snapshot snapper deleted stops keeping its boot image"

# A pending restore of a snapshot on another image: the restored root's entry
# is that image's second profile while the snapshot is listed on it, and its
# first once the snapshot is gone. The journal follows.
Expand Down