How do I setup a swap file in Linux?

Step 1

swapon --show

Step 2

free -h

Step 3

df -h

Step 4

cd <path>

Step 5

Method 1

fallocate -l 16G swap

Method 2

dd if=/dev/zero of=swap bs=1K count=16M

askubuntu.com/a/796997

Step 6

chmod 600 swap
mkswap swap
swapon swap

Step 7

echo "<path>/swap none swap sw 0 0" | sudo tee -a /etc/fstab

8. Testing

8.1.

swapoff swap
swapon -va

8.2.

free -h

2024-07-29--20-24-18

8.3.

swapon --show

2024-07-29--20-26-08