zramctl turns spare RAM into a compressed swap device, and it will bite you if you treat the size like a throwaway detail. This walkthrough creates a zram block device, initialises it as swap, checks the kernel is actually using it, then tears it down cleanly. Allow about ten minutes.
zramctl can do anything.zramctl command from util-linux. Check which binary you are actually running: on the reference machine, the Debian package reports util-linux 2.39.3, but the shell's zramctl resolves to Homebrew util-linux 2.42.4. Mismatches like that explain half the "it worked on my other box" reports.1G because a guide used it.The workflow below uses options documented by the local zramctl(8) manpage. It changes live swap state and needs elevated privileges, so nothing here is undo-free once you hit enter.
Run the read-only checks first, as your ordinary user:
$ command -v zramctl
$ zramctl --version
$ zramctl --help
$ zramctl
$ ls -l /dev/zram* 2>/dev/null || true
No output from the final two checks is a valid starting point. zram device nodes are not necessarily created at boot, and zramctl without options only reports devices with a non-zero size, so do not assume /dev/zram0 exists just because zram is supported.
Checkpoint: record the version and the path printed by command -v. If the command is missing, install or enable the host's normal util-linux and kernel support before continuing; do not download a replacement binary into a system path just for this test.
Use --find rather than guessing a device number: with a size attached, it finds the first unused zram device and initialises it in one operation. That changes kernel device state, so run it with sudo and keep the output:
$ sudo zramctl --find --size 1G
/dev/zram0
/dev/zram0 from a previous run.G means the same as GiB, and M means MiB. A requested size that is not a multiple of the memory page size gets rounded up.Warning: do not run this against a device already used for swap, a mounted filesystem or data you need. --find --size selects an unused zram device, but a device already created can still get picked incorrectly if another tool is changing devices at the same time. On a busy host, coordinate with whoever owns zram there.
Set a shell variable to the exact path from the previous step. This is an ordinary shell assignment, not a privileged operation:
$ ZRAMDEV=/dev/zram0
$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 1G 0B 0B 0B 4
$ zramctl --noheadings --output NAME,DISKSIZE,ALGORITHM,STREAMS "$ZRAMDEV"
/dev/zram0 1G zstd 4
Formatting varies with util-linux version and the host's kernel, so don't panic if your columns look different. What matters: the device name, a non-zero disk size and a selected compression algorithm. The algorithm list in the manpage is only a guide, since kernel configuration can make it incomplete. If the selected device is not the one you created, stop and investigate before formatting it.
Write a swap signature and activate the device. Both commands need elevated privileges:
$ sudo mkswap "$ZRAMDEV"
Setting up swapspace version 1, size = 1 GiB (1073737728 bytes)
no label, UUID=EXAMPLE-UUID
$ sudo swapon "$ZRAMDEV"
$ swapon --show "$ZRAMDEV"
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 1G 0B 100
The UUID is host-specific and the displayed size may be rounded. A successful swapon --show confirms the kernel considers this device active. If swapon fails, read its error before retrying: common causes are an existing signature or swap entry, a device that was never initialised, or a host policy rejecting the configuration.
This example does not touch /etc/fstab or a boot service. The swap disappears after swapoff and will not return after reboot unless something else enables it.
These are read-only while the temporary swap is available:
$ swapon --show
$ zramctl --output NAME,DISKSIZE,DATA,COMPR,TOTAL,COMP-RATIO,MOUNTPOINT
NAME DISKSIZE DATA COMPR TOTAL COMP-RATIO MOUNTPOINT
/dev/zram0 1G 0B 0B 0B 0.00
DATA is the uncompressed amount stored in zram, COMPR is the compressed amount, and TOTAL includes allocator and metadata overhead. Values sit near zero until something actually uses the swap. A large disk size is not a promise of that much free RAM.
When the maintenance task is finished, stop using the swap before resetting the device. This is the recovery path as well as the normal cleanup path:
$ sudo swapoff "$ZRAMDEV"
$ swapon --show "$ZRAMDEV"
$ sudo zramctl --reset "$ZRAMDEV"
$ zramctl
$ ls -l "$ZRAMDEV" 2>/dev/null || true
swapoff may take time. Pages are moving out of swap and it needs free RAM to do it. Do not interrupt it casually on a busy host.swapoff reports the device busy, find the owning process or service and resolve that dependency first; do not force a reset.zramctl normally prints no row for that device because its size is zero, but the node itself often stays. That's fine: an unused node can be picked again later with --find./dev/zram0 is an example, not a guarantee: keep the path --find actually returned.swapoff. Resetting active swap can disrupt the host and destroy data that has not been moved elsewhere./sys/block/zram0/comp_algorithm only for a device that exists, and treat its list as a guide, not a guarantee.zramctl before trusting its behaviour.--find --size returned a device and you recorded its path.swapon --show confirmed active swap.swapoff before zramctl --reset, not the other way round.