Posts Tagged ‘LVM’

Split a LVM2 Volume Group into two or more!

Friday, February 15th, 2008

We’ve all had that sinking feeling in our gut. The feeling when you realize that in a rush someone let CentOS, Fedora, or Redhat Linux auto-partition disks into one huge LVM2 mess. Until recently my answer would always simply be that its faster to reformat it and restore than try and reduce the volume group. That was until I had no choice.

I was absolutely horrified at the quality of information which was available to carry out what seems like a fairly mundane task. I am sure there are 300 different ways to do this exact same process but I needed a way that would work every time. (That is how I roll)

So about 10 or 15 completely destroyed file systems later, I share with you the fruit of my labor.

What this guide covers:

This guide covers shrinking a logical volume so that you can create more logical volumes, partitions and file systems.

What this guide does not cover:

Removing physical volumes from a Volume Group so that you can separate physical disks.

Warning: I would recommend following the guide below on a test machine prior to carrying it out on a production machine. Either way takes no responsibility for any damages caused by anything you do as a result of the instructions on this page, or any drinking games described on the other pages of this site.


–A Linux Rescue CD with LVM2 support (I used CentOS 5.1)


Boot your system from your rescue CD.

I will assume that your current volume group is VolGroup00 and your current logical volume is VolGroup00. I will be creating a new logical volume LogVol02 for the sake of example.

#Activate the Logical Volume so that it becomes available.

lvm lvchange -ay /dev/VolGroup00/LogVol00

#Retrieve information about the file system you wish to shrink.

tune2fs -l /dev/mapper/VolGroup00-LogVol00

Make note of the:

Block Count: 60252160
Block Size: 4096 (4K)

My disk is a 250GB RAID-1 (60252160 4K Blocks) I am going to slice my logical volume in half because it is an easy example.

#Force FSCK to run on the logical volume you want to shrink

e2fsck -f /dev/VolGroup00/LogVol00

Resize the logical volume keep in mind that the number on the end represents 4K blocks! 30126080 x 4 = 120504320K / 1048576 = ~115GB

#Notice we give resize2fs its size in 4K blocks.

resize2fs /dev/VolGroup00/LogVol00 30126080

Multiply the number you used above by 4 (30126080 * 4) = 120504320 we give lvreduce its value in K so we can get exactly what we want.

#resize the file system.

lvm lvreduce –size 120504320K /dev/VolGroup00/LogVol00

#use vgdisplay to figure out available space

lvm vgdisplay

#below you see      extents /  space free

Free  PE / Size       3677 / 114.91 GB

#Create a new Logical Volume: LogVol02
#You can create a LV using many different options:
#–size 114G would’ve created a 114GB LV
#–extents 3677
#I used extents because it seems more exact.

lvm lvcreate –extents 3677 -n LogVol02 VolGroup00

#Create a new ext3 file system on LogVol02

mkfs.ext3 /dev/VolGroup00/LogVol02


You now have two logical volumes where there used to be one!

Impress your friends, your co-workers, or maybe just yourself. Either way if you ever need to get your hands in LVM I hope this makes it easier.