The resize guard reads the Used column for /dev/zram0 out of /proc/swaps and treats a missing row as an empty device, which is right for a device that doesn't exist yet: the restart is what brings it up against the config daemon-reload just generated. A device that exists and is merely swapped off reads the same, and there the restart resets it first, which returns EBUSY for as long as anything still holds it open. That leaves a bare "Job failed. See 'journalctl -xe' for details." in the migration output and falls through to asking for the reboot that would have resized it anyway. Tell the two apart by whether /sys/block/zram0/disksize is there at all. The test modelled an absent device as a blank disksize file, which no longer stands in for one, so it removes the file instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
48 lines
2.1 KiB
Bash
48 lines
2.1 KiB
Bash
echo "Resize zram to match the shipped config"
|
|
|
|
# 90-omarchy.conf changed the device size. The migration that first applied the
|
|
# zram tuning is one-shot, so machines that already ran it have the new file on
|
|
# disk and the old device still running; nothing would pick the size up until
|
|
# something else rebooted them.
|
|
|
|
zram_disksize=${OMARCHY_ZRAM_DISKSIZE:-/sys/block/zram0/disksize}
|
|
swaps=${OMARCHY_SWAPS:-/proc/swaps}
|
|
|
|
# The size is an expression, and the generator is the only thing that evaluates
|
|
# it. Ask it what the shipped config comes to rather than repeating the
|
|
# arithmetic here, where the two would drift apart on the next tuning change.
|
|
units=$(mktemp -d)
|
|
trap 'rm -rf "$units"' EXIT
|
|
desired_mb=$(/usr/lib/systemd/system-generators/zram-generator "$units" 2>&1 |
|
|
grep -oP '/dev/zram0 with \K[0-9]+') || true
|
|
|
|
actual_bytes=$(cat "$zram_disksize" 2>/dev/null) || actual_bytes=0
|
|
|
|
# A device already at the right size needs neither a restart nor a reboot,
|
|
# whether an earlier boot picked the config up or another user got here first.
|
|
if [[ -n $desired_mb && $actual_bytes == $((desired_mb * 1024 * 1024)) ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
if sudo systemctl daemon-reload; then
|
|
# Resizing swaps the device off first, which faults every stored page back
|
|
# into memory. That's only cheap while it's empty, so a device under
|
|
# pressure keeps its old size until the next boot.
|
|
zram_used=$(awk '$1 == "/dev/zram0" {print $4}' "$swaps")
|
|
|
|
# No row at all means the device is not swap right now, and that covers two
|
|
# unlike situations. A device that doesn't exist yet is the one worth acting
|
|
# on: the restart brings it up against the config daemon-reload just picked
|
|
# up. A device that exists but is swapped off is not, because the restart
|
|
# resets it first, and reset returns EBUSY for as long as anything still
|
|
# holds it open. That leaves a "Job failed" from systemd in the migration
|
|
# output and still ends up asking for the reboot, so go straight there.
|
|
if [[ -n $zram_used || ! -e $zram_disksize ]] &&
|
|
[[ ${zram_used:-0} == 0 ]] &&
|
|
sudo systemctl restart dev-zram0.swap; then
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
omarchy-state set reboot-required
|