linux-create-swap-area

Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.

Create empty file on disk

1
sudo dd if=/dev/zero of=/opt/swap bs=1024 count=2048000

Make swap

1
sudo mkswap /opt/swap

Change permission

1
sudo chmod 600 /opt/swap

Enable

1
sudo swapon /opt/swap

Check result

1
2
3
4
5
6
7
8
~ # free -m
total used free shared buff/cache available
Mem: 3921 90 1567 1 2263 3543
Swap: 974 107 867

total used free shared buff/cache available
Mem: 3921 92 1565 1 2263 3542
Swap: 2974 106 2868

Disable

1
sudo swapoff /opt/swap

Remove file on disk

1
sudo rm -f /opt/swap