How to add swap space on Linux
Answered
36
My server is running out of memory. How can I add swap space without reinstalling the system?
F
Asked by
fatima_dev
Silver
•
169 rep
1 Answer
12
Create swap file
# 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
Make permanent
# Add to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Verify
free -h
O
Platinum
•
593 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer