Add swap file

PHOTO EMBED

Tue Sep 21 2021 17:41:17 GMT+0000 (UTC)

Saved by @ExplodeMilk #linux

# check cuurent swap space
sudo swapon --show
free -h

# check available disk space
df -h

# create swap file
sudo fallocate -l 1G /swapfile

# verification
ls -lh /swapfile

# enable swap file
sudo chmod 600 /swapfile
ls -lh /swapfile

# mark file as swap space
sudo mkswap /swapfile
sudo swapon /swapfile

# verification
sudo swapon --show
free -h

# make swap file permanent
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

# adjust swappiness
cat /proc/sys/vm/swappiness
sudo sysctl vm.swappiness=10

# set to automatically restart
sudo nano /etc/sysctl.conf
vm.swappiness=10

# set cache pressure
cat /proc/sys/vm/vfs_cache_pressure
sudo sysctl vm.vfs_cache_pressure=50

# make permanent
sudo nano /etc/sysctl.conf
content_copyCOPY

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04