Can you please guide me through the steps to create swap file on Centos Server?
Collapse
Announcement
Collapse
No announcement yet.
Steps to create swap file on Centos Server
Collapse
X
-
Hi Neha,
Here, I'll consider that you need to create a Swap space of 4 GB as as a reference and you may follow below steps to do so.
Connect to the server as root user.
1. Check total disk space available on the server
2. Manipulate File space. Create a swapfile in the location where it can't be deleted. I've considered /root location for the same.Code:df -h
3. Use following command, the count parameter will be used to allocate the desired block size 4 GB.Code:fallocate -l 4G /root/4GB.swap
4. Create a swap file.Code:dd if=/dev/zero of=/root/4GB.swap bs=1024 count=4048576
5. Change the permission to 600.Code:mkswap /root/4GB.swap
6. To enable Swap immediately and not on boot time.Code:chmod 600 /root/4GB.swap
7. To enable swap at boot time add an entry to /etc/fstab fileCode:swapon /root/4GB.swap
Code:vi /etc/fstab
8. To check the mount or entry is correct.Code:/root/4GB.swap swap swap defaults 0 0
9. Swap is now available and can be checked using below command.Code:mount -a
Code:free -m
Comment