Skip to content

Create Swap File | Debian | Ubuntu

Create

Bash
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Bash
sudo cp /etc/fstab /etc/fstab.save
Bash
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Bash
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
Bash
sudo nano /etc/sysctl.conf
Text Only
vm.swappiness=10
vm.vfs_cache_pressure=50

Show

Bash
sudo swapon --show

Remove

Bash
swapoff /swapfile
sudo rm -rf /swapfile