I recently created a swap file on my centos 6 based VPS using this guide. Now I wanted to extend this swap and I was reading through this guide. However, I think I've created a swap file than a partition. How do I go about extending this swapfile? The current size is 512M and I need to extend it by another 1G.
Can you show the results of
so we can be sure of your situation?
BTW - did you make sure the swap space (file or partition) is in your /etc/fstab?
If you created an lvm swap partition, extending it is easy and you can use the same guide - basically:
swap off; lvextend -L +1G VolGroup/LVswap; mkswap /dev/VolGroup-LVswap; swapon -a
If you indeed created a file - you can either repeat the procedure, create another 1G file and let swap handle it (swap space does not have to be contiguous)
Or you could simply remove the file (swapoff /path/to/swapfile; rm !$) and recreate it in a new size
Or you can use dd to extend your swap file (again - make sure to swapoff first)
dd oflag=append conv=notrunc if=/dev/zero of=/swapfile bs=1MB count=1024
It's advisable to use the
freecommand first, to ascertain swap is not used. As long as swap usage is 0, and no process is going to require more memory then physically available, there should be no issues.
Every swap device must be present in
swapon -ato detect them all.
If using procedure (3) above, to keep swap "downtime" to a minimum, you can do the following:
3.1 Create new swapfile
/etc/fstab to point to new swap file.
Optionally combine 3.3 and 3.4 as:
swapoff /path/to/OLD/swapfile && swapon -a
will ensure least amount of time without swap.