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
3 changes: 2 additions & 1 deletion bin/omamobile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
2 changes: 2 additions & 0 deletions docs/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<release>` 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

For a first install, or to recover a phone that won't boot. One bundle per device per release.
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-omarchy/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions packages/omamobile-omarchy/install
Original file line number Diff line number Diff line change
@@ -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]}")"
Expand All @@ -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
Expand Down
133 changes: 133 additions & 0 deletions packages/omamobile-omarchy/lib/modules-cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/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/<release> 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 <release>/.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 (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.
#
# 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);
# - 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.
# and removes the others with rm -rf. Only direct children named like a
# release ([0-9]*) are candidates; symlinks, dot-directories (.old, the
# .<release>.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)
# 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
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
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
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)
Original file line number Diff line number Diff line change
@@ -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. 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
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions packages/omamobile-omarchy/systemd/omamobile-modules-cleanup.timer
Original file line number Diff line number Diff line change
@@ -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
27 changes: 26 additions & 1 deletion packages/omamobile-omarchy/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading