Add zram-to-zswap migration script - #15
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.Features
--applyto actually change anything)/etc/fstab, the kernel cmdline file, and the originalinit-zram-swappingscript before making changes, with a--revert [--apply]mode to undoTest plan
bash -nsyntax check passes--applyrun end-to-end on a real Ubuntu 24.04 VM (zram-only → swapfile + zswap); confirmed viaswapon, GRUB cmdline, and/sys/module/zswap/parameters/*--revert --applyrun on the same VM; found and fixed a real bug wheresystemctl enable --nowdidn'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.--applyafter revert to confirm idempotency (reused the existing swapfile rather than recreating it)