RSS LinkedIn Twitter

CentOS 6.4 – Changing the Size of your Swap Disk

June 24th, 2013 Categories: Uncategorized

When I install CentOS using the XenServer template, it doesn’t allow make any changes to the disk drive configuration. This has two side effects that typically annoy me. First, it calculates an amount of swap space which could be anywhere from 50% to 200% of the amount of RAM you have (I’m not entirely sure of the calculation method it uses, but it takes into account disk size and amount of RAM). Secondly, if I have a drive that’s larger than 32GB, it will partition a chunk of it to be mounted at /home. I like to use separate logical volumes for a lot of things, however, /home is not typically one of them.

I’m going to cover both situations in this post. First let’s change the size of the swap space, and assign that space back to the root logical volume.

Resizing the Swap Drive

1. Turn off swapping.

swapoff -v /dev/VolGroup/lv_swap

2. Reduce the size of the logical volume.

lvm lvreduce /dev/VolGroup/lv_swap -L -8192M

3. Make the new swap space.

mkswap /dev/VolGroup/lv_swap

4. Turn swapping back on.

swapon -va

5. Check to see if your swap partition is the size you wanted it.

cat /proc/swaps

Deleting the lv_home Logical Drive.

1. Unmount /home.

umount /home

2. Remove the /home mount from fstab

vi /etc/fstab

3. Remove the line from fstab that looks like:

/dev/mapper/VolGroup-lv_home /home                       ext4    defaults        1 1

4. Remount drives

mount -a

5. Remove the logical drive.

lvremove /dev/VolGroup/lv_home

I usually find that a reboot at this point gives me better results. I’m not sure the cause of it, but on occasion I have not rebooted until the end, and found out I had corrupted my drive by the end.

Resize the lv_root Logical Drive.

1. Extend the logical volume.

lvextend -l +100%FREE /dev/VolGroup/lv_root

2. Resize the volume to use the remaining free space.

resize2fs /dev/VolGroup/lv_root

3. Check that the drive is the size you were expecting.

df -h

No comments yet.

Leave a Comment