Powered By Blogger

Thursday, September 16, 2010

Re-sizing Logical Volume Swap Space

Today we're going tweak some disk.  Sure this topic has been covered 100's of times by 100's of forums, bloggers, etc., but I thought I'd take a crack at it.

Recently I had a developer come to me with the need to add more swap space to a Red Hat Enterprise 5.3 system.  Originally the server had been configured with logical volume manager and had 2GB of swap in a logical volume.

He was installing Oracle and had the need to have 8GB of swap to the system to match the 16GB of physical RAM we had given it.  Traditionally you want to size your swap space to be 50% of physical RAM, but I find in today's high powered systems where RAM is cheap and disk is more costly, we don't always size in that manner.

So typically to re-size a logical volume, especially when we have the luxury of a VM system we just shut down the VM and resize the Virtual Disk as needed, or add a new Virtual Disk while the system is up.

If you go the add new Virtual Disk route to make the changes while the system is hot, you can run this command (and all the following commands for that matter) as root to get the new disk to be seen by the OS:

echo "- - -" > /sys/class/scsi_host/host0/scan

Well, that's what I did in this scenario.  Now that I had the disk available I opened up logical volume manager in an X Session.

I found the new disk in the uninitialized Entities area and initialized it.  I then added it to the Logical Volume group where the swap volume was so I could expand it.

I hadn't done this in awhile and soon realized there was no way to resize or add a swap volume in the tool...  WTF that's lame.

So, bust open a terminal and let's get this thing fixed so I can get back to project work.
Based on what you named your Logical Volume type in:
swapoff /dev/VolGroupXX/LogVolXX

That has stopped the system from using swap on that device.  I also ran umount /dev/VolGroupXX/LogVolXX to ensure it wasn't mounted (not necessary, but I wanted to be more safe than sorry.)

Next we want to issue a command to expand our current swap volume:
lvm lvresize /dev/VolGroupXX/LogVolXX -l +100%Free

What that did was add 100% of the Free space which was previously added to the logical volume group onto that logical volume.

Good, now we need to make this extended disk swap:
mkswap /dev/VolGroupXX/LogVolXX

Next we want to turn swap back on for that logical volume:
swapon -va

Check that it's fully available now:
swapon -s
free -m

Done.  Exit your root shell as always and log-out of your X session.







No comments:

Post a Comment