Using commands Vgcreate, lvcreate, and lvextend to manage and create LVM in Linux

Source: Internet
Author: User
Tags mkdir reserved uuid advantage lfcs

As some of the changes in the LFCs exam took effect on February 2, 2016, we added some necessary topics to the LFCs series. We also recommend the students for the exam, while reading the LFCE series.

One of the most important decisions to make when installing a Linux system is to allocate space to system files, home directories, and so on. Make a mistake in this place, and then expand the area of insufficient space, which is both troublesome and risky.

Logical Volume management (LVM) has many advantages over traditional partitioning management and has become the default choice for most, if not all, Linux distributions when installed. The greatest advantage of LVM should be the ease with which you can adjust (reduce or increase) the size of the logical partition.

The composition structure of LVM:

Configure a single or multiple hard disk or one or more partitions into a physical volume (PV).
A volume group (VG) created with one or more physical volumes. You can think of a volume group as a separate storage unit.
You can create multiple logical volumes on a volume group. Each logical volume is equivalent to a partition in the traditional sense--the advantage is that its size can be resized as needed, as mentioned earlier.
In this article, we will create three physical volumes using three 8 GB disks (/DEV/SDB,/DEV/SDC, and/DEV/SDD) respectively. You can either create PV directly on the entire device, or you can partition it before creating it.

Here we choose the first way, if you decide to use the second one (refer to the third part of this series: Create partitions and file systems) to ensure that each partition is of type 8e.

Create physical volumes, volume groups, and logical volumes

To create a physical volume on/dev/sdb,/DEV/SDC, and/DEV/SDD, run:


You can list the newly created PV by:


And get detailed information for each PV, by:

(X is B, C or D)

If you do not enter/DEV/SDX, you will get all PV information.

Create a volume group using/DEV/SDB and/DEV/SDC, named Vg00 (you can extend the space by adding other devices when you need it, we'll wait until we explain this, so we'll keep the/DEV/SDD for the time being):

# vgcreate VG00/DEV/SDB/DEV/SDC

As with physical volumes, you can also view the volume group's information by:

# Vgdisplay Vg00

Since vg00 is made up of two 8 GB disks, it will be displayed as a GB hard drive:

When it comes to creating logical volumes, the allocation of space must take into account current and future requirements. It is a good idea to name each logical volume by its purpose.

For example, let's create two LV, named Vol_projects (GB) and vol_backups (the rest of the space), for deployment project files and system backups, respectively.

Parameter-n is used to specify the name for the LV, while-L is used to set the fixed size and the space for the specified percentage size in the reserved space of the-l (lowercase L) in the VG.

# lvcreate-n Vol_projects-l 10G vg00
# lvcreate-n Vol_backups-l 100%free vg00

As before, you can view the list of LV and the basic information by:


Or view the details by:

# Lvdisplay

To view information for a single LV, use Lvdisplay plus VG and LV as parameters, as follows:

# Lvdisplay Vg00/vol_projects

As shown above, we see that LV has been created as a storage device (refer to the LV Path line). Before you can use each logical volume, you need to create a file system on it first.

Here we take ext4 for example, because for each LV size, the EXT4 can both grow and decrease (relative XFS only allows to increase):

# mkfs.ext4/dev/vg00/vol_projects
# mkfs.ext4/dev/vg00/vol_backups

We'll show you in the next section how to resize a logical volume and add additional external storage space when needed.

Adjust logical volume size and expand volume Group

Now imagine the following scenario. The space in the vol_backups is about to run out, and the vol_projects has the space of surplus. Because of the LVM nature, we can easily reduce the size of the latter (for example, 2.5 GB) and assign it to the former, while resizing each file system.

Luckily, it's easy, just:

# lvreduce-l -2.5g-r/dev/vg00/vol_projects
# lvextend-l +100%free-r/dev/vg00/vol_backups

When you adjust a logical volume, it is important that the minus sign (-) or plus sign (+) is included. Otherwise, the LV will be set to the specified size, rather than the specified size.

There are times when you may encounter problems that cannot be solved just by adjusting the size of a logical volume, when you need to purchase additional storage devices, and you may need to add a hard disk. Here we will simulate this by adding the PV (/DEV/SDD) that was reserved prior to configuration.

Want to add/DEV/SDD to Vg00, execute:

# Vgextend VG00/DEV/SDD

If you perform Vgdisplay vg00 before and after you run the previous command, you will see that the size of the VG has increased.

# Vgdisplay Vg00

Now, you can use the new add space, adjust the size of the existing LV according to your needs, or create a new LV.

Mount logical volumes on startup and requirements

Of course, if we don't intend to actually use logical volumes, then creating them makes no sense. To better identify the logical volume, we need to find its UUID (used to identify a unique and unchanging attribute for a formatted storage device).

To do this, you can use Blkid plus the path for each device:

# blkid/dev/vg00/vol_projects
# blkid/dev/vg00/vol_backups

To find the UUID for a logical volume
To find the UUID for a logical volume
To create a mount point for each LV:

# mkdir/home/projects
# mkdir/home/backups

and insert the appropriate entry in/etc/fstab (make sure to use the UUID you obtained earlier):

Uuid=b85df913-580f-461c-844f-546d8cde4646/home/projects EXT4 Defaults 0 0
Uuid=e1929239-5087-44b1-9396-53e09db6eb9e/home/backups EXT4 Defaults 0 0

Save and Mount LV:

# mount-a
# Mount | grep Home

When it comes to the actual use of LV, you need to set the appropriate ugo+rwx for it as explained in the eighth of this series: Managing Users and groups of users

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.