Linux Administrator

Resize LVM – How To Increase An LVM Partition

How-to-increase-lvm-partition-800x430
mm
Written by Santosh Prasad

In this article I will show you how to expand an LVM volume or partition in Linux by first resizing logical volume, advantage of resizing the file system to take advantage of the additional space.

In my example I am going to expand logical volume /var/centos/var from 5GB to 10GB. Currently I have mounted logical volume to /mnt.

Logical Volume Manager (LVM) Overview

Before resizing process it is important you first understand some lvm basic concepts around physical volumes, volume groups, logical volumes and the file system.

  • Physical Volume (PV) : PV can be create on a whole physical disk like /dev/sda or a Linux partition.
  • Volume Group (VG) : VG can be created with at least one or more PV (physical volumes).
  • Logical Volume (LV) : This is also called partition, it sits within a VG ( volume group ) and has a file system written to it.
  • File System : File system such as ext3 or ext4 will be on the logical volume (LV)

Increase and expand the logical volume (LVM)

We can increase the lvm on fly with no downtime or mount the volume without interruption. To resize the LV, VG that it is in must have free space available.

Check free space of VG (volume group)

Run vgdisplay command as shown below and look at the “Free PE / Size” field.

# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               20.74 GiB
  PE Size               4.00 MiB
  Total PE              5309
  Alloc PE / Size       4030 / 15.74 GiB
  Free  PE / Size       1280 / 5.00 GiB
  VG UUID               VvG6Sp-wIgb-LTh0-szdU-s9R1-a6K9-qHassI

Above you can see there is 5GB of free space is available in the volume group, as shown by “Free PE / Size 1279 / 5.00 GiB”.

Note :- If you do not have enough free space in the volume group, you will first need to extend the volume group (VG) to extend the LV, or Alternatively if you have multiple LVM partitions, you could shrink a different logical volume first to create space within the volume group.

Now that we have confirmed there is space free within the volume group, confirm the name of the logical volume you want to increase as well as how much space you plan on adding. The below lvdisplay command will show all logical volumes and their current size. It will also show the volume group that the logical volume is a member of, so ensure that the correct volume group has been checked for enough space with vgdisplay as previously mentioned to prevent trying to increase a logical volume that is inside some other volume group.

As shown in the example below, we are going to be working with the logical volume “var” which is in volume group “centos”, the volume group we saw in vgdisplay.

In my example I only have just the one volume group, but there may have more so you need to check first.

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/var
  LV Name                var
  VG Name                centos
  LV UUID                7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M
  LV Write Access        read/write
  LV Creation host, time CentOS7, 2015-04-16 07:50:25 +1000
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

Now it’s time to expand the logical volume. In the below example we are using the -L flag to increase by a size specified (M for Megabytes, G for Gigabytes, T for Terabytes). You can alternatively remove the + to increase to the amount specified rather than by the amount specified.

# lvextend -L+5G /dev/centos/var
   Rounding size to boundary between physical extents: 4.90 GiB
   Size of logical volume centos/var changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
   Logical volume var successfully resized

As you can see we have increased the logical volume /dev/centos/var by 5GB, currently it is already 5GB so this will increase it to total of 10GB.

You can do the same with below command.

# lvextend -L 10G /dev/centos/var

As this is what was specified with no +.

Alternatively if you instead want to just use all free space in the volume group rather than specifying a size to increase to, run below command

# lvextend -l +100%FREE /dev/centos/var

Verify the extended LV using lvdisplay command shown below.

# vgdisplay
  --- Logical volume ---
  LV Path                /dev/centos/var
  LV Name                var
  VG Name                centos
  LV UUID                7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M
  LV Write Access        read/write
  LV Creation host, time CentOS7, 2015-04-16 07:50:25 +1000
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

Now that the logical volume has been extended, we can resize the file system. This will extend the file system so that it takes up the newly created space inside the logical volume. The command may differ depending on the type of file system you are using.

# resize2fs /dev/centos/var

Alternatively,

# xfs_growfs /dev/centos/var

After resizing the file system the space should be ready to use. We can check disk space using df command.

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  9.8G  1.4G  8.5G  14% /
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    914M     0  914M   0% /dev/shm
tmpfs                    914M  8.6M  905M   1% /run
tmpfs                    914M     0  914M   0% /sys/fs/cgroup
/dev/sda1                497M   96M  402M  20% /boot
/dev/mapper/centos-var    10G   33M   10G   1% /mnt

Above I have run a ‘mount /dev/centos/var /mnt’ to mount the logical volume to /mnt, as shown above /mnt is correctly reporting a size of 10G.

Thanks:)

Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment