CertGrid CertGrid
Hands-on Lab·Linux Foundation Certified System Administrator

Swap files, partitions and swappiness

Swap is the part of storage that is not a filesystem, and adding some is a common exam task because it touches allocation, permissions, fstab and sysctl at once. This guide reads what the two hosts already have - which turns out to differ - then adds a swap file, prioritises it, and takes it away again.

Storage Guide 35 of 38 Beginner

Ubuntu's installer creates a swap file at /swap.img; RHEL's creates a swap partition on LVM. Both are ordinary and the commands are identical. swapon, mkswap and swapoff are util-linux on both.

The swap file added here was created, prioritised, disabled and deleted inside the transcript. Neither host's own swap was touched.
Server NameIP AddressOSRolesCPURAMHDD
LFCS-A01192.168.0.70Ubuntu 26.04 LTSPrimary host - most guides run only here2 Core4 GB50 GB
LFCS-C01192.168.0.72AlmaLinux 10.2The other distribution - dnf, firewalld and NetworkManager2 Core4 GB50 GB

This guide includes

Use this for the part of storage that is not a filesystem. This matters because adding swap is a task you may be handed, and a priority number decides which area gets used first.

Before you start

  1. What the two hosts already have

  2. A swap file, made by hand

  3. Which swap area gets used first

  4. How eagerly the kernel swaps

  5. Taking it away

Official sources