Increase swap disk disk on CentOS 7 from 2 GB to 4 GB - how to update /etc/fstab
I'm troubleshooting our server falling over last night, and when I looked, I saw swap space was depleted and cPHulk taking up all the CPU.
TL;DR Any ideas how to quickly increase size of dm-1 partition?
To isolate, I'm first going to increase swap space from 2 GB (server has 8GB RAM) to 4 GB as running out of swap sounds like a big no-no to me.
I found two types of methods on the internet on how to increase the swap space on a CentOS Linux server, but I'm having problems doing the /etc/fstab part and / or understanding the second method.
The first method seems pretty straightforward, for example the one at Linuxize "How to Add Swap Space on CentOS 7".
In summary:
Check first what's going on (I have 2 GB swap space):
[QUOTE]swapon --show
Create swap. At this point the guide says it can be done with fallocate -l 4G /swapfile too, but this failed later so used dd method instead [QUOTE]dd if=/dev/zero of=/swapfile bs=1024 count=4194304
[QUOTE]chmod 600 /swapfile mkswap /swapfile
[QUOTE]swapon /swapfile
(this failed with swapon failed: Invalid argument if fallocate was used) cat /etc/fstab [QUOTE]... /swapfile swap swap defaults 0 0
So that all works. But now I have this: [CODE=bash]# swapon --show NAME TYPE SIZE USED PRIO /dev/dm-1 partition 2G 1.8G -2 /swapfile file 4G 0B -3
Two swap files! The other type of guide seems nice and complicated. Stuff about increasing that disk partition. Questions: 1. Will I be okay with two swap files (I prefer one)? 2. Any quick steps to rather just increase dm-1? I've spend a ton of time on this and waking up at 3AM wasn't nice. I'm in a bad mood already and also haven't had coffee.
Create swap. At this point the guide says it can be done with fallocate -l 4G /swapfile too, but this failed later so used dd method instead [QUOTE]dd if=/dev/zero of=/swapfile bs=1024 count=4194304
[QUOTE]chmod 600 /swapfile mkswap /swapfile
[QUOTE]swapon /swapfile
(this failed with swapon failed: Invalid argument if fallocate was used) cat /etc/fstab [QUOTE]... /swapfile swap swap defaults 0 0
So that all works. But now I have this: [CODE=bash]# swapon --show NAME TYPE SIZE USED PRIO /dev/dm-1 partition 2G 1.8G -2 /swapfile file 4G 0B -3
Two swap files! The other type of guide seems nice and complicated. Stuff about increasing that disk partition. Questions: 1. Will I be okay with two swap files (I prefer one)? 2. Any quick steps to rather just increase dm-1? I've spend a ton of time on this and waking up at 3AM wasn't nice. I'm in a bad mood already and also haven't had coffee.
-
Do a "swapoff /dev/dm-1" and make sure there's no line for /dev/dm-1 in /etc/fstab if you're sure you don't want to use it anymore. 0 -
Actually the 2 swap files are added together so instead of 2GB which was the old one you now have 6GB which wouldn't hurt. You can check it with "free -m' command. 0 -
Let us know if the details that @wintech2003 and @andrew.n aren't enough to get this resolved for you! 0
Please sign in to leave a comment.
Comments
3 comments