Loading...
 

LVM Expanding Logical Volumes

Lets say we want to increase the size of the logical volume “home”
root@mk-scripts-vmhost-1:~# df -h /home/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/DomU--VG1-home
4.6G 138M 4.3G 4% /home
The new disk should be visible
root@mk-scripts-vmhost-1:~# ls /dev/xvdd
/dev/xvdd

Create the physical volume

root@mk-scripts-vmhost-1:~# pvcreate /dev/xvdd
Physical volume “/dev/xvdd” successfully created
root@mk-scripts-vmhost-1:~# pvdisplay -s
Device “/dev/xvdc1” has a capacity of 56.00 MiB
Device “/dev/xvdd” has a capacity of 5.00 GiB

Add the PV into the Volume Group

root@mk-scripts-vmhost-1:~# vgdisplay -s DomU-VG1
“DomU-VG1” 40.00 GiB 39.94 GiB used / 56.00 MiB free

root@mk-scripts-vmhost-1:~# vgextend DomU-VG1 /dev/xvdd
Volume group “DomU-VG1” successfully extended
root@mk-scripts-vmhost-1:~# vgdisplay -s DomU-VG1
“DomU-VG1” 44.99 GiB 39.94 GiB used / 5.05 GiB free

Resize the Logical Volume

root@mk-scripts-vmhost-1:~# lvdisplay /dev/DomU-VG1/home | grep Size
LV Size 4.60 GiB
root@mk-scripts-vmhost-1:~# lvresize -L +5.05G DomU-VG1/home
Rounding up size to full physical extent 5.05 GiB
Extending logical volume home to 9.65 GiB
root@mk-scripts-vmhost-1:~# lvdisplay /dev/DomU-VG1/home | grep Size
LV Size 9.65 GiB Logical volume home successfully resized

Resize the filesystem on the LV

root@mk-scripts-vmhost-1:~# resize2fs /dev/mapper/DomU--VG1-home
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/mapper/DomU--VG1-home is mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/DomU--VG1-home to 2530304 (4k) blocks.
The filesystem on /dev/mapper/DomU--VG1-home is now 2530304 blocks long.

root@mk-scripts-vmhost-1:~# df -h /home/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/DomU--VG1-home
9.6G 139M 8.9G 2% /home