How to increase partition in linux using LVM

Resize of LVM partition is very easy in Unix , resize of LVM partition can be done without unmounting the the existing file system partition.

let’s assume that you have an ext3 partition lv_root which is mounted on / and a swap partition lv_root in a logical volume group vg_controller, now you are running out of space in /, there’s no space left in the above volume group but you have a brand new disk drive with lots of free space.

How to add some space to the / partition?

PV = Physical Volume

VG = Volume Group

LV = Logical Volume

WARNING: If you have important data in any directory under / then backup before attempting this.

Steps to increase or re-size the existing Linux partition using LVM ?

I’ll assume the spare disk is called /dev/sdb(108GB), make sure to switch to administrator (root)

[root@experts ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_controller-lv_root

50G  4.0G   43G   9% /

tmpfs                 2.9G  224K  2.9G   1% /dev/shm

/dev/sda1             485M   56M  404M  13% /boot

/dev/mapper/vg_controller-lv_home

245G  188M  233G   1% /home

vg_controller-lv_root

 

know physical volumes..

[root@compute1 ~]# pvdisplay

know physical volumes

know volume groups

[root@experts ~]# vgdisplay

know Logical Volume created and mapping

vgdisplay

[root@experts ~]# lvdisplay

check disk attached status

lvdisplay

 [root@experts ~]#fdisk -l

Disk /dev/sdb: 108.4 GB, 108447924224 bytes

255 heads, 63 sectors/track, 13184 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0×00000000

know Volume Group created

fdisk -l

2. Create a new partition of appropriate size using fdisk and also change partition id.

[root@experts ~]#fdisk /dev/sdb

options  m, n, p , partition cylinder default 1,Last Cyliner: +90G  ,  p

new partition

option :t , select partition 2,  L to list code :8e Linux LVM,

write data to disk

3.Create an ext3 file system in the partition this is required to make file system usable .

Create an ext3

[root@experts ~]#mkfs.ext3 /dev/sdb2

 

4.Initialize the partition for use as a physical volume in lvm and add it to vg_controller

[root@experts ~]#pvcreate /dev/sdb2

sdb1 new physical volume

 [root@experts ~]#vgextend vg_controller /dev/sdb2

 

5.Extend lv_root (use ‘df -h’ to check that / is mounted on lv_root) as required (by 90G here)

# lvextend -L +90G /dev/vg_controller/lv_root

lvextend

 6.Finally, resize the filesystem (this part normally would require unmounting /, but for ext3 and 2.6 Kernels it works while the partition is mounted)

[root@experts ~]#resize2fs /dev/vg_controller/lv_root

resize2fs