36
My server is running out of memory. How can I add swap space without reinstalling the system?
Loading...
Q&A · Answered
My server is running out of memory. How can I add swap space without reinstalling the system?
Accepted answer
# Create 4GB swap file
sudo fallocate -l 4G /swapfile
# Or using dd
sudo dd if=/dev/zero of=/swapfile bs=1G count=4
# Set correct permissions
sudo chmod 600 /swapfile
# Set up swap area
sudo mkswap /swapfile
# Enable swap
sudo swapon /swapfile
# Add to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Verify
free -hSay what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.