How to Work with vgextend Command on Linux

Figuring out how to work with the vgextend command in Linux?

There are various reasons why a user would want to adjust the memory and create multiple partitions in a hard disk of their choice. Different methods are used for this purpose, but one of the most popular toolboxes for Linux users is the Logical Volume Management (LVM) toolbox. 

Users prefer LVM because of its advanced features that allow you to create and modify the partitions. If a user had created a partition previously but realized that the partition size might not be what they require, they may use commands such as $vgextend to modify the partition size. 

$vgextend, as the name suggests, can be used to add more volume to an already created partitioned disk. If you are a user of Linux and are interested in learning how to work with the $vgextend command, then you are in the right place, as this article will guide you on everything related to $vgextend. 

So, let’s get going!

How do LVM and $vgextend Commands Work?

The Logical Volume Management toolbox can be used to create logical volumes in the computer system’s hard disk. These volumes are also called partitions. As stated before, if the size of the volume a user created turns out to be less than what they require, they can only add more by first adding a physical memory in the logical volume.

For adding that physical memory, the $vgextend command can be used. The command adds the physical memory to the logical volume dynamically. Physical memory can also be added directly to the volume if the logical volume was created using the $vgcreate command. 

Syntax and Operators of $vgextend Command.

The basic syntax of the $vgextend command is as follows. 

$ vgextend <operator>

There are different operators available with $vgextend, which are as follows. 

-A: this operator is used to specify whether the user wants to back up the metadata or not. A prompt appears where you can choose from yes or no.

-d: this operator is used to specify that the user wants to go into debugging mode. 

t: this operator is used to specify that the user wants to test whatever they are attempting to do with the $vgextend command.

-f: -f can be used to override the previous configurations set by the user.

-q: this operator is used to specify that the user doesn’t want the output and log messages.

-y: when you use this operator, the system is instructed that no further prompt is required and that whatever the user attempts to do is to be executed immediately. 

reportformat basic|json: this operator can be used to specify that the system will output messages in a certain format. 

These different operators can be used in tandem with the $vgextend command. 

Creating a Physical Volume.

To create a physical volume, follow these steps.

Open the Command Terminal.

First, check whether there are any physical volumes created previously. 

$ sudo pvs

To create a physical volume, we must first have a block device. Use the following command to get a list of the different block devices present on the system.

$ sudo lvmdiskscan

You should see a list of the devices, as shown in the image below. 


Now, unmount a block device using the following command as a template. 

$ sudo umount <block device>
work with vgextend command on linux

Enter a block device available to you or the block device you want to unmount

Next, we create the physical volume using the block device we unmounted. Use the following command as a template. 

$ sudo pvcreate <block device>
work with vgextend command on linux

Now use this command to confirm the creation of the physical volume. 

$ sudo pvs

This is how you create a physical volume. 

Creating a Volume Group.

Follow these steps to create volume groups.

You will use the physical volume you created above. 

Use the following command as a template to create a volume group.

$ sudo vgcreate <volume name> <physical volume>
work with vgextend command on linux

To get more information on the volume you just created, use the following command.

$ vgdisplay <volume name>

Now, we extend the memory size of the volume group using the $vgextend command. 

$ vgextend <volume name> <physical volume>
work with vgextend command on linux

Keep in mind that when you are extending, you need to use a physical volume from which no volume groups are created. When you execute the above-mentioned command, the memory size of the physical volume will be added to the specified volume group. 

This is how to work with the $vgextend command in Linux. 

You might have noticed that we have used the keyword “sudo” in many of the commands mentioned yet. Sudo is used to specify the terminal that the admin user of the system is trying to execute the commands. When you use sudo at the start of a new terminal session, the terminal prompts the user to enter the admin user password for execution.

If you want to know how to manage the sudo user and their passwords, you can go to this link.

This was an article on how to manage the $vgextend command in Linux. Moreover, we looked into the $vgextend command in detail. We discussed its syntax and its different operators. Ultimately, we used the LVM toolbox to create physical volumes and volume groups and extended a group using $vgextend.

Creating new volume groups and partitions is something you need to have a good understanding of. Problems can arise if you don’t work out the whole process properly.

So, it is recommended to have complete knowledge regarding partitioning before attempting it.

If this guide helped you, please share it😊


Leave a Reply

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