Exactly 👍
Let’s decode the dd line first:
dd if=/dev/zero of=$ZRAM_DEV bs=4096 count=1
| | | |
source of zeros | one block |
destination block-size
• bs=4096 → one block is 4 KiB
• count=1 → copy one such block
So the command overwrites only 1 × 4096 B = 4096 B (4 KiB) starting at the very beginning (offset 0) of the device.
The remaining ~2 GiB are left untouched.
Why is that enough?
-
Swap recognition depends on a tiny header
Linux marks a swap area with the magic string SWAPSPACE2 that lives inside the first page of the device.*
If those first few kilobytes are no longer there, the kernel and utilities no longer see “hey, this is already a swap”, so you can re-run mkswap or reuse the device cleanly.
-
ZRAM is RAM-backed and volatile
The contents of the compressed pages vanish as soon as you swapoff or reset the zram device; you do not need to wipe all 2 GiB for security.
All you really need is to get rid of the swap signature.
-
Speed
Zeroing 2 GiB every time would be pointlessly slow compared to writing a single 4 KiB page.
If you ever do want to blank the whole thing you could drop count=1 (or set the count appropriately), e.g.:
dd if=/dev/zero of=$ZRAM_DEV bs=1M status=progress
—but for the typical “reset zram swap” workflow, clearing the first page is the quick, sufficient solution.
*History note: pre-2.6.29 kernels looked for the magic in the first 1024 B; since 2.6.29 the first whole page (4 KiB on most systems) is skipped for bootloaders/metadata and the header starts at offset 4096, still within that first page region we’re clearing.