Skip to content

Add zram-to-zswap migration script - #15

Merged
modem7 merged 2 commits into
masterfrom
add-zram-to-zswap-script
Jul 30, 2026
Merged

Add zram-to-zswap migration script#15
modem7 merged 2 commits into
masterfrom
add-zram-to-zswap-script

Conversation

@modem7

@modem7 modem7 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds Bash/Server scripts/zram-to-zswap.sh, a script to audit a host's current zram/swap setup and migrate it to zswap (compressed cache in front of real disk swap) instead of zram-only swap.
  • Rationale: https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html — zram has a hard capacity ceiling and no kernel reclaim integration; zswap degrades gracefully to disk instead.

Features

  • Dry-run by default (--apply to actually change anything)
  • Auto-detects current state: zram-only, real-swap-only, both (the "never combine" anti-pattern), or neither
  • Auto-provisions backing swap (ZFS zvol / LVM LV / swapfile, whichever fits the host) sized dynamically from total RAM, not hardcoded
  • Idempotent: safe to re-run, won't recreate devices that already exist
  • Backs up /etc/fstab, the kernel cmdline file, and the original init-zram-swapping script before making changes, with a --revert [--apply] mode to undo

Test plan

  • bash -n syntax check passes
  • Dry-run mode exercised against real hosts (Proxmox hypervisors on LVM and ZFS root, Proxmox Backup Server, Ubuntu VMs of various RAM sizes) to validate detection/diagnosis logic
  • --apply run end-to-end on a real Ubuntu 24.04 VM (zram-only → swapfile + zswap); confirmed via swapon, GRUB cmdline, and /sys/module/zswap/parameters/*
  • --revert --apply run on the same VM; found and fixed a real bug where systemctl enable --now didn't restart an already-active zram-config service, so the restored custom init script never re-ran. Fixed by explicitly stopping the service and resetting zram devices before restoring the script and restarting. Re-tested after the fix — confirmed clean.
  • Re-ran --apply after revert to confirm idempotency (reused the existing swapfile rather than recreating it)

Audits a host's current zram/swap setup and migrates it to zswap
(compressed cache in front of real disk swap) instead of zram-only
swap, per https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html.
Supports dry-run, ZFS/LVM/swapfile auto-provisioning, dynamic sizing
based on host RAM, and backup/revert of everything it touches.
Live-tested --apply/--revert on a real VM: when zram-config's postinst
had already auto-started the service with the stock init script,
'systemctl enable --now' on the already-active oneshot unit was a
no-op, so our restored custom script never actually ran. Now stop the
service and reset any zram devices apt created before restoring the
custom script and restarting.
@modem7
modem7 merged commit fb26259 into master Jul 30, 2026
1 check passed
@modem7
modem7 deleted the add-zram-to-zswap-script branch July 30, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant