You are here

howto extend the logical volume in linux

Recently, I added a new hard disk to my linux box and I decided to document it the process of how to extend to root partition over the 2 disks.

First of all the disk was the 2nd disk on the system so it was /dev/sdb

so we do a

pvcreate /dev/sdb

then we add this new pv we created to an already existing lv. for the purposes of this document let us call it lv_root

vgextend vg_root /dev/sdb

which means that vg_root has /dev/sda2 and /dev/sdb

next step is to extend the lv using the vg_root. here, there are several ways to do it.
1. is to add an additional 50M to the lv with

lvextend -L +50M /dev/vg_root/lv_root

2. is to add an additional 200 physical extents to the lv. the extents are obtained from the output of

vgdisplay | grep "Free  PE"

and the command for that is

lvextend -l 200 /dev/vg_root/lv_root

3. to extend the vg with all the free space on the new disk

lvextend /dev/vg_root/lv_root /dev/sdb

having done, our work is still not done. because while the lv is now bigger, the filesystem is still the same and also needs to be increased. here i am assuming you have an ext3 or ext4 based filesystem for the command to work:

resize2fs -p /dev/vg_root/lv_root

and we are done.


 the fs step can be removed by going back to step 3 and using this command

lvextend -r -l 100%FREE VolGroup01/LogVol00

it might also be a good idea to disable the lvm with

lvchange -an /dev/vg_root/lv_root