How to Increase LVM Partition Size in Linux

Hi Techies, one of the advantages of LVM partition is that it can be resized online without any downtime. Here resize means increasing and reducing lvm partition size. Though it is not recommended to reduce lvm partition as it may leads to data corruption.

In this post, we will demonstrate how to extend or increase LVM partition’s size in linux using lvextend command. For the demonstration, we have ‘/dev/vg01-lv01’ partition of size 10 GB and mounted on /data folder.

$ df -Th /data/
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 ext4  9.8G   37M  9.3G   1% /data
$

Let’s assume we want to increase the size from 10 GB to 15GB. Also, we don’t have free space available in volume group vg01.

$ sudo vgs vg01
  VG   #PV #LV #SN Attr   VSize   VFree
  vg01   1   1   0 wz--n- <10.00g 4.00m
$

Let’s deep dive into the steps,

Step 1) Attach New disk to Linux System

Attach 5 GB disk to your linux system, once it is attached make sure it is available at operating system level.

Run lsblk and ‘fdisk -l’ command to verify,

$ lsblk | grep -i sd

lsblk-new-disk-linux

$ sudo fdisk -l

fdisk-l-command-linux

Above output confirms that new disk ‘/dev/sdc’ of size 5 GB is detected at OS level.

Step 2) Create Physical Volume (PV)

Create PV on /dev/sdc disk using pvcreate command,

$ sudo pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.
$ sudo pvs /dev/sdc
  PV         VG Fmt  Attr PSize PFree
  /dev/sdc      lvm2 ---  5.00g 5.00g
$

Step 3) Extend Volume Group

To extend volume group, add new pv (/dev/sdc)  to the volume group (vg01) using vgextend command

$ sudo vgextend vg01 /dev/sdc
  Volume group "vg01" successfully extended
$

Once the volume group is extended then verify its size using vgs command,

$ sudo vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   2   1   0 wz--n- 14.99g 5.00g
$

Above output confirms that now we have 5 GB free space in the volume group.

Step 4) Extend Logical Volume (LV)

Identify the LV using lvs command,

$ sudo lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-ao---- 9.99g
$

In case of Ext4 LVM file system, run following commands to increase the size on line

$ sudo lvextend -L +4.99G /dev/vg01/lv01
$ sudo resize2fs /dev/vg01/lv01
$ df -Th /data

Extend-LVM-Partition-with-lvextend-command

Great, above output clearly confirms that file system size has been increased from 10 GB to 15 GB.

In case of XFS LVM file system, run following command,

$ sudo lvextend -L +4.99G /dev/vg01/lv01 -r

Above command will extend and resize the file system in one go.

That’s all from this post, I hope you have found it informative. Please do share your feedback and queries in below comments section.

Read Also : 20 Useful Grep Command Examples in Linux

Leave a Comment

seventeen − 16 =