4.3. Volume Group Administration
4.3.1. Creating Volume Groups
vgcreatecommand creates a new volume group by name and adds at least one physical volume to it.
vg1that contains physical volumes
vgcreate vg1 /dev/sdd1 /dev/sde1
-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
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”.
/devdirectory with the following layout:
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
4.3.2. LVM Allocation
- 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.
- 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.
lvconvertsteps such that the allocation policies applied to each step leave LVM no discretion over the layout.
-vvvvoption to a command.
4.3.3. Creating Volume Groups in a Cluster
vgcreatecommand, just as you create them on a single node.
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
-cnoption of the
vg1that contains physical volumes
vgcreate -c n vg1 /dev/sdd1 /dev/sde1
-coption of the
vgchangecommand, which is described in Section 4.3.9, “Changing the Parameters of a Volume Group”.
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
vgextendcommand increases a volume group's capacity by adding one or more free physical volumes.
/dev/sdf1to the volume group
vgextend vg1 /dev/sdf1
4.3.5. Displaying 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.
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.
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.
/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”.
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
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.
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
pvmovecommand. Then use the
vgreducecommand to remove the physical volume.
/dev/hda1from the volume group
vgreduce my_volume_group /dev/hda1
--removemissingparameter of the
vgreducecommand, if there are no logical volumes that are allocated on the missing physical volumes.
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.
4.3.8. Activating and Deactivating Volume Groups
--available) argument of the
vgchange -a n my_volume_group
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.
vgchange -l 128 /dev/vg00
vgchangecommand, see the
vgchange(8) man page.
4.3.10. Removing Volume Groups
vgremove officevgVolume group "officevg" successfully removed
4.3.11. Splitting a Volume Group
pvmovecommand to force the split.
smallvgfrom the original volume group
vgsplit bigvg smallvg /dev/ram15Volume group "smallvg" successfully split from "bigvg"
4.3.12. Combining Volume Groups
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.
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
lvm.conffile. By default, the metadata backup is stored in the
/etc/lvm/backupfile and the metadata archives are stored in the
/etc/lvm/archivesfile. 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.
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.
vgrename /dev/vg02 /dev/my_volume_group
vgrename vg02 my_volume_group
4.3.15. Moving a Volume Group to Another System
vgimportcommands when you do this.
--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.
- 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
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.
vgmknodescommand into the
vgscancommand by specifying the
mknodesargument to the