Show Table of Contents
18.104.22.168. Extending a Logical Volume with the cling Allocation Policy
When extending an LVM volume, you can use the
--alloc clingoption of the
lvextendcommand to specify the
clingallocation policy. This policy will choose space on the same physical volumes as the last segment of the existing logical volume. If there is insufficient space on the physical volumes and a list of tags is defined in the
lvm.conffile, LVM will check whether any of the tags are attached to the physical volumes and seek to match those physical volume tags between existing extents and new extents.
For example, if you have logical volumes that are mirrored between two sites within a single volume group, you can tag the physical volumes according to where they are situated by tagging the physical volumes with @site1 and @site2 tags and specify the following line in the
cling_tag_list = [ "@site1", "@site2" ]
For information on tagging physical volumes, see Appendix D, LVM Object Tags.
In the following example, the
lvm.conffile has been modified to contain the following line:
cling_tag_list = [ "@A", "@B" ]
Also in this example, a volume group
tafthas been created that consists of the physical volumes
/dev/sdh1. These physical volumes have been tagged with tags
C. The example does not use the
Ctag, but this will show that LVM uses the tags to select which physical volumes to use for the mirror legs.
pvs -a -o +pv_tags /dev/sd[bcdefgh]1PV VG Fmt Attr PSize PFree PV Tags /dev/sdb1 taft lvm2 a- 135.66g 135.66g A /dev/sdc1 taft lvm2 a- 135.66g 135.66g B /dev/sdd1 taft lvm2 a- 135.66g 135.66g B /dev/sde1 taft lvm2 a- 135.66g 135.66g C /dev/sdf1 taft lvm2 a- 135.66g 135.66g C /dev/sdg1 taft lvm2 a- 135.66g 135.66g A /dev/sdh1 taft lvm2 a- 135.66g 135.66g A
The following command creates a 100GB mirrored volume from the volume group
lvcreate -m 1 -n mirror --nosync -L 100G taft
The following command shows which devices are used for the mirror legs and mirror log.
lvs -a -o +devicesLV VG Attr LSize Log Copy% Devices mirror taft Mwi-a- 100.00g mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0) [mirror_mimage_0] taft iwi-ao 100.00g /dev/sdb1(0) [mirror_mimage_1] taft iwi-ao 100.00g /dev/sdc1(0) [mirror_mlog] taft lwi-ao 4.00m /dev/sdh1(0)
The following command extends the size of the mirrored volume, using the
clingallocation policy to indicate that the mirror legs should be extended using physical volumes with the same tag.
lvextend --alloc cling -L +100G taft/mirrorExtending 2 mirror images. Extending logical volume mirror to 200.00 GiB Logical volume mirror successfully resized
The following display command shows that the mirror legs have been extended using physical volumes with the same tag as the leg. Note that the physical volumes with a tag of
lvs -a -o +devicesLV VG Attr LSize Log Copy% Devices mirror taft Mwi-a- 200.00g mirror_mlog 50.16 mirror_mimage_0(0),mirror_mimage_1(0) [mirror_mimage_0] taft Iwi-ao 200.00g /dev/sdb1(0) [mirror_mimage_0] taft Iwi-ao 200.00g /dev/sdg1(0) [mirror_mimage_1] taft Iwi-ao 200.00g /dev/sdc1(0) [mirror_mimage_1] taft Iwi-ao 200.00g /dev/sdd1(0) [mirror_mlog] taft lwi-ao 4.00m /dev/sdh1(0)