Resizing LVM Partitions

My brother Ben has installed quite a few games and other things on his Ubuntu desktop. Because most of these are programs are available as packages, his 6 GB root partition started getting a bit small. He has a 500 GB hard drive partitioned into root, swap, and home. Ben and I decided to transfer 20 GB from his home partition to his root partition. The drive was configured with LVM which is supposed to make this procedure simple. It turns out it was mildly more complicated than simple, but it wasn’t too bad.

The first step is to boot from a CD like GParted. GParted provides the necessary LVM command line tools to resize the partitions. We need to boot from a CD or another drive because we will be modifying the root partition.

Because I was booted from a CD, I did not capture the output from the commands that I used. The first step is to find the name of the LVM volume group:

lvdisplay

On Ben’s computer, the volume group was “loki”. Next, we make that volume group available:

vgchange --available y loki

Then we decrease the size of the home partition. First we resize the EXT3 file system and then we resize the LVM partition. The “e2fsck” commands check and repair the file system as we go. We are resizing the home partition from 440 GB down to 420 GB.

e2fsck -f /dev/loki/home
resize2fs /dev/loki/home 420G
e2fsck -f /dev/loki/home
lvreduce --size 420G /dev/loki/home
e2fsck -f /dev/loki/home

Once the 20 GB is available, we increase the size of the root partition. We do this in reverse order. First we increase the size of the LVM partition and then increase the size of the file system.

e2fsck -f /dev/loki/root
lvextend --size +20.15G /dev/loki/root
e2fsck -f /dev/loki/root
resize2fs /dev/loki/root 26G
e2fsck -f /dev/loki/root

We rebooted Ben’s computer again, and he now had 26 GB root partition.