From 7428d62687f353b532c66e01fbfb33e8adcac511 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Thu, 29 Oct 2026 15:48:20 -0400 Subject: [PATCH 1/2] omamobile-omarchy 0.1.21: keep the next boot's kernel modules, and prune old ones Omarchy's base packages include kernel-modules-hook, and its installer enables linux-modules-cleanup.service, which at every boot moves each /usr/lib/modules/ that isn't the running kernel and that no package owns into /usr/lib/modules/.old. A phone's kernels never come from pacman: bin/omamobile modules-push unpacks the next boot's tree ahead of the reboot. So any boot between a push and the reboot into the new kernel took that tree away, and the new kernel came up with no drivers (cheetah NOTES, 2026-10-27). Every replaced tree (about 94 MB) also piled up in .old for good. fix belongs here (review lesson L-233). omamobile-omarchy is on every phone: - a drop-in holds linux-modules-cleanup off while this package's version file exists; - omamobile-modules-cleanup.timer (enabled by a staged timers.target.wants link) runs lib/modules-cleanup ten minutes after boot, at idle priority with a timeout, so nothing on the boot path waits for it. It keeps the running release, every tree that arrived during this boot (marker or tree mtime, or the tree's ctime, after /proc/stat's btime: the next boot's kernel, even mid-push), every pacman-owned tree and the two newest others by marker mtime (rollback), and rm -rf's the rest. Only direct [0-9]* children are candidates; symlinks, .old and dot-dirs (a push's ..new) are never touched, and nothing is removed when pacman can't read its database. --dry-run (or OMAMOBILE_MODULES_CLEANUP_DRY_RUN=1) shows what it would do. A removed tree is recoverable: push re-sends a tree whose marker is missing. test/modules-cleanup.sh runs it against a scratch module root with stub uname and pacman; test/all also checks the staged drop-in, units, script and wants link, and runs systemd-analyze verify on the units. Co-Authored-By: Claude Opus 5.5 --- docs/RELEASES.md | 2 + packages/omamobile-omarchy/PKGBUILD | 2 +- packages/omamobile-omarchy/install | 14 +- .../omamobile-omarchy/lib/modules-cleanup | 113 +++++++++++++++++ .../10-omamobile.conf | 10 ++ .../systemd/omamobile-modules-cleanup.service | 18 +++ .../systemd/omamobile-modules-cleanup.timer | 15 +++ packages/omamobile-omarchy/test/all | 27 +++- .../omamobile-omarchy/test/modules-cleanup.sh | 120 ++++++++++++++++++ packages/omamobile-omarchy/version | 2 +- 10 files changed, 318 insertions(+), 5 deletions(-) create mode 100755 packages/omamobile-omarchy/lib/modules-cleanup create mode 100644 packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf create mode 100644 packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.service create mode 100644 packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.timer create mode 100644 packages/omamobile-omarchy/test/modules-cleanup.sh diff --git a/docs/RELEASES.md b/docs/RELEASES.md index 9b9d3a98b..1da192ce1 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -223,6 +223,8 @@ The kernel is not touched: it still reaches the phone through `bin/omamobile pus **The phone's update UI** is `omamobile-shell`'s `omamobile.update` sheet: a toast when Omarchy has a release (tap to open) and Update > Omarchy in the menu open it; it shows what's new, the battery and the phone patches, asks for the PIN, shows progress with the output under Details, and ends on the result. The run is a systemd user unit, so it survives the shell restart at its end. +**Kernel module trees.** Omarchy enables `kernel-modules-hook`'s `linux-modules-cleanup.service`, which at every boot moves each `/usr/lib/modules/` that isn't running and that no package owns into `.old`. A phone's kernels come from `bin/omamobile push`, so a boot between a push and the reboot into the new kernel took the next kernel's modules away (cheetah NOTES, 2026-10-27). `omamobile-omarchy` 0.1.14 holds that unit off with a drop-in and runs `omamobile-modules-cleanup.timer` ten minutes after boot instead: it keeps the running release, every tree pushed during this boot, every pacman-owned tree and the two newest others, and removes the rest (`/usr/lib/omamobile-omarchy/modules-cleanup --dry-run` shows what it would do). A removed tree comes back with the next `push`, which re-sends a tree whose `.omamobile-tarball` marker is missing. It never touches `.old`; trees moved there before 0.1.14 can be deleted by hand. + ## 6. Release bundles and the installer For a first install, or to recover a phone that won't boot. One bundle per device per release. diff --git a/packages/omamobile-omarchy/PKGBUILD b/packages/omamobile-omarchy/PKGBUILD index b4e21bdbe..9584abe80 100644 --- a/packages/omamobile-omarchy/PKGBUILD +++ b/packages/omamobile-omarchy/PKGBUILD @@ -3,7 +3,7 @@ pkgname=omamobile-omarchy pkgver=$(cat "${startdir:-.}/version") pkgrel=1 -pkgdesc="Omarchy Mobile's Omarchy patches, re-applied after every Omarchy upgrade, and omamobile-update, Omarchy's update for a phone" +pkgdesc="Omarchy Mobile's Omarchy patches, re-applied after every Omarchy upgrade, omamobile-update, Omarchy's update for a phone, and a kernel module cleanup that keeps the next boot's modules" arch=(any) url="https://github.com/derekross/omarchy-mobile" license=(MIT) diff --git a/packages/omamobile-omarchy/install b/packages/omamobile-omarchy/install index 5dc12bc8e..110562919 100755 --- a/packages/omamobile-omarchy/install +++ b/packages/omamobile-omarchy/install @@ -1,7 +1,9 @@ #!/bin/bash # SPDX-License-Identifier: MIT -# Stage omamobile-omarchy into DESTDIR. Activates nothing by itself: the pacman -# hook applies the patch series after the package transaction. +# Stage omamobile-omarchy into DESTDIR. The pacman hook applies the patch +# series after the package transaction; the module-tree cleanup's timer is +# enabled by the wants link staged here, and Arch's linux-modules-cleanup is +# held off by a drop-in (lib/modules-cleanup says why). # ./install DESTDIR set -euo pipefail cd -- "$(dirname -- "${BASH_SOURCE[0]}")" @@ -13,6 +15,14 @@ for f in lib/update-bin/*; do install -Dm755 "$f" "$d/usr/lib/omamobile-omarchy/update-bin/${f##*/}" done install -Dm755 lib/lock-pam "$d/usr/lib/omamobile-omarchy/lock-pam" +install -Dm755 lib/modules-cleanup "$d/usr/lib/omamobile-omarchy/modules-cleanup" +u=$d/usr/lib/systemd/system +install -Dm644 systemd/omamobile-modules-cleanup.service "$u/omamobile-modules-cleanup.service" +install -Dm644 systemd/omamobile-modules-cleanup.timer "$u/omamobile-modules-cleanup.timer" +install -Dm644 systemd/linux-modules-cleanup.service.d/10-omamobile.conf \ + "$u/linux-modules-cleanup.service.d/10-omamobile.conf" +install -d "$u/timers.target.wants" +ln -sfn ../omamobile-modules-cleanup.timer "$u/timers.target.wants/omamobile-modules-cleanup.timer" for f in patches/*.patch; do install -Dm644 "$f" "$d/usr/share/omamobile/omarchy/patches/${f##*/}" done diff --git a/packages/omamobile-omarchy/lib/modules-cleanup b/packages/omamobile-omarchy/lib/modules-cleanup new file mode 100755 index 000000000..8d73c9a13 --- /dev/null +++ b/packages/omamobile-omarchy/lib/modules-cleanup @@ -0,0 +1,113 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Prune old kernel module trees on a phone, keeping the ones a boot needs. +# +# Omarchy's kernel-modules-hook runs linux-modules-cleanup.service at every +# boot, which moves each /usr/lib/modules/ that isn't the running +# kernel and that no package owns into /usr/lib/modules/.old. A phone's +# kernels never come from pacman: `bin/omamobile modules-push` unpacks the +# next boot's tree and writes /.omamobile-tarball, so any boot +# between the push and the reboot into the new kernel took that tree away, +# and the new kernel came up without drivers (cheetah NOTES, 2026-10-27). +# This package holds that unit off (linux-modules-cleanup.service.d) and runs +# this instead, from omamobile-modules-cleanup.timer, well after boot. +# +# It keeps, in /usr/lib/modules: +# - the running release (uname -r); +# - every tree that arrived during this boot: its marker's mtime, or the +# tree's mtime or ctime (a rename sets it), is after the boot time +# (/proc/stat btime): that is the next boot's kernel (ctime counts only +# here, so a push caught before it writes its marker is kept too); +# - every tree a package owns (pacman -Qo); +# - the KEEP (2) newest of the rest, by marker mtime (else the tree's +# mtime): the rollback kernels. +# and removes the others with rm -rf. Only direct children named like a +# release ([0-9]*) are candidates; symlinks, dot-directories (.old, the +# ..new of a push in progress) and plain files are never touched. +# A removed tree is recoverable: `bin/omamobile push` re-sends a tree whose +# marker is missing. When pacman can't answer, nothing is removed. +# +# modules-cleanup [--dry-run] +# Environment: +# OMAMOBILE_MODULES_CLEANUP_DRY_RUN=1 the same as --dry-run +# OMAMOBILE_MODULES_ROOT the module root (/usr/lib/modules) +# OMAMOBILE_MODULES_KEEP rollback trees kept (2) +# OMAMOBILE_PROC_STAT where btime is read (/proc/stat; tests) +set -euo pipefail + +dry=${OMAMOBILE_MODULES_CLEANUP_DRY_RUN:-} +[[ $dry == 0 ]] && dry= +case ${1:-} in + --dry-run) dry=1 ;; + '') ;; + *) echo "Usage: modules-cleanup [--dry-run]" >&2; exit 2 ;; +esac +root=${OMAMOBILE_MODULES_ROOT:-/usr/lib/modules} +keep=${OMAMOBILE_MODULES_KEEP:-2} +[[ $keep =~ ^[0-9]+$ ]] || { echo "modules-cleanup: OMAMOBILE_MODULES_KEEP must be a number" >&2; exit 2; } +log() { echo "modules-cleanup: $*"; } + +if [[ ! -d $root || -L $root ]]; then + log "no directory $root; nothing to do" + exit 0 +fi +running=$(uname -r) +btime=$(awk '$1 == "btime" { print $2; exit }' "${OMAMOBILE_PROC_STAT:-/proc/stat}") +[[ $btime =~ ^[0-9]+$ ]] || { log "no boot time in ${OMAMOBILE_PROC_STAT:-/proc/stat}; nothing removed"; exit 1; } +# Without a working package database "not owned" can't be told from an error +pacman -Qq >/dev/null 2>&1 || { log "pacman can't read its database; nothing removed"; exit 1; } + +# When the tree came: its marker's mtime (modules-push writes it last), else +# the tree's mtime (depmod's files land in it). Rollback trees rank by this. +pushed() { + if [[ -f $1/.omamobile-tarball && ! -L $1/.omamobile-tarball ]]; then + stat -c %Y -- "$1/.omamobile-tarball" + else + stat -c %Y -- "$1" + fi +} +# Whether it arrived during this boot: also the tree's own mtime and ctime, +# so a push caught between its rename into place and its marker counts too +arrived() { + local m c + read -r m c < <(stat -c '%Y %Z' -- "$1") + (( $2 >= btime || m >= btime || c >= btime )) +} + +rest=() +for tree in "$root"/[0-9]*; do + [[ -e $tree || -L $tree ]] || continue # the glob matched nothing + name=${tree##*/} + if [[ -L $tree || ! -d $tree ]]; then + log "skip $name: not a directory" + continue + fi + if [[ $name == "$running" ]]; then + log "keep $name: running" + continue + fi + t=$(pushed "$tree") + if arrived "$tree" "$t"; then + log "keep $name: arrived during this boot (the next boot's kernel)" + continue + fi + if owner=$(pacman -Qqo -- "$tree" 2>/dev/null); then + log "keep $name: owned by ${owner//$'\n'/ }" + continue + fi + rest+=("$t $name") +done + +n=0 +while read -r t name; do + [[ -n $name ]] || continue + if (( n < keep )); then + n=$((n + 1)) + log "keep $name: rollback ($(date -d "@$t" '+%F %T' 2>/dev/null || echo "$t"))" + elif [[ -n $dry ]]; then + log "would remove $name (dry run)" + else + log "remove $name" + rm -rf --one-file-system -- "${root:?}/$name" + fi +done < <(printf '%s\n' "${rest[@]+"${rest[@]}"}" | sort -rn) diff --git a/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf b/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf new file mode 100644 index 000000000..3834d9185 --- /dev/null +++ b/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT +[Unit] +# A phone's kernels come as modules trees from `bin/omamobile modules-push`, +# never from pacman. Arch's cleanup moves every tree that isn't the running +# kernel and that no package owns to /usr/lib/modules/.old at each boot, so a +# boot between a push and the reboot into the new kernel took the next +# kernel's drivers away, and old trees piled up in .old. Held off while this +# package is installed; omamobile-modules-cleanup.timer prunes instead, +# keeping the running, next-boot and rollback trees. +ConditionPathExists=!/usr/share/omamobile/omarchy/version diff --git a/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.service b/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.service new file mode 100644 index 000000000..cb66c913b --- /dev/null +++ b/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.service @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=Prune old kernel module trees (keeps the running, next-boot and rollback ones) +Documentation=file:///usr/lib/omamobile-omarchy/modules-cleanup +ConditionPathIsDirectory=/usr/lib/modules + +[Service] +Type=oneshot +ExecStart=/usr/lib/omamobile-omarchy/modules-cleanup +# Started by its timer well after boot, at idle priority, and never for long +Nice=19 +IOSchedulingClass=idle +TimeoutStartSec=5min +ProtectSystem=strict +ReadWritePaths=/usr/lib/modules +PrivateTmp=yes +PrivateNetwork=yes +NoNewPrivileges=yes diff --git a/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.timer b/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.timer new file mode 100644 index 000000000..26b28067b --- /dev/null +++ b/packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.timer @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +# Ten minutes after boot rather than at boot: nothing on the boot path waits +# for it, it doesn't compete with the session for storage, and the boot it +# runs in has already started its kernel. A phone that never stays up that +# long only keeps a few more trees until one does. Enabled by the package's +# own timers.target.wants link. +[Unit] +Description=Prune old kernel module trees after boot + +[Timer] +OnBootSec=10min +AccuracySec=1min + +[Install] +WantedBy=timers.target diff --git a/packages/omamobile-omarchy/test/all b/packages/omamobile-omarchy/test/all index a2d3fd46b..c1f63713f 100755 --- a/packages/omamobile-omarchy/test/all +++ b/packages/omamobile-omarchy/test/all @@ -9,7 +9,8 @@ cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } pass() { printf 'ok - %s\n' "$1"; } -for f in install omamobile-omarchy.install lib/update-bin/* lib/lock-pam test/update.sh test/lock-pam.sh test/lock-glance test/sleep-lock.sh; do +for f in install omamobile-omarchy.install lib/update-bin/* lib/lock-pam lib/modules-cleanup test/update.sh \ + test/lock-pam.sh test/lock-glance test/sleep-lock.sh test/modules-cleanup.sh; do bash -n "$f" || fail "$f parses" done for f in bin/omamobile-omarchy-patches bin/omamobile-update test/patches.py; do @@ -39,6 +40,30 @@ done grep -q AbortOnFail "$hook" && fail "hook: a failed re-patch must not abort pacman" pass "the hook re-applies after Omarchy or this package changes" +# The module-tree cleanup: Arch's unit held off, ours staged and enabled +u=$t/stage/usr/lib/systemd/system +[[ -x $t/stage/usr/lib/omamobile-omarchy/modules-cleanup ]] || fail "modules-cleanup staged executable" +for f in omamobile-modules-cleanup.service omamobile-modules-cleanup.timer linux-modules-cleanup.service.d/10-omamobile.conf; do + [[ -f $u/$f ]] || fail "not staged: $f" +done +[[ $(readlink "$u/timers.target.wants/omamobile-modules-cleanup.timer") == ../omamobile-modules-cleanup.timer ]] \ + || fail "the cleanup timer is enabled by a vendor wants link" +grep -qxF 'ConditionPathExists=!/usr/share/omamobile/omarchy/version' "$u/linux-modules-cleanup.service.d/10-omamobile.conf" \ + || fail "the drop-in holds linux-modules-cleanup off on this package's version file" +grep -qxF '[Unit]' "$u/linux-modules-cleanup.service.d/10-omamobile.conf" || fail "the drop-in's condition is in [Unit]" +grep -qxF 'ExecStart=/usr/lib/omamobile-omarchy/modules-cleanup' "$u/omamobile-modules-cleanup.service" || fail "the unit runs the script" +grep -qxF 'Type=oneshot' "$u/omamobile-modules-cleanup.service" || fail "the unit is a oneshot" +grep -q '^TimeoutStartSec=' "$u/omamobile-modules-cleanup.service" || fail "the unit can't hang" +grep -q '^WantedBy=\|^RequiredBy=\|^Before=' "$u/omamobile-modules-cleanup.service" && fail "nothing on the boot path waits for the unit" +grep -qx 'OnBootSec=[0-9]*min' "$u/omamobile-modules-cleanup.timer" || fail "the timer starts it after boot" +if command -v systemd-analyze >/dev/null; then + systemd-analyze verify --root="$t/stage" --man=no "$u/omamobile-modules-cleanup.service" "$u/omamobile-modules-cleanup.timer" 2>&1 \ + | grep -v "linux-modules-cleanup\|Failed to prepare filename\|is not executable" | grep . \ + && fail "systemd-analyze verify" +fi +pass "install stages the module cleanup, its timer's wants link and the drop-in for Arch's" +bash test/modules-cleanup.sh || fail "modules-cleanup" + # Every patch file says what it is for, before its first diff for p in patches/*.patch; do [[ $(sed -n '1p' "$p") == \#* || $(sed -n '1p' "$p") == commit* ]] || fail "$p starts with a header" diff --git a/packages/omamobile-omarchy/test/modules-cleanup.sh b/packages/omamobile-omarchy/test/modules-cleanup.sh new file mode 100644 index 000000000..ec588beeb --- /dev/null +++ b/packages/omamobile-omarchy/test/modules-cleanup.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# lib/modules-cleanup against a scratch module root: fake trees with set +# mtimes, a stub uname and pacman on PATH, and a fake /proc/stat for the boot +# time. Run from the package directory (test/all does). +set -euo pipefail +fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } +pass() { printf 'ok - %s\n' "$1"; } + +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +tool=$PWD/lib/modules-cleanup +mkdir -p "$t/bin" +cat > "$t/bin/uname" <<'EOF' +#!/bin/bash +[[ ${1:-} == -r ]] && { echo 7.3.0-running; exit 0; } +exec /usr/bin/uname "$@" +EOF +# Owns 6.0.0-pkg and nothing else; -Qq lists packages +cat > "$t/bin/pacman" <<'EOF' +#!/bin/bash +case $1 in + -Qq) echo linux; exit 0 ;; + -Qqo) [[ ${@: -1} == */6.0.0-pkg ]] && { echo linux; exit 0; } + echo "error: No package owns ${@: -1}" >&2; exit 1 ;; +esac +exit 1 +EOF +chmod +x "$t/bin/uname" "$t/bin/pacman" +cp "$t/bin/pacman" "$t/pacman.good" + +boot=$(( $(date +%s) - 3600 )) # the trees' times count back from here + +# tree NAME AGE_BEFORE_BOOT_SECONDS [marker]: a tree whose files and marker +# carry that time. +tree() { + local d=$t/root/$1 when=$(( boot - $2 )) + mkdir -p "$d/kernel" + echo x > "$d/kernel/a.ko" + [[ ${3:-} == marker ]] && echo sha > "$d/.omamobile-tarball" + find "$d" -mindepth 1 -exec touch -h -d "@$when" {} + + touch -d "@$when" "$d" +} +setup() { + rm -rf "$t/root"; mkdir -p "$t/root" + tree 7.3.0-running 90000 marker + tree 7.3.0-pushed 99999 marker # the marker is rewritten below + tree 6.0.0-pkg 99999 + tree 7.2.0-new1 1000 marker + tree 7.2.0-new2 2000 # no marker: the tree's mtime + tree 7.1.0-old1 3000 marker + tree 7.0.0-old2 4000 marker + mkdir -p "$t/root/.old/6.9.0-moved" "$t/root/.7.4.0.new/7.4.0" + mkdir -p "$t/outside/6.8.0-target/kernel" + ln -s "$t/outside/6.8.0-target" "$t/root/6.8.0-link" + echo keep > "$t/outside/6.8.0-target/kernel/b.ko" +} +# ctime can't be set, and every scratch tree's is "now", so each run boots +# one second from now: no ctime counts as "arrived during this boot", and +# the pushed tree's marker, 600 s after that boot, does. +run() { + local b=$(( $(date +%s) + 1 )) + if [[ -e $t/root/7.3.0-pushed ]]; then touch -d "@$(( b + 600 ))" "$t/root/7.3.0-pushed/.omamobile-tarball"; fi + printf 'cpu 1 2 3\nbtime %s\nprocesses 1\n' "$b" > "$t/stat" + PATH=$t/bin:$PATH OMAMOBILE_MODULES_ROOT=$t/root OMAMOBILE_PROC_STAT=$t/stat "$tool" "$@" +} +left() { (cd "$t/root" && ls -A | LC_ALL=C sort | tr '\n' ' '); } + +setup +before=$(left) +out=$(OMAMOBILE_MODULES_CLEANUP_DRY_RUN=1 run) || fail "dry run exits 0" +[[ $(left) == "$before" ]] || fail "dry run removes nothing: $(left)" +grep -qxF 'modules-cleanup: would remove 7.1.0-old1 (dry run)' <<<"$out" || fail "dry run names old1: $out" +out=$(run --dry-run) || fail "--dry-run exits 0" +[[ $(left) == "$before" ]] || fail "--dry-run removes nothing" +pass "a dry run names what it would remove and removes nothing" + +out=$(run) || fail "cleanup exits 0: $out" +want='.7.4.0.new .old 6.0.0-pkg 6.8.0-link 7.2.0-new1 7.2.0-new2 7.3.0-pushed 7.3.0-running ' +[[ $(left) == "$want" ]] || fail "kept set: got '$(left)', want '$want'" +grep -qxF 'modules-cleanup: keep 7.3.0-running: running' <<<"$out" || fail "logs the running tree" +grep -qxF 'modules-cleanup: keep 7.3.0-pushed: arrived during this boot (the next boot'"'"'s kernel)' <<<"$out" \ + || fail "logs the pushed tree" +grep -qxF 'modules-cleanup: keep 6.0.0-pkg: owned by linux' <<<"$out" || fail "logs the owned tree" +grep -q '^modules-cleanup: keep 7.2.0-new1: rollback' <<<"$out" || fail "logs rollback new1" +grep -q '^modules-cleanup: keep 7.2.0-new2: rollback' <<<"$out" || fail "logs rollback new2" +grep -qxF 'modules-cleanup: remove 7.1.0-old1' <<<"$out" || fail "logs the removal of old1" +grep -qxF 'modules-cleanup: remove 7.0.0-old2' <<<"$out" || fail "logs the removal of old2" +pass "keeps running, pushed-this-boot, owned and the two newest; removes the rest" + +[[ -d $t/root/.old/6.9.0-moved && -d $t/root/.7.4.0.new/7.4.0 ]] || fail ".old and a push in progress untouched" +[[ -L $t/root/6.8.0-link && -f $t/outside/6.8.0-target/kernel/b.ko ]] || fail "a symlinked tree and its target untouched" +grep -qxF 'modules-cleanup: skip 6.8.0-link: not a directory' <<<"$out" || fail "logs the skipped symlink" +pass "dot-directories, symlinks and what they point to are left alone" + +# A removed tree's symlink out of the root is not followed +setup +ln -s "$t/outside" "$t/root/7.0.0-old2/escape" +touch -d "@$(( boot - 4000 ))" "$t/root/7.0.0-old2" +run >/dev/null || fail "cleanup with an escape link" +[[ ! -e $t/root/7.0.0-old2 && -f $t/outside/6.8.0-target/kernel/b.ko ]] || fail "rm follows no symlink inside a removed tree" +pass "a link inside a removed tree is removed, not followed" + +# Pacman can't read its database: nothing goes +setup +cat > "$t/bin/pacman" <<'EOF' +#!/bin/bash +exit 1 +EOF +before=$(left) +run >/dev/null 2>&1 && fail "fails without pacman's database" +[[ $(left) == "$before" ]] || fail "nothing removed without pacman's database" +pass "without pacman's database nothing is removed" + +# An empty root and a missing one are fine +cp "$t/pacman.good" "$t/bin/pacman" +rm -rf "$t/root"; mkdir -p "$t/root" +run >/dev/null || fail "empty root" +rm -rf "$t/root" +run >/dev/null || fail "missing root" +pass "an empty or missing module root is not an error" diff --git a/packages/omamobile-omarchy/version b/packages/omamobile-omarchy/version index baa983785..790629964 100644 --- a/packages/omamobile-omarchy/version +++ b/packages/omamobile-omarchy/version @@ -1 +1 @@ -0.1.20 +0.1.21 From 11c3ff5bfea525fc4a5d317afce7dd650db01a0b Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Thu, 29 Oct 2026 22:43:29 -0400 Subject: [PATCH 2/2] omamobile-omarchy 0.1.21: keep the release modules-push named, and trees stamped by a reset clock Review found that the boot after a push, the case the cleanup exists for, protected the pushed tree only by its rank, and a marker written while the phone's clock read 1970 ranked it oldest and removed it. modules-push now names the release it pushed in /usr/lib/modules/.omamobile-next, and the cleanup keeps that release and any tree stamped before 2026. Also corrects two claims: the incident was on the Pixel 7, not in cheetah's NOTES, and .old doesn't pile up, because kernel-modules-hook's own tmpfiles rule empties it. Co-Authored-By: Claude Opus 5.5 --- bin/omamobile | 3 ++- docs/RELEASES.md | 2 +- .../omamobile-omarchy/lib/modules-cleanup | 22 +++++++++++++++++- .../10-omamobile.conf | 2 +- .../omamobile-omarchy/test/modules-cleanup.sh | 23 +++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/bin/omamobile b/bin/omamobile index 4e9697e58..7ff1a0663 100755 --- a/bin/omamobile +++ b/bin/omamobile @@ -272,7 +272,8 @@ cmd_modules_push() { zstd -dc | tar -C /usr/lib/modules/.$rel.new -xf - rm -rf /usr/lib/modules/$rel; mv /usr/lib/modules/.$rel.new/$rel /usr/lib/modules/$rel rmdir /usr/lib/modules/.$rel.new; depmod -a $rel - echo $(sha256sum < "$tarball" | cut -d' ' -f1) > /usr/lib/modules/$rel/.omamobile-tarball; sync" < "$tarball" + echo $(sha256sum < "$tarball" | cut -d' ' -f1) > /usr/lib/modules/$rel/.omamobile-tarball + echo $rel > /usr/lib/modules/.omamobile-next; sync" < "$tarball" "$ssh" "find /usr/lib/modules/$rel -name '*.ko*' | wc -l; ls /usr/lib/modules/$rel/modules.dep" } diff --git a/docs/RELEASES.md b/docs/RELEASES.md index 1da192ce1..37ee11a4a 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -223,7 +223,7 @@ The kernel is not touched: it still reaches the phone through `bin/omamobile pus **The phone's update UI** is `omamobile-shell`'s `omamobile.update` sheet: a toast when Omarchy has a release (tap to open) and Update > Omarchy in the menu open it; it shows what's new, the battery and the phone patches, asks for the PIN, shows progress with the output under Details, and ends on the result. The run is a systemd user unit, so it survives the shell restart at its end. -**Kernel module trees.** Omarchy enables `kernel-modules-hook`'s `linux-modules-cleanup.service`, which at every boot moves each `/usr/lib/modules/` that isn't running and that no package owns into `.old`. A phone's kernels come from `bin/omamobile push`, so a boot between a push and the reboot into the new kernel took the next kernel's modules away (cheetah NOTES, 2026-10-27). `omamobile-omarchy` 0.1.14 holds that unit off with a drop-in and runs `omamobile-modules-cleanup.timer` ten minutes after boot instead: it keeps the running release, every tree pushed during this boot, every pacman-owned tree and the two newest others, and removes the rest (`/usr/lib/omamobile-omarchy/modules-cleanup --dry-run` shows what it would do). A removed tree comes back with the next `push`, which re-sends a tree whose `.omamobile-tarball` marker is missing. It never touches `.old`; trees moved there before 0.1.14 can be deleted by hand. +**Kernel module trees.** Omarchy enables `kernel-modules-hook`'s `linux-modules-cleanup.service`, which at every boot moves each `/usr/lib/modules/` that isn't running and that no package owns into `.old`. A phone's kernels come from `bin/omamobile push`, so a boot between a push and the reboot into the new kernel took the next kernel's modules away (seen on the Pixel 7 on 2026-10-27). `omamobile-omarchy` 0.1.14 holds that unit off with a drop-in and runs `omamobile-modules-cleanup.timer` ten minutes after boot instead: it keeps the running release, the release `modules-push` last pushed (named in `/usr/lib/modules/.omamobile-next`), every tree pushed during this boot, every tree stamped before 2026 (a reset clock), every pacman-owned tree and the two newest others, and removes the rest (`/usr/lib/omamobile-omarchy/modules-cleanup --dry-run` shows what it would do). A removed tree comes back with the next `push`, which re-sends a tree whose `.omamobile-tarball` marker is missing. It never touches `.old`, which kernel-modules-hook's own tmpfiles rule empties. ## 6. Release bundles and the installer diff --git a/packages/omamobile-omarchy/lib/modules-cleanup b/packages/omamobile-omarchy/lib/modules-cleanup index 8d73c9a13..ba05dd5f9 100755 --- a/packages/omamobile-omarchy/lib/modules-cleanup +++ b/packages/omamobile-omarchy/lib/modules-cleanup @@ -8,7 +8,8 @@ # kernels never come from pacman: `bin/omamobile modules-push` unpacks the # next boot's tree and writes /.omamobile-tarball, so any boot # between the push and the reboot into the new kernel took that tree away, -# and the new kernel came up without drivers (cheetah NOTES, 2026-10-27). +# and the new kernel came up without drivers (on the Pixel 7, 2026-10-27, +# recorded in #149's device/panther NOTES). # This package holds that unit off (linux-modules-cleanup.service.d) and runs # this instead, from omamobile-modules-cleanup.timer, well after boot. # @@ -18,6 +19,11 @@ # tree's mtime or ctime (a rename sets it), is after the boot time # (/proc/stat btime): that is the next boot's kernel (ctime counts only # here, so a push caught before it writes its marker is kept too); +# - the release `bin/omamobile modules-push` last pushed, which it names in +# /usr/lib/modules/.omamobile-next: the next boot's kernel even when the +# push was in an earlier boot or its times are wrong; +# - every tree whose time is before 2026, which only a phone clock reset +# to 1970 writes: its age is unknown, so it isn't ranked; # - every tree a package owns (pacman -Qo); # - the KEEP (2) newest of the rest, by marker mtime (else the tree's # mtime): the rollback kernels. @@ -52,6 +58,12 @@ if [[ ! -d $root || -L $root ]]; then exit 0 fi running=$(uname -r) +# modules-push names the release it pushed; a stamp before 2026 is a reset clock +next="" +if [[ -f $root/.omamobile-next && ! -L $root/.omamobile-next ]]; then + read -r next < "$root/.omamobile-next" || true +fi +floor=1767225600 # 2026-01-01 UTC btime=$(awk '$1 == "btime" { print $2; exit }' "${OMAMOBILE_PROC_STAT:-/proc/stat}") [[ $btime =~ ^[0-9]+$ ]] || { log "no boot time in ${OMAMOBILE_PROC_STAT:-/proc/stat}; nothing removed"; exit 1; } # Without a working package database "not owned" can't be told from an error @@ -86,7 +98,15 @@ for tree in "$root"/[0-9]*; do log "keep $name: running" continue fi + if [[ -n $next && $name == "$next" ]]; then + log "keep $name: pushed for the next boot (.omamobile-next)" + continue + fi t=$(pushed "$tree") + if (( t < floor )); then + log "keep $name: its time is before 2026 (a reset clock), so its age is unknown" + continue + fi if arrived "$tree" "$t"; then log "keep $name: arrived during this boot (the next boot's kernel)" continue diff --git a/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf b/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf index 3834d9185..1c39219e1 100644 --- a/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf +++ b/packages/omamobile-omarchy/systemd/linux-modules-cleanup.service.d/10-omamobile.conf @@ -4,7 +4,7 @@ # never from pacman. Arch's cleanup moves every tree that isn't the running # kernel and that no package owns to /usr/lib/modules/.old at each boot, so a # boot between a push and the reboot into the new kernel took the next -# kernel's drivers away, and old trees piled up in .old. Held off while this +# kernel's drivers away. Held off while this # package is installed; omamobile-modules-cleanup.timer prunes instead, # keeping the running, next-boot and rollback trees. ConditionPathExists=!/usr/share/omamobile/omarchy/version diff --git a/packages/omamobile-omarchy/test/modules-cleanup.sh b/packages/omamobile-omarchy/test/modules-cleanup.sh index ec588beeb..68b9c2991 100644 --- a/packages/omamobile-omarchy/test/modules-cleanup.sh +++ b/packages/omamobile-omarchy/test/modules-cleanup.sh @@ -111,6 +111,29 @@ run >/dev/null 2>&1 && fail "fails without pacman's database" [[ $(left) == "$before" ]] || fail "nothing removed without pacman's database" pass "without pacman's database nothing is removed" +# The incident's case: pushed in an earlier boot, so only .omamobile-next or +# its rank protects it, and here its marker was written under a 1970 clock +cp "$t/pacman.good" "$t/bin/pacman" +setup +rm -rf "$t/root/7.3.0-pushed" +tree 7.4.0-next 99999 marker +touch -h -d @100000 "$t/root/7.4.0-next/.omamobile-tarball" "$t/root/7.4.0-next" +echo 7.4.0-next > "$t/root/.omamobile-next" +out=$(run) || fail "cleanup with .omamobile-next" +[[ -d $t/root/7.4.0-next ]] || fail "the release named in .omamobile-next is kept: $out" +grep -qxF 'modules-cleanup: keep 7.4.0-next: pushed for the next boot (.omamobile-next)' <<<"$out" || fail "logs the next-boot tree: $out" +[[ -d $t/root/7.2.0-new1 && -d $t/root/7.2.0-new2 && ! -e $t/root/7.1.0-old1 ]] || fail "the rollback ranking is unchanged: $(left)" +pass "the release modules-push named for the next boot is kept, even pushed in an earlier boot" + +setup +rm -rf "$t/root/7.3.0-pushed" +tree 7.4.0-reset 99999 marker +touch -h -d @100000 "$t/root/7.4.0-reset/.omamobile-tarball" "$t/root/7.4.0-reset" +out=$(run) || fail "cleanup with a 1970 stamp" +[[ -d $t/root/7.4.0-reset ]] || fail "a tree stamped before 2026 is kept: $out" +grep -qxF 'modules-cleanup: keep 7.4.0-reset: its time is before 2026 (a reset clock), so its age is unknown' <<<"$out" || fail "logs the reset-clock tree" +pass "a tree stamped under a reset clock is kept, not ranked oldest" + # An empty root and a missing one are fine cp "$t/pacman.good" "$t/bin/pacman" rm -rf "$t/root"; mkdir -p "$t/root"