Table of Contents
In this article I will take you through 11 Useful LVM(lvcreate, pvcreate and vgcreate) command example on Linux. You might be aware of LVM Technologies which is frequently being used by multiple Organizations to manage their resources effectively. You can check more about LVM Configuration on How to Configure LVM in Linux (pvcreate, vgcreate and lvcreate) Using 6 Easy Steps.
It is very important as Linux Professional to understand the usage of different LVM Commands like lvcreate, pvcreate and vgcreate. You will understand more about the usage of these commands as you go through the different examples in this article.
Useful LVM(lvcreate, pvcreate and vgcreate) Command Examples
Also Read: How to Delete Volume Group(LVM) in Linux Using 5 Easy Steps
Example 1: How to Create Physical volume using pvcreate command
In this example, we are trying to create physical volume /dev/sdb1
and /dev/sdc1
using pvcreate /dev/sdb1 /dev/sdc1
command as shown below.
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created.
NOTE:
root
user to run all the below commands.You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.Example 2: How to Create Volume Group using vgcreate command
In this example, we are trying to create volume group vol_grp
using physical volume /dev/sdb1
and /dev/sdc1
by running vgcreate vol_grp /dev/sdb1 /dev/sdc1
command as shown below.
[root@localhost ~]# vgcreate vol_grp /dev/sdb1 /dev/sdc1 Volume group "vol_grp" successfully created
Example 3: How to Create Logical Volume using lvcreate command
In this example, we are trying to create logical volume log_vol
of size 200
logical extents from volume group vol_grp
using lvcreate -l 200 -n log_vol vol_grp
command as shown below.
[root@localhost ~]# lvcreate -l 200 -n log_vol vol_grp Logical volume "log_vol" created.
Example 4: How to Scan Physical Volume using pvscan command
In this example, we are trying to scan and detect all physical volumes using pvscan
command as shown below. As you can see from below output, pvscan is currently detecting 3 physical volumes in the System - /dev/sda2
, /devsdb1
and /dev/sdc1
.
[root@localhost ~]# pvscan PV /dev/sda2 VG centos lvm2 [<39.00 GiB / 4.00 MiB free] PV /dev/sdb1 lvm2 [<8.00 GiB] PV /dev/sdc1 lvm2 [<8.00 GiB] Total: 3 [54.99 GiB] / in use: 1 [<39.00 GiB] / in no VG: 2 [<16.00 GiB]
Example 5: How to Scan Volume Group using vgscan command
In this example, we are trying to scan and detect all volume group using vgscan
command as shown below. As you can see from below output, vgscan
command is currently detecting two volume groups - vol_grp
and centos
.
[root@localhost ~]# vgscan Reading volume groups from cache. Found volume group "vol_grp" using metadata type lvm2 Found volume group "centos" using metadata type lvm2
Example 6: How to Scan Logical Volume using lvscan command
In this example, we are trying to scan and detect all logical volumes using lvscan
command as shown below. As you can see from below output, lvscan
command is currently detecting three logical volumes - log_vol1
, swap
and root
.
[root@localhost ~]# lvscan ACTIVE '/dev/vol_grp/log_vol' [800.00 MiB] inherit ACTIVE '/dev/centos/swap' [2.00 GiB] inherit ACTIVE '/dev/centos/root' [36.99 GiB] inherit
Example 7: How to Display all Physical Volume using pvdisplay command
In this example, we are trying to display all physical volume using pvdisplay
command as shown below. This command will give multiple information about a Physical Volume like its name, PV Size, PE Size, Total PE, Free PE, Allocated PE etc. As you can see from below output, there are currently 3 Physical Volume present in the System i.e /dev/sda2
, /dev/sdb1
and /dev/sdc1
in which /dev/sda2
is the physical volume used for centos Installation by default.
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <39.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 9983 Free PE 1 Allocated PE 9982 PV UUID uJMT8K-6jPs-OeYy-Qt1w-PLdB-P090-NjbkFB "/dev/sdb1" is a new physical volume of "<8.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size <8.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID nDXlXQ-LuKp-d4X0-UPUa-WSnA-BS9c-QTOBZJ "/dev/sdc1" is a new physical volume of "<8.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size <8.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID ZpLhRg-GG6c-PgX0-Vtbj-sKnF-Xvct-OCR8I1
Example 8: How to Display all Volume Group using vgdisplay command
In this example, we are trying to display all volume group using vgdisplay
command as shown below. This command will give multiple information about a Volume Group like its name, VG Status, VG Access, VG Size etc. As you can see from below output, there are currently 2 Volume Group available in the System i.e vol_grp
and centos
in which centos
is the default volume group created during installation.
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vol_grp System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 15.99 GiB PE Size 4.00 MiB Total PE 4094 Alloc PE / Size 0 / 0 Free PE / Size 4094 / 15.99 GiB VG UUID 2W12Cx-zE0Q-r35g-tTE4-3vfp-fzE6-5FBRLD --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <39.00 GiB PE Size 4.00 MiB Total PE 9983 Alloc PE / Size 9982 / 38.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID tA52Mr-InE5-O80P-NX7r-XZ35-bONj-FMST8E
Example 9: How to Display all Logical Volume using lvdisplay command
In this example, we are trying to display all logical volume using lvdisplay
command as shown below. This command will give multiple information about a Logical Volume like its volume group name, LV UUID, LV Status, LV Access, LV Size etc. As you can see from below output, there are currently 3 Logical Volume available in the System i.e log_vol1, swap and root in which swap and root are default created logical volume.
[root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/vol_grp/log_vol1 LV Name log_vol1 VG Name vol_grp LV UUID C104Xa-gZgZ-O1q0-9o9v-gJlE-y9Y3-IPA9lc LV Write Access read/write LV Creation host, time localhost.localdomain, 2020-05-05 03:22:40 -0400 LV Status available # open 0 LV Size 12.00 MiB Current LE 3 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID xcPG6O-oaGI-itD2-9LBN-SsvT-IkIt-fzvfGu LV Write Access read/write LV Creation host, time localhost, 2020-04-23 12:36:29 -0400 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID fVY6mC-enqD-pSlK-EYlA-Artm-RJU5-Jn0LzT LV Write Access read/write LV Creation host, time localhost, 2020-04-23 12:36:30 -0400 LV Status available # open 1 LV Size 36.99 GiB Current LE 9470 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
Example 10: How to Remove Logical Volume using lvremove command
In this example, we are trying to remove logical volume /dev/vol_grp/log_vol1
using lvremove /dev/vol_grp/log_vol1
command as shown below.
[root@localhost ~]# lvremove /dev/vol_grp/log_vol1 Do you really want to remove active logical volume vol_grp/log_vol1? [y/n]: y Logical volume "log_vol1" successfully removed
Example 11: How to Extend LVM Partition using lvextend command
In this example, we are trying to extend logical volume /dev/vol_grp/log_grp1
by 200 MB
using lvextend -L +200M /dev/vol_grp/log_grp1
command as shown below.
[root@localhost ~]# lvextend -L +200M /dev/vol_grp/log_grp1 Size of logical volume vol_grp/log_grp1 changed from 200.00 MiB (50 extents) to 400.00 MiB (100 extents). Logical volume vol_grp/log_grp1 successfully resized.
Popular Recommendations:-
How to Compare Strings in Python
How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8
10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)
9 useful w command in Linux with Examples
12 Most Popular rm command in Linux with Examples
Create a Self Signed Certificate using OpenSSL
11 Useful PSSH Command Examples to Perform Parallel SSH in Multiple Linux Servers