mediumFoundationSymptom-first#swap#swapfile#memory#swapon#fstab

Swap not enabled despite configuration — no swap active

swapon --show returns empty

Likely source:configurationperformance

Focused incident mode — strips away everything but this runbook.

Symptoms

  • swapon --show returns empty
  • free -h shows 0B swap
  • System OOM kills under memory pressure despite having a swapfile configured

Evidence to grab

Collect these artifacts before you change anything — they prove (or rule out) each cause.

  • Active swap

    swapon --show
  • fstab swap entries

    grep swap /etc/fstab

Diagnostic flow

Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.

Guided decision tree is ready.

Steps with commands, expected output, and pass/fail branches.

Ranked root causes

Evidence checklist

  • swapon --show is empty
  • ls shows the swapfile exists but file does not show 'swap'

Confirm before fixing

file /swapfile 2>/dev/null
READ

Check if the file is a valid swap area

Fix

dd if=/dev/zero of=/swapfile bs=1M count=1024 && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
DESTRUCTIVE

Create, format, and enable a 1GB swap file

Resolution runbook

Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.

1
swapon --show
READ

Confirm no swap is active

2
grep swap /etc/fstab
READ

Check fstab for swap configuration

3
dd if=/dev/zero of=/swapfile bs=1M count=1024 && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
DESTRUCTIVE

Create and enable a swap file

4
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
CHANGE

Add swap entry to fstab for persistence across reboots

Prevention

  • Always add swap during initial server provisioning, not after a memory crisis.
  • Set swappiness to 10-60 based on workload type (database vs general).
  • Monitor swap usage and alert on sudden increases.
  • Use fallocate or dd to create swapfiles; verify with swapon --show after boot.

Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.