Create Swap File in Linux

1. Create the 1GB swap file (takes a few seconds)

sudo fallocate -l 1G / swapfile

# Alternative if failure doesn't work: # sudo dd if = / dev / zero of = / swapfile bs = 1024 count = 1048576

# 2. Ensure correct permits (root only) sudo chmod 600 / swapfile# 3. Formatting as a swap area sudo mkswap / swapfile# 4. Activate the swap its

do swapon / swapfile# 5. Verify that it is active sudo swapon -sho w free -h# 6. Make it permanent (add to / etc / fstab) echo '/ swapfile none swap sw 0' | sudo tee -a / etc / fstab# Adjusting swappiness (recommended value: 10 for servers, 60 for desktop) sudo sysctl vm.swappiness = 10# Make the value of swappiness permanent echo 'vm.swappiness = 10' | sudo tee -a / etc / sysctl. conf# Adjust cache pressure sudo sysctl vm.vfs _ cache _ pressure = 50 echo 'vm.vfs _ cache _ pressure' | sudo tee -a / etc / sysctl. conf  

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish