LVM Volume Groups
A volume group is an abstraction layer between block devices and logical volumes.
The commands used to manage a volume group start with vg:
vgcfgbackup vgcfgrestore vgchange vgck vgconvert vgcreate vgdisplay vgexport vgextend vgimport vgimportclone vgmerge vgmknodes vgreduce vgremove vgrename vgs vgscan vgsplit
vgcreate
Use the vgcreate command to create a volume group. You can immediately name all the physical volumes that span the volume group
# vgcreate vg33 /dev/sde /dev/sdf Volume group "vg33" successfully created
vgextend
Use the vgextend command to extend an existing volume group with a physical volume:
# vgextend vg33 /dev/sdg Volume group "vg42" successfully extended
vgremove
Use the vgremove command to remove volume groups from lvm. The volume groups may not be in use:
# vgremove vg33 Volume group "vg33" successfully removed
vgreduce
Use the vgreduce command to remove a Physical Volume from the Volume Group.
The following example adds Physical Volume /dev/sdg to the vg33 Volume Group using vgextend. And then removes it again using vgreduce.
# pvs | grep sdg /dev/sdg lvm2 -- 819.20M 819.20M # vgextend vg33 /dev/sdg Volume group "vg33" successfully extended # pvs | grep sdg /dev/sdg vg1 lvm2 a- 816.00M 816.00M # vgreduce vg33 /dev/sdg Removed "/dev/sdg" from volume group "vg33" # pvs | grep sdg /dev/sdg lvm2 -- 819.20M 819.20M
vgchange
Use the vgchange command to change parameters of a Volume Group.
This example shows how to prevent Physical Volumes from being added or removed to the Volume Group vg33
.
# vgchange -xn vg33 Volume group "vg33" successfully changed # vgextend vg33 /dev/sdg Volume group vg33 is not resizable.
You can also use vgchange to change most other properties of a Volume Group. This example changes the maximum number of Logical Volumes and maximum number of Physical Volumes that vg33 can serve:
# vgdisplay vg33 | grep -i max MAX LV 0 Max PV 0 # vgchange -l16 vg33 Volume group "vg33" successfully changed # vgchange -p8 vg33 Volume group "vg33" successfully changed # vgdisplay vg33 | grep -i max MAX LV 16 Max PV 8
vgmerge
Merging two Volume Groups into one is done with vgmerge. The following example merges vg33 into vg32, keeping all the properties of vg32:
# vgmerge vg32 vg33 Volume group "vg33" successfully merged into "vg32"
vgs
Similar to pvs
is the use of vgs
to display a quick overview of all volume groups.
# vgs VG #PV #LV #SN Attr VSize VFree vg30 1 2 0 wz--n- 15.88G 0
There is only one volume group in the screenshot below, it is named vg30 and is almost 16GB in size.
vgscan
The vgscan
command will scan all disks for existing Volume Groups. It will also update the /etc/lvm/.cache
file. This file contains a list of all current lvm devices.
# vgscan Reading all physical volumes. This may take a while... Found volume group "vg30" using metadata type lvm2
LVM will run the vgscan
automatically at boot-up, so if you add hot swap devices, then you will need to run vgscan
to update /etc/lvm/.cache
with the new devices.
vgdisplay
The vgdisplay
command will give you more detailed information about a volume group (or about all volume groups if you omit the argument).
# vgdisplay vg30 --- Volume group --- VG Name vg30 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 15.88 GB PE Size 32.00 MB Total PE 508 Alloc PE / Size 508 / 15.88 GB Free PE / Size 0 / 0 VG UUID 2bb9351c-d23e-479d-9818-eb2771cc10ce