Last updated on November 20, 2020 by Dan Nanni
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.
fdisk to check what disks you have on your system.
$ sudo fdisk -l
In this example, three disks are detected (
/dev/sdc). The first disk (
/dev/sda) is used by LVM, while the other two (
/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
$ sudo lvs
In the example, one volume group (
yoda-vg) exists, and two logical volumes (
swap) are created in this volume group.
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/sdc to the
root logical volume in the rest of the tutorial.
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
fdisk to verify newly created partitions (
$ sudo fdisk -l
Next, create a physical volume on each new disk partition (
$ 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
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.,
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
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
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.