Extend an LVM root filesystem

12 04 2010

I’d previously posted how to extend a linux partition that wasn’t part of a logical volume, so I thought I’d probably best document what happens if it is (besides RH and CentOS both default to logical volumes, so it’s probably more useful).  It’s interesting to note that no reboot is necessary for this process to happen (in fact no services even need to be taken down).  Now down to business…

First we ensure we have something to extend over, either a partition on an existing drive or another hard disk.  To do this we can look at the command:

#fdisk -l

This should show a breakdown of all the physical disks in the system, as well as the partitions on those disks.  In my instance I wanted to extend my / filesystem over a new partition on an existing disk (I’d just increased the provisioned space on the disk in ESX as this was a VM).  My machine had only one disk /dev/sda which had 3 existing partitions, shown in fdisk as:

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM
/dev/sda3            2611        5221    20972857+  8e  Linux LVM

As I’d extended the size of /dev/sda I knew that after the end of the third partition there was free space, so I needed to create a new partition for which to extend my / filesystem over.  To do this, I entered the following:

#fdisk /dev/sda

n (to create a new partition)

p (to create a primary partition, if you've 4 or more partitions you'll have to choose extended)

4 (the number of the new partition, this is important you'll need this later)

After this questions fdisk asks what cylinders to start and finish on, I just chose the defaults which are the first free cylinder to the last cylinder on the disk (ie; the free space).  At this point we have a new partition on the disk, but it’s not the right type of partition for LVM – to change the partition type we enter the following:

t (to change the partition type)

4 (enter the number of the partition to change, this should be the partition created earlier)

8e (this is the partition type code for 'Linux LVM')

After the partition is fully created we enter ‘w’ to write and quit the fdisk utility.  At this stage it’s common to get an error stating that the kernel will not see the new partition until after reboot, it’s safe to ignore this message.  To confirm the new partition enter “fdisk -l” again, for example:

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM
/dev/sda3            2611        5221    20972857+  8e  Linux LVM
/dev/sda4            5222        9137    31455270   8e  Linux LVM

Notice the new partition /dev/sda4.

Now we’ve created the new partition I like to run ‘partprobe’ – this gets us round the fact that the kernel doesn’t know about the new partition.  At this point we need to check out our current LVM settings.  To do this we look at the following commands:

# mount 
# /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)

The output of mount tells us in this instance that the logical volume LogVol00 is mounted as the / filesystem.  It also tells us the the logical volume LogVol00 is a member of the volume group VolGroup00.  If necessary you can look at the logical volume attributes using the following command:


You should be able to see the size of the logical volume as well as the volume group it’s a member of.

LVM is a bit like Russian dolls – the physical disk partitions are members of physical volume groups, the physical volume groups are then broken into logical volumes.  The logical volumes are presented to the operating system where they are used for filesystems.  We want to add our new partition (or disk) to the physical volume group so that we can extend our logical volume over it.  To do this we enter the following:

#pvcreate /dev/sda4 

(this creates a new physical volume that we can add to our physical volume group)

#vgextend VolGroup00 /dev/sda4 

(this associates the physical volume with our volume group VolGroup00)

At this point our new partition is available in our volume group as free space.  We use the following command to confirm that and also to record the amount of free space:


From the output of this command we should see an entry called “Free PE” – this is the free physical extents (in other words our free space).  We can use this value to extend our existing logical volume LogVol00 for example (this shows 959 free extents):

#lvextend -l +959 /dev/VolGroup00/LogVol00

After this command completes the logical volume LogVol00 will be extended by the amount of free space our new partition has.  You can display this using the command:


You should notice the “LV size” has increased.  At this point our / filesystem still doesn’t know about the new space, so the last piece of the jigsaw is to let it know about the new space:

#resize2fs /dev/VolGroup00/LogVol00

Once this command completes our / filesystem should see our new free space.  You can confirm this using the command:

#df -h /

Hopefully all is well and you’ve now got additional storage.




3 responses

10 07 2012

Awesome! Thanks so much for posting these steps – I’ve been looking for a while, but haven’t found anything useful until now. partprobe doesn’t seem to work on CentOS 6.2, though, so I did a reboot and things seemed to work fine.

23 04 2013

Hi Mark,

thank you for that great summary – that made my day 🙂
Worked like a charm.
Time for coffee,


29 09 2013

Thanks Mark, it’s really helped.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: