Linux Commands

The lvextend Linux Command

“Is your LVM partition running out of space? Or perhaps you wish to extend it to accommodate more items. Whatever the case, Linux offers an easy way of extending your LVM partitions.

With the Logical Volume Manager 2 (LVM2), you can aggregate your physical storage into various groups and divide them into logical volumes. You can proceed further to extend or reduce the sizes of the logical volumes to use the free space in the volume group. Linux systems make this possible using the lvextend command, which offers various ways of extending logical volumes, and no reboot is needed. You can extend the logical volumes on a live root system, and we will see how to go about it in today’s post.”

What is LVM?

Linux systems use Logical Volume Management to manage various file systems and logical volumes. You are probably used to their volume management tools like GParted, but LVM offers more features and is more preferred.

Before using any LVM tools, you must install the LVM package using the command below.

$ sudo apt-get install lvm2

Check the version of the LVM to verify the installation.

To extend a logical volume, you must first have a physical volume and volume group created. You can verify so using the commands below in administrator mode.

$ sudo pvs

$ sudo vgs


Also, check the available logical volumes using the command below.

We will be extending the lv01 logical volume that is currently 100.00Mbs.

To extend a logical volume, you should have free space in the volume group, and our volume group is vg01. Use the vgs command to check the available space.

For our case, our volume group labeled vg01 has a free space of 408.00M.

Extending the Logical Volume Using lvextend

There are various options for extending the logical volume. We will cover all the options.

Method 1. Extend by Specific Unit

For instance, if we need to extend our logical volume by 100 Mb, we can use the syntax below.

# lvextend -L +[unit] [logical-volume-path]

The command would be: Note that you must root for the command to work.

# lvextend -L +100M /dev/vg01/lv01

Verify the new extended size using the command below.

# lvs

Our initial size was 100Mb, but we’ve extended it to 200Mb.

Method 2. Extend by Setting the Size

Alternatively, you may set a predefined size for your logical volume and extend it to that size. Instead of adding a given unit to the current one, this method changes the current size to the one specified.

For our case, let’s extend our volume to 330Mb using the command below.

# lvextend -L 330M /dev/vg01/lv01

The -L is added to specify the unit size. Our output will be:

We get a success message implying everything worked fine. Let’s confirm our new size for the logical volume.

Bingo! We successfully extended the volume.

Method 3. Extend by Percentage

lvextend also supports specifying a percentage by which to extend the logical volume. The percentage specified extends the current size by the percentage of the total space. For instance, let’s extend by 5%. Our current size is 332.00M.

The new command will be as shown.

# lvextend -l +5%VG /dev/vg01/lv01

Our new size extends to 360.00M

Method 4. Extend Using Remaining Free Space

The above method extends to a fraction of the total space. However, this method extends based on the percentage of free space available. Therefore, using 100% will extend and use all the available free space.

Let’s extend by 50% of the free space using the command below.

# lvextend -l +50%FREE /dev/vg01/lv01

Finally, check the new volume and the remaining available space to confirm the latest volume.

Our new volume size is 436M, and the remaining free space is 72M

Wrap Up

That’s how to extend logical volume size using the lvextend command. This guide covered various usage examples of the lvextend, and we’ve seen how you can use it to increase the size of your logical volumes using four methods. You no longer have to worry about running out of space for your LVM partitions when you have the lvextend command available.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.