Keep swap disabled on kernels without zram support

This commit is contained in:
Andrei Smaliak 2026-09-03 16:34:20 +02:00
parent 0cdf2923f1
commit bfeda9114e
2 changed files with 2 additions and 68 deletions

View File

@ -369,62 +369,6 @@ EOF
fi fi
} }
configure_zram_swap() {
write_if_changed /usr/local/sbin/iomatex-zram 0755 <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
device=/dev/zram0
case "${1:-start}" in
start)
if swapon --show=NAME --noheadings 2>/dev/null | awk '{$1=$1};1' | grep -qx "$device"; then
exit 0
fi
modprobe zram num_devices=1 >/dev/null 2>&1 || exit 0
[ -b "$device" ] || exit 0
command -v zramctl >/dev/null 2>&1 || exit 0
mem_kib="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)"
size_bytes=$((mem_kib * 1024 / 4))
min_bytes=$((128 * 1024 * 1024))
max_bytes=$((512 * 1024 * 1024))
[ "$size_bytes" -lt "$min_bytes" ] && size_bytes="$min_bytes"
[ "$size_bytes" -gt "$max_bytes" ] && size_bytes="$max_bytes"
zramctl --reset "$device" >/dev/null 2>&1 || true
zramctl --size "$size_bytes" "$device"
mkswap "$device" >/dev/null
swapon --priority 100 "$device"
;;
stop)
swapoff "$device" >/dev/null 2>&1 || true
zramctl --reset "$device" >/dev/null 2>&1 || true
;;
*)
echo "usage: $0 {start|stop}" >&2
exit 2
;;
esac
EOF
write_if_changed /etc/systemd/system/iomatex-zram.service 0644 <<'EOF'
[Unit]
Description=IOMATEX compressed RAM swap
After=systemd-modules-load.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/iomatex-zram start
ExecStop=/usr/local/sbin/iomatex-zram stop
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl_enable_now_safe iomatex-zram.service
}
userdata_has_journal() { userdata_has_journal() {
local device local device
device="$(readlink -f /dev/disk/by-partlabel/userdata 2>/dev/null || true)" device="$(readlink -f /dev/disk/by-partlabel/userdata 2>/dev/null || true)"
@ -1325,7 +1269,6 @@ EOF
# - NO fstab entries that can block boot # - NO fstab entries that can block boot
# - /userdata is treated as optional for boot # - /userdata is treated as optional for boot
# - NO swap on /userdata; hard power cuts can make that partition block boot on fsck # - NO swap on /userdata; hard power cuts can make that partition block boot on fsck
# - compressed RAM swap is provided by iomatex-zram.service when supported
# - generic app log directory is created only when /userdata is already mounted # - generic app log directory is created only when /userdata is already mounted
# ------------------------- # -------------------------
step "Userdata SAFE: non-blocking mount + generic logs + log overflow protection" step "Userdata SAFE: non-blocking mount + generic logs + log overflow protection"
@ -1343,7 +1286,6 @@ if [ "$STAGE_ENV_REINSTALL" -eq 0 ]; then
else else
log "Existing Edge detected: leaving swap configuration untouched" log "Existing Edge detected: leaving swap configuration untouched"
fi fi
configure_zram_swap
soft_run "systemd daemon-reload (storage contract)" 20 /bin/systemctl daemon-reload soft_run "systemd daemon-reload (storage contract)" 20 /bin/systemctl daemon-reload
soft_run "Enable iomatex-userdata-prepare.service" 20 /bin/systemctl enable iomatex-userdata-prepare.service soft_run "Enable iomatex-userdata-prepare.service" 20 /bin/systemctl enable iomatex-userdata-prepare.service

View File

@ -138,19 +138,11 @@ check_base_system() {
local swap_total="" local swap_total=""
swap_total="$(free -h 2>/dev/null | awk '/^Swap:/ {print $2}')" swap_total="$(free -h 2>/dev/null | awk '/^Swap:/ {print $2}')"
if [[ -z "$swap_total" || "$swap_total" == "0B" || "$swap_total" == "0" ]]; then if [[ -z "$swap_total" || "$swap_total" == "0B" || "$swap_total" == "0" ]]; then
if unit_exists "iomatex-zram.service"; then
warn "iomatex-zram.service is installed but swap is unavailable"
else
warn "swap is disabled" warn "swap is disabled"
fi
else else
pass "swap configured: ${swap_total}" pass "swap configured: ${swap_total}"
if swapon --show=NAME --noheadings 2>/dev/null | awk '{$1=$1};1' | grep -qx /dev/zram0; then if swapon --show=NAME --noheadings 2>/dev/null | grep -q '^/userdata/'; then
pass "zram swap active on /dev/zram0"
elif swapon --show=NAME --noheadings 2>/dev/null | grep -q '^/userdata/'; then
fail "swap must not depend on /userdata" fail "swap must not depend on /userdata"
else
warn "swap is active but not provided by iomatex zram"
fi fi
fi fi