Vgextend Command on Linux

How to Work with Vgextend Command on Linux?

We’re here to see how to work with the vgextend command on Linux for logical volume management. 

Logical volume management enables you to create and manage partitions. With it, you can aggregate different physical storage into volume groups. One can create, remove, resize and change storage volumes. You can also easily resize a volume group with physical volume using the vgextend command. 

In this article, our objective is to discuss the concept of logical volume management in Linux. And we’ll also go about how to create physical volumes, logical volumes, and how they can be extended.

How to Work with vgextend Command on Linux

Like we said earlier, we will go through all the possible steps on how to use the vgextend command in the process of logical volume management. But first, let’s get familiar with all the necessary technical terms.

Logical volume management (LVM)

LVM is the recommended volume management tool in Linux. You can use it to manage file systems and logical volumes in Linux. In this section, we will discuss the various commands that can be used for logical volume management. Then in the next one, we will go over the complete procedure for extending a volume group.

In order to create a physical volume, the following command can be used:

$ pvcreate /dev/sda1

This will create a physical volume with the storage block /dev/sda1. To extend a volume group, one can use the following command:

$ vgextend vgdata /dev/sda1

To extend the logical volume and resize the underlying file system together, the following command can be used:

$ lvextend -r -L +250G /dev/vgdata/lvdata

Creating physical volumes, volume groups, and extend volume groups using vgextend

Here, we will talk about the complete procedure on how we can extend the volume group using the vgextend command. 

Creating physical volume

First, we need to check if physical volumes are present in the system. You can check if they already exist in your system using the following command:

$sudo pvs

If you see no physical volume, we will have to create two of them. But before that, you need to list down the block device, as we need a block device to create a physical volume. You can check the block device using the following command:

$sudo lvmdiscscan

As discussed earlier, we will create two physical volumes. Suppose, the aforementioned command shows two block devices /dev/sda1 and /dev/sda2. We will use /dev/sda1and /dev/sdb1 to create physical volumes. But before that, let’s unmount the block devices. The following commands illustrates that:

$sudo unmount /dev/sda1


$sudo unmount /dev/sdb1

Now that the block devices are unmounted, we can initialize physical volumes. In the command above, replace /dev/sda1 and /dev/sdb1 with the block device in your case. For initializing physical volume, the pvcreate command can be used. The following commands creates two physical volumes:

$ sudo pvcreate /dev/sda1


$ sudo pvcreate /dev/sdb1

In order to confirm if the physical volumes are initialized, use the following command:

$sudo pvs

You will see two physical volumes shown as the output of the aforementioned command.

Creating volume groups

Now, let’s verify that we don’t have any volume group in physical volumes. For this purpose, the following command will be used:

$sudo vgs

At this point, you can now create a volume for one of the physical volumes. We will extend its size by adding the other physical volume to it. The following command adds the physical volume to the volume group:

$ sudo vgcreate volgroup1 /dev/sdb1

This will create a volume group for /dev/sdb1 with the name volgroup1. Now, we can verify that a volume group has been created with the following command:

$sudo vgs

To get more details about the volume group, use the following command:

$ vgdisplay volgroup1

Note down the Free PE size for the volume group. We can extend this size by using the vgextend command. 

Extend the volume group with another physical volume

Now, we will extend the volume group with another physical volume. The following command illustrates it:

$ vgextend volgroup1 /dev/sda1

This will extend the volume group volgroup1 with /dev/sda1. A success message should be displayed, mentioning that the volume group has successfully been extended. 

Now, you can see the details of the volume group again with the following command:

$ vgdisplay volgroup1

You should see that your Free PE size has been extended. In this way, you can easily extend the volume group via the vgextend command. For it expands the size of a volume group by appending a physical volume.

Other options of vgextend

There are various parameters that can be passed to vgextend. For example, the -d option can be used for debugging, -f to override various checks (forced operation). The -q option can be used to suppress log messages, -y to avoid prompts, -t for a test, and –A for specifying y/n for auto backup metadata. 

Enabling –A option is strongly advised. Since with it, you can see the complete details of the option via the –h command.

Tip: Physical volumes that were previously missing due to any error and returned, later on, can be added back to the volume group without reinitializing.

And that’s about it for this article. Here, we discussed logical volume management in Linux. We even tackled the various commands that can be used for the management of volumes along with its several options. 

Then, using examples, we also discussed how vgextend can be used to extend a volume group in Linux. If you have more questions regarding this topic, feel free to see the Linux manual via typing man vgextend.

If this guide helped you, please share it.

Leave a Reply
Related Posts