Logical Volume Manager: How can I extend a Volume Group?

Want to support HowtoForge? Become a subscriber!
 
Submitted by sinanceylan (Contact Author) (Forums) on Mon, 2008-10-20 20:00. :: Linux

Logical Volume Manager: How can I extend a Volume Group?

It is a good choice to use LVM on Linux. It provides flexible storage management than any other traditional physical partitoning. With LVM, you can easily create, delete, resize storage volumes. First of all, if you want to know what LVM is, there are many documents on the Internet (e.g. http://tldp.org/HOWTO/LVM-HOWTO/). In this example we will learn how to extend a Volume Group size.

Assume that, we have 30GB hard disk and partitioned as follows:

# fdisk /dev/sda

The number of cylinders for this disk is set to 3916.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2563    20482875   8e  Linux LVM

We have two partitions;

/dev/sda1 is a non-LVM partition (Type: 0x83)
/dev/sda2 is an LVM partition (Type: 0x8e)

And we have some unpartitioned free space (3916 - 2563 = 1353 cylinders) And this is our Volume Group Info:

# vgdisplay

--- Volume group ---
VG Name               VolGroup00
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               19.53 GB
PE Size               32.00 MB
Total PE              625
Alloc PE / Size       625 / 19.53 GB
Free  PE / Size       0 / 0
VG UUID               hx8M0U-TMkp-M0cB-eQpb-Avge-UddS-M0ZCc0

We allocated every PE.So, we don't have any free PE. Our goal is to extend VolGroup00 with this unpartitioned free space.

1. Use fdisk and create a new partition and change the type of it to 8e.

# fdisk /dev/sda

The number of cylinders for this disk is set to 3916.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2563    20482875   8e  Linux LVM
/dev/sda3            2564        3916    10867972+  8e  Linux
Command (m for help): t
Partition number (1-3): 3
Hex code (type L to list codes): 8e
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2563    20482875   8e  Linux LVM
/dev/sda3            2564        3916    10867972+  8e  Linux LVM
Command (m for help): w
#

Your new partition table should looks like above. 2. Now, we should create a new PV to use this new partition. To do this use pvcreate command. (i.e. pvcreate /dev/sda3):

# pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created

Okay, we have a new PV. Let's look at it.

# pvdisplay

--- Physical volume ---
PV Name               /dev/sda2
VG Name               VolGroup00
PV Size               19.53 GB / not usable 2.81 MB
Allocatable           yes (but full)
PE Size (KByte)       32768
Total PE              625
Free PE               0
Allocated PE          625
PV UUID               vRmmoI-0cM9-AFRS-1ruI-1b7S-IKCn-gO35nl
"/dev/sda3" is a new physical volume of "10.36 GB"
--- NEW Physical volume ---
PV Name               /dev/sda3
VG Name
PV Size               10.36 GB
Allocatable           NO
PE Size (KByte)       0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               EQ2sdZ-b2a3-OThW-8TE5-LyQS-SYg4-DOmykI

3. The final step we have to extend VolGroup00 with this new PV. To do this use pvextend command. (i.e. pvextend /dev/VolGroup00 /dev/sda3). You will see something like this;

# vgextend /dev/VolGroup00 /dev/sda3

Volume group "VolGroup00" successfully extended

Let's look at what we have.

# vgdisplay

--- Volume group ---
VG Name               VolGroup00
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  8
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                2
Act PV                2
VG Size               29.88 GB
PE Size               32.00 MB
Total PE              956
Alloc PE / Size       625 / 19.53 GB
Free  PE / Size       331 / 10.34 GB
VG UUID               hx8M0U-TMkp-M0cB-eQpb-Avge-UddS-M0ZCc0

We did it. We have 331 Free PE in VolGroup00.

That's all. You see that using LVM is most comfortable way of volume management. But, be careful using lvm commands. Using incorrect parameter can make your files inaccessible.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Nigel (not registered) on Mon, 2013-09-09 14:49.

Thanks for this, very helpful and I have just successfully extended my volume group.

Thought you would want to know you have a typo in step 3, sentence "To do this use pvextend command. (i.e. pvextend /dev/VolGroup00 /dev/sda3)." should use vgextend and not pvextend. The command under it is correct, but you made the typing mistake in the instructions.

Submitted by Chris Burnley (not registered) on Wed, 2012-10-31 07:38.
Don't forget to run resize2fs /dev/vg_xxxx/lv_xxxx to resize the filesytem
Submitted by Sergio, from spain (not registered) on Sun, 2012-05-27 16:21.
Very good tutorial. Thank  you a lot !
Submitted by Anonymous (not registered) on Wed, 2011-05-18 08:46.
Thanks ! very helpful !
Submitted by Anonymous (not registered) on Wed, 2010-08-11 21:06.
thank you! this was helpful.