How to add disks to LVM volume on Linux

Question: I have new unused hard drives, and want to add them to an existing LVM volume to increase its size. How can I add disks to LVM to extend an LVM volume?

The biggest advantage of LVM over traditional disk partitions is its support for "dynamic partitions"; you can create and resize (grow or shrink) LVM volumes dynamically as needed. There is no notion of physical disk boundary in LVM logical volumes, so you can create a large LVM volume that spans across multiple smaller physical disks. Such flexible partitioning allows you to manage storage space more efficiently as disk usage patterns change over time.

If you want to add new disks to an existing LVM volume to expand its size, you can easily do it, and here is how.

Preparation

First, use fdisk to check what disks you have on your system.

$ sudo fdisk -l

In this example, three disks are detected (/dev/sda, /dev/sdb, /dev/sdc). The first disk (/dev/sda) is used by LVM, while the other two (/dev/sdb and /dev/sdc) are not added to LVM, and do not have any partition in them.

Check available LVM volume groups and logical volumes with the lvs command.

$ sudo lvs

In the example, one volume group ("yoda-vg") exists, and two logical volumes ("root" and "swap") are created in this volume group.

$ df

According to the df output, the "root" logical volume is mapped to /dev/mapper/yoda--vg-root by the device mapper.

Using this information, I will show how to add two disks /dev/sdb and /dev/sdc to the "root" logical volume in the rest of the tutorial.

Step One: Create Partitions on New Disks (Optional)

The first step is to create a partition on each new disk before adding them to LVM. This step is needed only if you want to allocate only part of the disk to LVM. If you want to add the whole disk to LVM, creating a partition is not necessary, and you can skip this step.

$ sudo fdisk /dev/sdb

Create a primary-type partition which takes up the whole disk (2TB).

Repeat the same step with /dev/sdc.

Use fdisk to verify newly created partitions (/dev/sdb1 and /dev/sdc1).

$ sudo fdisk -l

Step Two: Create Physical Volumes on New Disks

Next, create a physical volume on each new disk partition (/dev/sdb1 and /dev/sdc1).

$ sudo pvcreate /dev/sdb1
$ sudo pvcreate /dev/sdc1

If you haven't created any partition on each disk, run the following commands instead.

$ sudo pvcreate /dev/sdb
$ sudo pvcreate /dev/sdc

Using lvmdiskscan, verify that physical volumes are created successfully.

$ sudo lvmdiskscan -l

Newly created LVM physical volumes are named the same as the original partitions (e.g., /dev/sdb1, /dev/sdc1).

Step Three: Extend an Existing Logical Volume

Next, find the volume group which contains the logical volume to expand, and extend the group by adding newly created physical volumes to it.

In our example, the "root" logical volume belongs to the "yoda-vg" volume group. Let's add a physical volume /dev/sdb1 to this group first.

$ sudo vgextend yoda-vg /dev/sdb1

Again, if there is no partition in /dev/sdb, the following command instead.

$ sudo vgextend yoda-vg /dev/sdb

Given the resized volume group, now extend the "root" logical volume itself:

$ sudo lvm lvextend -l +100%FREE /dev/yoda-vg/root

The above command tells the "root" logical volume to use all available additional free space in its volume group. Note that /dev/yoda-vg/root is the device the "root" volume is mapped to.

The final step is to enlarge the filesystem created inside the "root" volume. Otherwise, the filesystem will not recognize additional free space in the volume.

$ sudo resize2fs -p /dev/mapper/yoda--vg-root

The resize2fs command supports resizing ext2/ext3/ext4 filesystems. It also supports online resizing in case you expand a filesystem. No need to unmount the filesystem.

At this point, the filesystem should be expanded to take up 100% of the resized "root" logical volume.

Repeat the step three with /dev/sdc.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

4 thoughts on “How to add disks to LVM volume on Linux

  1. You do not and really should not create partitions on full disk adds especially if all LVM PVs are full disks. There is just no need for them and it greatly simplifies things when doing pvmoves to you can pvremove a full disk (for example, doing a live upgrade to bigger disks).

    pvcreate /dev/sdd
    pvcreate /dev/sde

    vgextend yoda-vg /dev/sdd /dev/sde

    Also, you can use LVM short names (which makes more LVM sense) instead of full dev mapper names.

    lvextend -l +100%Free /dev/yoda-vg/root
    resize2fs /dev/yoda-vg/root

    • @Christopher Cox:
      Agreed.
      Partitions make things more cumbersome/less flexible.
      If you can create full-disk LVM PVs, it's best to do so.

  2. Even better vgextend converts the raw disks into PV automatically when you add them. No need to pvcreate. It's pretty safe too.
    vgextend yoda-vg /dev/sdd /dev/sde

Leave a comment

Your email address will not be published. Required fields are marked *