The next step in implementing LVM after creating the physical volumes or PV, is to assign the physical volumes to an existing or new volume group. Below are the most commonly used VG related operation/utilities.
Creating a Volume Group
Use the vgcreate command to create a new volume group. Space in a volume group is divided into “extents.” The default physical extent size is 4 MB. The syntax is:
# vgcreate [options] volume_group_name physical_volume
For example, to create a volume group named vg01 by using the /dev/sdb and /dev/sdc physical volumes with a default physical extent size of 4 MB, enter:
# vgcreate -v vg01 /dev/sdb /dev/sdc Wiping internal VG cache Wiping cache of LVM-capable devices Wiping signatures on new PV /dev/sdb. Wiping signatures on new PV /dev/sdc. Adding physical volume '/dev/sdb' to volume group 'vg01' Adding physical volume '/dev/sdc' to volume group 'vg01' Archiving volume group "vg01" metadata (seqno 0). Creating volume group backup "/etc/lvm/backup/vg01" (seqno 1). Volume group "vg01" successfully created
Displaying Volume Groups
Use the vgdisplay command to display attributes of volume groups:
# vgdisplay vg01 --- Volume group --- VG Name vg01 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 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VG UUID FWwr8K-3HbK-qv2b-kDGv-sGOq-bLa2-2Vyc05
In addition to vgdisplay, two other commands list information about volume groups. The vgs command reports information about volume groups in a more condensed form. The vgscan command scans all disks for volume groups and rebuilds caches. Example:
# vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- 19.00g 0 vg01 2 0 0 wz--n- 39.99g 39.99g
# vgscan Reading volume groups from cache. Found volume group "vg01" using metadata type lvm2 Found volume group "cl" using metadata type lvm2
Removing Volume Groups
Use the vgremove command to remove a volume group, for example:
# vgremove vg01 Volume group "vg01" successfully removed
# vgdisplay vg01 Volume group "vg01" not found Cannot process volume group vg01
Additional VG Commands
The following commands are used to manipulate volume groups:
- vgcfgbackup : Back up volume group configurations.
- vgcfgrestore : Restore volume group configurations.
- vgchange : Change volume group attributes.
- vgck : Check the consistency of volume groups.
- vgconvert : Change the volume group metadata format.
- vgexport : Unregister volume groups from the system.
- vgextend : Add physical volumes to a volume group.
- vgimport : Register an exported volume group with the system.
- vgmerge : Merge volume groups.
- vgmknodes : Create special files for volume group devices in /dev.
- vgreduce : Remove physical volumes from a volume group.
- vgrename : Rename a volume group.
- vgsplit : Move physical volumes into a new or existing volume group.
LVM Configuration : Logical Volume (LV) Operations/Utilities
LVM Configuration : Physical Volume (PV) Operations/Utilities