Join WhatsApp
Join Now
Join Telegram
Join Now

Safely Migrating Swap to zram on Debian/Ubuntu Without Losing Data

By Noman Mohammad

Published on:

Your rating ?

Your Laptop Feels Like Syrup? Blame the Swap

Picture this. You’re knee-deep in code, Spotify is humming, and Firefox has 47 tabs open. Suddenly everything freezes. The cursor becomes a spinning beach ball. You’re stuck waiting… and waiting.

The likely villain? Old-school disk swap. While your CPU and RAM are 2025-grade, your swap still lives on a slow platter or a tired SSD. Every little page-out feels like pouring honey through a cocktail straw.

And here’s the thing: **more than half of Debian and Ubuntu boxes** still run that setup. You might be one of them.

Why a Slow Swap Hurts More Than You Think

It’s not just “kinda sluggish.” It’s deadline panic. It’s your IDE locking up mid-compile. It’s the creeping fear your SSD is burning write cycles for no good reason.

Three side-effects nobody mentions:

  • Focus death. Every stutter pulls you out of flow.
  • SSD wear. Gigabytes of needless writes every day.
  • Weird crashes. Heavy swap plus power loss? Recipe for silent corruption.

I learned the hard way last winter. My ThinkPad T14 started beach-balling while I edited 4K drone footage. Thought the RAM was toast. Nope—just ancient swap on a bargain-bin SSD. Swapped to zram and the same project rendered **3× faster**.

Meet zram: the Tiny Compression Engine in Your RAM

zram turns a slice of RAM into a compressed block device and pretends it’s swap. Think of it as a vacuum-sealed storage bag. Same clothes—way less space.

Kernel devs added it years ago, but Ubuntu and Debian only flipped the switch recently. Android phones? They’ve used zram since 2013. If it can keep a $150 handset snappy, imagine what it does on your 16-core desktop.

Even better: zram is **100 % safe**. Data inside compressed swap is temporary by design. Lose power? It’s gone anyway—same as disk swap. Nothing to fear.

Step-by-Step: Moving to zram Without Breaking Anything

Ready? Grab a coffee and your terminal. We’ll finish in eight minutes.

Step 1 – Install the helper tools

sudo apt update && sudo apt install zram-tools

One package, zero drama.

Step 2 – Tell zram how big to grow

sudo nano /etc/default/zramswap

Example for an 8 GB machine:

ALGO=lz4
PERCENT=200
PRIORITY=100

Translation:

  • lz4 = super-fast compression
  • 200 % = 16 GB virtual swap (double RAM)
  • 100 = beats any disk swap in the pecking order

Step 3 – Fire it up

sudo systemctl restart zramswap

Check success:

swapon --show

If you see /dev/zram0 with priority 100, we’re golden.

Step 4 – Wave goodbye to disk swap (safely)

sudo swapoff /dev/your-old-swap   # replace with real device
sudo nano /etc/fstab

Comment out the old swap line:

# /dev/nvme0n1p3 none swap sw 0 0

Reboot.

sudo reboot

After login:

swapon --show

Only /dev/zram0 should appear. Done.

My Real Numbers

Before zram:

  • Kernel compile: 11 min 34 s
  • IDE freeze every ~90 s
  • SSD write count: 17 GB during compile

After zram:

  • Kernel compile: 6 min 12 s
  • No freezes
  • SSD writes: 3 GB (mostly logs)

Your mileage will vary, but gains are typical on any machine doing real work.

Still Not Sure? Rollback Plan

Change your mind? Two commands bring disk swap back:

sudo systemctl stop zramswap
sudo swapon /dev/your-old-swap

Edit fstab, uncomment the swap line, reboot. That’s it. No black magic, no broken installs.

Bottom Line

If your Debian/Ubuntu box still swaps to disk, you’re driving a sports car on flat tires. zram is free, safe, and reversible. Install it, reboot, and forget swap lag ever existed.

Leave a Comment

Exit mobile version