Tuesday, May 26, 2015

Increasing Swap Space by Stealing from /home

  Recently, I was installing Oracle 12c on Red Hat Enterprise Linux 6. This should have been easy, right? In this case, I did not install the OS - my IT guy did, and he didn't know that Oracle has a minimum swap size requirement. And of course, I didn't remember to tell him. So... as I was checking prerequisites, I find that I was below the minimum on swap space. I needed 16G, and only had 4G.

What to do? Well, the simplest approach is to steal home. Or actually, steal some space from /home.

In my case, I had about 4G of swap space, and I had about 224G of space in the /home partition. With a default install of RHEL6, the filesystems are in volume groups, so instead of using fdisk, we get to use lvm commands, which is really pretty cool.

The short and simple approach follows. Note, this is not a well written guide with examples and output and highlights. It is a quick and dirty cookbook for someone who knows what they are doing. I might expand on this later... or not. Log off all existing users, and login as root. In a bash shell, run the following, changing the paths and sizes for the specifics for your install.

Preliminary Information

vgs
Get the name and size of the volume group.
lvs
This will show the size of the various logical volumes in the volume group
mount
Show the paths of the mounted filesystems. Take the base of the home path, and find out the other paths.
fdisk -l /dev/mapper/vg_node*
This will give us the other similarly named partitions, which will give us the swap partition path.

Reducing the Size of /home and the Logical Volume

umount /home
Yep. It unmounts /home so you can mess with it.
e2fsck -f /dev/mapper/vg_node2-lv_home
This checks the volume, and is required before a resize.
resize2fs -p /dev/mapper/vg_node2-lv_home 210G
This resizes the ext4 volume to 210G, which added enough space for the swap space I needed.
lvreduce -L 210G /dev/mapper/vg_node2-lv_home
I use the exact same size specifier here, so I don't destroy the filesystem.
e2fsck -f /dev/mapper/vg_node2-lv_home
Not strictly required, but it really makes me feel better to do this.
mount /home
We should have a working home volume now.
lvs
Show use the new size of the volumes. In this example, /home should be 210G.

Increasing the Size of swap

cat /proc/swaps
Check out the size of our existing swap
swapoff /dev/mapper/vg_node2-lv_swap 
Turn it off so we don't mess with it.
vgdisplay
This will show you the number of free extents, which we pass to the -l param below.
lvextend -l+3682 /dev/mapper/vg_node2-lv_swap 
We extend the volume by as much as we had free (in this case 3682 extents).
mkswap /dev/mapper/vg_node2-lv_swap 
We recreate the swap space using all available space.
swapon /dev/mapper/vg_node2-lv_swap 
Turn on the swap space!

cat /proc/swaps
Verify that the new swap space is being used.
lvs
Display the size of the logical volumes.

No comments: