Sometimes we need to resize the swap size. Possible reasons include:
- Running out of memory
- You may need to increase the swap size
- Check the storage. Do you have enough free disk space to extend the swap file?
- Check the current memory usage by running the 'top' command to determine which process is using a lot of memory. You may not need to increase the memory :)
- Running out of disk space
- One possible solution is to decrease the swap size
- Check that you have enough memory by running the free -m command
- Check that the swap partition and the small partition are in the same place? If not, this change may not be useful in your case.
Let's see how to modify the swap size on CentOS 7
- Check the current size of the swap:
- Check the current swap file location:
# Accessiblefilesystems, byreference, aremaintainedunder '/dev/disk'
# See man pagesfstab(5), findfs(8), mount(8) and/orblkid(8) for more info
/dev/mapper/centos-root / xfs defaults 0 0
UUID=11bbb941-3929-44fc-89d5-94272765cb99 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
Based on the last line, our swap file located at
- Turn off this swap file:
- Remove the old swap file:
rm -f /dev/mapper/centos-swap
- Create a new swap file (the size is 8GB in this example):
dd if=/dev/zero of=/dev/mapper/centos-swap count=8192 bs=1MiB
- Make this file as a swap file:
- Set right permission:
chmod 600 /dev/mapper/centos-swap
- Turn the swap on again:
- Check what we did:
- That's all.
If you found this article useful and would like to show your appreciation, please consider making a small donation via PayPal. Your support will allow me to continue creating valuable content and make my blog even better. Thank you for your contribution!