LEEUNITYAssets / Content / 博客.asset
层级
⌄ Lee / Homepage
INSPECTOR
Type
Content
Name
博客
lee@mtftm.com ↗GitHub ↗
N021SYSTEM / LINUX

技术 / English

Configure Swap on Debian

You can use free -h to check the current swap usage

更新
2026.07.18
阅读
2 分钟
语言
English

Create

You can use free -h to check the current swap usage

Create a new swap file (set the size as needed)

sudo fallocate -l 1G /swapfile

Set file permissions to root only (optional)

sudo chmod 600 /swapfile

Format the file as swap space

sudo mkswap /swapfile

Enable swap

sudo swapon /swapfile

Enable automatic mounting

Open the etc/fstab file and add at the end:

/swapfile none swap sw 0 0

Modify

Change swap activation threshold

Open the etc/sysctl.conf file and modify the value after vm.swappiness=80.If it does not exist, add a new line.

Change swap size

  • Use swapoff -a to turn off swap
  • Delete the previously created swapfile
  • Repeat the creation steps