Language and Page Formatting Options
4.3. Volume Group Administration
This section describes the commands that perform the various aspects of volume group administration.
4.3.1. Creating Volume Groups
To create a volume group from one or more physical volumes, use the
vgcreatecommand creates a new volume group by name and adds at least one physical volume to it.
The following command creates a volume group named
vg1that contains physical volumes
vgcreate vg1 /dev/sdd1 /dev/sde1
When physical volumes are used to create a volume group, its disk space is divided into 4MB extents, by default. This extent is the minimum amount by which the logical volume may be increased or decreased in size. Large numbers of extents will have no impact on I/O performance of the logical volume.
You can specify the extent size with the
-soption to the
vgcreatecommand if the default extent size is not suitable. You can put limits on the number of physical or logical volumes the volume group can have by using the
-larguments of the
By default, a volume group allocates physical extents according to common-sense rules such as not placing parallel stripes on the same physical volume. This is the
normalallocation policy. You can use the
--allocargument of the
vgcreatecommand to specify an allocation policy of
cling. In general, allocation policies other than
normalare required only in special cases where you need to specify unusual or nonstandard extent allocation. For further information on how LVM allocates physical extents, see Section 4.3.2, “LVM Allocation”.
LVM volume groups and underlying logical volumes are included in the device special file directory tree in the
/devdirectory with the following layout:
For example, if you create two volume groups
myvg2, each with three logical volumes named
lv03, this creates six device special files:
/dev/myvg1/lv01 /dev/myvg1/lv02 /dev/myvg1/lv03 /dev/myvg2/lv01 /dev/myvg2/lv02 /dev/myvg2/lv03
The device special files are not present if the corresponding logical volume is not currently active.
The maximum device size with LVM is 8 Exabytes on 64-bit CPUs.
4.3.2. LVM Allocation
When an LVM operation needs to allocate physical extents for one or more logical volumes, the allocation proceeds as follows:
- The complete set of unallocated physical extents in the volume group is generated for consideration. If you supply any ranges of physical extents at the end of the command line, only unallocated physical extents within those ranges on the specified physical volumes are considered.
- Each allocation policy is tried in turn, starting with the strictest policy (
contiguous) and ending with the allocation policy specified using the
--allocoption or set as the default for the particular logical volume or volume group. For each policy, working from the lowest-numbered logical extent of the empty logical volume space that needs to be filled, as much space as possible is allocated, according to the restrictions imposed by the allocation policy. If more space is needed, LVM moves on to the next policy.
The allocation policy restrictions are as follows:
- An allocation policy of
contiguousrequires that the physical location of any logical extent that is not the first logical extent of a logical volume is adjacent to the physical location of the logical extent immediately preceding it.When a logical volume is striped or mirrored, the
contiguousallocation restriction is applied independently to each stripe or mirror image (leg) that needs space.
- An allocation policy of
clingrequires that the physical volume used for any logical extent be added to an existing logical volume that is already in use by at least one logical extent earlier in that logical volume. If the configuration parameter
allocation/cling_tag_listis defined, then two physical volumes are considered to match if any of the listed tags is present on both physical volumes. This allows groups of physical volumes with similar properties (such as their physical location) to be tagged and treated as equivalent for allocation purposes. For more information on using the
clingpolicy in conjunction with LVM tags to specify which additional physical volumes to use when extending an LVM volume, see Section 4.4.19, “Extending a Logical Volume with the
clingAllocation Policy”.When a Logical Volume is striped or mirrored, the
clingallocation restriction is applied independently to each stripe or mirror image (leg) that needs space.
- An allocation policy of
normalwill not choose a physical extent that shares the same physical volume as a logical extent already allocated to a parallel logical volume (that is, a different stripe or mirror image/leg) at the same offset within that parallel logical volume.When allocating a mirror log at the same time as logical volumes to hold the mirror data, an allocation policy of
normalwill first try to select different physical volumes for the log and the data. If that is not possible and the
allocation/mirror_logs_require_separate_pvsconfiguration parameter is set to 0, it will then allow the log to share physical volume(s) with part of the data.Similarly, when allocating thin pool metadata, an allocation policy of
normalwill follow the same considerations as for allocation of a mirror log, based on the value of the
- If there are sufficient free extents to satisfy an allocation request but a
normalallocation policy would not use them, the
anywhereallocation policy will, even if that reduces performance by placing two stripes on the same physical volume.
The allocation policies can be changed using the
If you rely upon any layout behavior beyond that documented in this section according to the defined allocation policies, you should note that this might change in future versions of the code. For example, if you supply on the command line two empty physical volumes that have an identical number of free physical extents available for allocation, LVM currently considers using each of them in the order they are listed; there is no guarantee that future releases will maintain that property. If it is important to obtain a specific layout for a particular Logical Volume, then you should build it up through a sequence of
lvconvertsteps such that the allocation policies applied to each step leave LVM no discretion over the layout.
To view the way the allocation process currently works in any specific case, you can read the debug logging output, for example by adding the
-vvvvoption to a command.
4.3.3. Creating Volume Groups in a Cluster
You create CLVM volume groups in a cluster environment with the
vgcreatecommand, just as you create them on a single node.
In Red Hat Enterprise Linux 7, clusters are managed through Pacemaker. Clustered LVM logical volumes are supported only in conjunction with Pacemaker clusters, and must be configured as cluster resources. For general information on configuring LVM volumes in a cluster, see Section 1.4, “LVM Logical Volumes in a Red Hat High Availability Cluster”.
Volume groups that are shared by members of the cluster should be created with the clustered attribute set with the
vgchange -cycommand. The clustered attribute is set automatically if if CLVMD is running. This clustered attribute signals that this volume group should be managed and protected by CLVMD. When creating any volume group that is not shared by the cluster and should only be visible to a single host, this clustered attribute should be disabled with the
By default, volume groups created with with the clustered attribute on shared storage are visible to all computers that have access to the shared storage. It is possible, however, to create volume groups that are local, visible only to one node in the cluster, by using the
-cnoption of the
The following command, when executed in a cluster environment, creates a volume group that is local to the node from which the command was executed. The command creates a local volume named
vg1that contains physical volumes
vgcreate -c n vg1 /dev/sdd1 /dev/sde1
You can change whether an existing volume group is local or clustered with the
-coption of the
vgchangecommand, which is described in Section 4.3.9, “Changing the Parameters of a Volume Group”.
You can check whether an existing volume group is a clustered volume group with the
vgscommand, which displays the
cattribute if the volume is clustered. The following command displays the attributes of the volume groups
testvg1. In this example,
VolGroup00is not clustered, while
testvg1is clustered, as indicated by the
cattribute under the
vgsVG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 19.88G 0 testvg1 1 1 0 wz--nc 46.00G 8.00M
4.3.4. Adding Physical Volumes to a Volume Group
To add additional physical volumes to an existing volume group, use the
vgextendcommand increases a volume group's capacity by adding one or more free physical volumes.
The following command adds the physical volume
/dev/sdf1to the volume group
vgextend vg1 /dev/sdf1
4.3.5. Displaying Volume Groups
There are two commands you can use to display properties of LVM volume groups:
vgscancommand, which scans all the disks for volume groups and rebuilds the LVM cache file, also displays the volume groups. For information on the
vgscancommand, see Section 4.3.6, “Scanning Disks for Volume Groups to Build the Cache File”.
vgscommand provides volume group information in a configurable form, displaying one line per volume group. The
vgscommand provides a great deal of format control, and is useful for scripting. For information on using the
vgscommand to customize your output, see Section 4.8, “Customized Reporting for LVM”.
vgdisplaycommand displays volume group properties (such as size, extents, number of physical volumes, and so on) in a fixed form. The following example shows the output of the
vgdisplaycommand for the volume group
new_vg. If you do not specify a volume group, all existing volume groups are displayed.
vgdisplay new_vg--- Volume group --- VG Name new_vg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 51.42 GB PE Size 4.00 MB Total PE 13164 Alloc PE / Size 13 / 52.00 MB Free PE / Size 13151 / 51.37 GB VG UUID jxQJ0a-ZKk0-OpMO-0118-nlwO-wwqd-fD5D32
4.3.6. Scanning Disks for Volume Groups to Build the Cache File
vgscancommand scans all supported disk devices in the system looking for LVM physical volumes and volume groups. This builds the LVM cache file in the
/etc/lvm/cache/.cachefile, which maintains a listing of current LVM devices.
LVM runs the
vgscancommand automatically at system startup and at other times during LVM operation, such as when you execute the
vgcreatecommand or when LVM detects an inconsistency.
You may need to run the
vgscancommand manually when you change your hardware configuration and add or delete a device from a node, causing new devices to be visible to the system that were not present at system bootup. This may be necessary, for example, when you add new disks to the system on a SAN or hotplug a new disk that has been labeled as a physical volume.
You can define a filter in the
/etc/lvm/lvm.conffile to restrict the scan to avoid specific devices. For information on using filters to control which devices are scanned, see Section 4.5, “Controlling LVM Device Scans with Filters”.
The following example shows the output of the
vgscanReading all physical volumes. This may take a while... Found volume group "new_vg" using metadata type lvm2 Found volume group "officevg" using metadata type lvm2
4.3.7. Removing Physical Volumes from a Volume Group
To remove unused physical volumes from a volume group, use the
vgreducecommand shrinks a volume group's capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.
Before removing a physical volume from a volume group, you can make sure that the physical volume is not used by any logical volumes by using the
pvdisplay /dev/hda1-- Physical volume --- PV Name /dev/hda1 VG Name myvg PV Size 1.95 GB / NOT usable 4 MB [LVM: 122 KB] PV# 1 PV Status available Allocatable yes (but full) Cur LV 1 PE Size (KByte) 4096 Total PE 499 Free PE 0 Allocated PE 499 PV UUID Sd44tK-9IRw-SrMC-MOkn-76iP-iftz-OVSen7
If the physical volume is still being used you will have to migrate the data to another physical volume using the
pvmovecommand. Then use the
vgreducecommand to remove the physical volume.
The following command removes the physical volume
/dev/hda1from the volume group
vgreduce my_volume_group /dev/hda1
If a logical volume contains a physical volume that fails, you cannot use that logical volume. To remove missing physical volumes from a volume group, you can use the
--removemissingparameter of the
vgreducecommand, if there are no logical volumes that are allocated on the missing physical volumes.
If the physical volume that fails contains a mirror image of a logical volume of a
mirrorsegment type, you can remove that image from the mirror with the
vgreduce --removemissing --mirrorsonly --forcecommand. This removes only the logical volumes that are mirror images from the physical volume.
For information on recovering from LVM mirror failure, see Section 6.3, “Recovering from LVM Mirror Failure”. For information on removing lost physical volumes from a volume group, see Section 6.6, “Removing Lost Physical Volumes from a Volume Group”
4.3.8. Activating and Deactivating Volume Groups
When you create a volume group it is, by default, activated. This means that the logical volumes in that group are accessible and subject to change.
There are various circumstances for which you need to make a volume group inactive and thus unknown to the kernel. To deactivate or activate a volume group, use the
--available) argument of the
The following example deactivates the volume group
vgchange -a n my_volume_group
If clustered locking is enabled, add ’e’ to activate or deactivate a volume group exclusively on one node or ’l’ to activate or/deactivate a volume group only on the local node. Logical volumes with single-host snapshots are always activated exclusively because they can only be used on one node at once.
You can deactivate individual logical volumes with the
lvchangecommand, as described in Section 4.4.11, “Changing the Parameters of a Logical Volume Group”, For information on activating logical volumes on individual nodes in a cluster, see Section 4.7, “Activating Logical Volumes on Individual Nodes in a Cluster”.
4.3.9. Changing the Parameters of a Volume Group
vgchangecommand is used to deactivate and activate volume groups, as described in Section 4.3.8, “Activating and Deactivating Volume Groups”. You can also use this command to change several volume group parameters for an existing volume group.
The following command changes the maximum number of logical volumes of volume group
vgchange -l 128 /dev/vg00
For a description of the volume group parameters you can change with the
vgchangecommand, see the
vgchange(8) man page.
4.3.10. Removing Volume Groups
To remove a volume group that contains no logical volumes, use the
vgremove officevgVolume group "officevg" successfully removed
4.3.11. Splitting a Volume Group
To split the physical volumes of a volume group and create a new volume group, use the
Logical volumes cannot be split between volume groups. Each existing logical volume must be entirely on the physical volumes forming either the old or the new volume group. If necessary, however, you can use the
pvmovecommand to force the split.
The following example splits the new volume group
smallvgfrom the original volume group
vgsplit bigvg smallvg /dev/ram15Volume group "smallvg" successfully split from "bigvg"
4.3.12. Combining Volume Groups
To combine two volume groups into a single volume group, use the
vgmergecommand. You can merge an inactive "source" volume with an active or an inactive "destination" volume if the physical extent sizes of the volume are equal and the physical and logical volume summaries of both volume groups fit into the destination volume groups limits.
The following command merges the inactive volume group
my_vginto the active or inactive volume group
databasesgiving verbose runtime information.
vgmerge -v databases my_vg
4.3.13. Backing Up Volume Group Metadata
Metadata backups and archives are automatically created on every configuration change to a volume group or logical volume unless disabled in the
lvm.conffile. By default, the metadata backup is stored in the
/etc/lvm/backupfile and the metadata archives are stored in the
/etc/lvm/archivefile. You can manually back up the metadata to the
/etc/lvm/backupfile with the
vgcfgrestorecommand restores the metadata of a volume group from the archive to all the physical volumes in the volume groups.
For an example of using the
vgcfgrestorecommand to recover physical volume metadata, see Section 6.4, “Recovering Physical Volume Metadata”.
4.3.14. Renaming a Volume Group
vgrenamecommand to rename an existing volume group.
Either of the following commands renames the existing volume group
vgrename /dev/vg02 /dev/my_volume_group
vgrename vg02 my_volume_group
4.3.15. Moving a Volume Group to Another System
You can move an entire LVM volume group to another system. It is recommended that you use the
vgimportcommands when you do this.
You can use the
--forceargument of the
vgimportcommand. This allows you to import volume groups that are missing physical volumes and subsequently run the
vgexportcommand makes an inactive volume group inaccessible to the system, which allows you to detach its physical volumes. The
vgimportcommand makes a volume group accessible to a machine again after the
vgexportcommand has made it inactive.
To move a volume group from one system to another, perform the following steps:
- Make sure that no users are accessing files on the active volumes in the volume group, then unmount the logical volumes.
- Use the
-a nargument of the
vgchangecommand to mark the volume group as inactive, which prevents any further activity on the volume group.
- Use the
vgexportcommand to export the volume group. This prevents it from being accessed by the system from which you are removing it.After you export the volume group, the physical volume will show up as being in an exported volume group when you execute the
pvscancommand, as in the following example.
pvscanPV /dev/sda1 is in exported VG myvg [17.15 GB / 7.15 GB free] PV /dev/sdc1 is in exported VG myvg [17.15 GB / 15.15 GB free] PV /dev/sdd1 is in exported VG myvg [17.15 GB / 15.15 GB free] ...When the system is next shut down, you can unplug the disks that constitute the volume group and connect them to the new system.
- When the disks are plugged into the new system, use the
vgimportcommand to import the volume group, making it accessible to the new system.
- Activate the volume group with the
-a yargument of the
- Mount the file system to make it available for use.
4.3.16. Recreating a Volume Group Directory
To recreate a volume group directory and logical volume special files, use the
vgmknodescommand. This command checks the LVM2 special files in the
/devdirectory that are needed for active logical volumes. It creates any special files that are missing and removes unused ones.
You can incorporate the
vgmknodescommand into the
vgscancommand by specifying the
mknodesargument to the