← Knowledge base

VPS swapfile

Create a swapfile and persist it.

Linux2026-02-10

In this guide: VPS swapfile. Create a swapfile and persist it.

Commands below target a typical Linux setup (Ubuntu/Debian). On other distros, package/service names may differ.

If something goes wrong: check the service is running, listening on the expected port, and that your firewall allows the connection. For web services, `nginx -t` and `journalctl -u nginx` are good starting points. Swap helps with spikes, but constant swapping usually means you need to optimize memory or add RAM.

After completing the steps below, verify the result: service status, logs, and network reachability. This saves hours when an issue shows up later.

Below you’ll find a quick checklist, verification commands, and common pitfalls. This helps you not only “do it”, but also confirm what a correct outcome looks like.

Quick checklist

  • Check service status and logs after each change.
  • Keep headroom for disk and memory: many “random” issues are OOM/disk-full.
  • Do not edit system files without a backup copy.
  • Make one small change at a time and verify the result immediately.
  • Keep notes of what you changed (file/command/time).

Verify the result

# Verify / sanity checks
uptime
free -h
df -h
sudo systemctl --failed --no-pager || true

Common pitfalls

  • Editing configs without validating syntax (sshd/nginx).
  • Full disk (logs/caches/Docker) causes cascading failures.
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Need a VPS now?

Rent a WHITEWHALE VDS and launch in minutes.

European locations, transparent pricing, quick self-serve ordering.

Order VPS