5.4.14.3. Extending a Logical Volume with the cling Allocation Policy
When extending an LVM volume, you can use the
--alloc cling option of the lvextend command to specify the cling allocation 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.conf file, 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
lvm.conf file:
cling_tag_list = [ "@site1", "@site2" ]
cling_tag_list = [ "@site1", "@site2" ]
For information on tagging physical volumes, see 附录 D, LVM 对象标签.
In the following example, the
lvm.conf file has been modified to contain the following line:
cling_tag_list = [ "@A", "@B" ]
cling_tag_list = [ "@A", "@B" ]
Also in this example, a volume group
taft has been created that consists of the physical volumes /dev/sdb1, /dev/sdc1, /dev/sdd1, /dev/sde1, /dev/sdf1, /dev/sdg1, and /dev/sdh1. These physical volumes have been tagged with tags A, B, and C. The example does not use the C tag, but this will show that LVM uses the tags to select which physical volumes to use for the mirror legs.
The following command creates a 100GB mirrored volume from the volume group
taft.
lvcreate -m 1 -n mirror --nosync -L 100G taft
# lvcreate -m 1 -n mirror --nosync -L 100G taft
The following command shows which devices are used for the mirror legs and mirror log.
The following command extends the size of the mirrored volume, using the
cling allocation policy to indicate that the mirror legs should be extended using physical volumes with the same tag.
lvextend --alloc cling -L +100G taft/mirror
# lvextend --alloc cling -L +100G taft/mirror
Extending 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
C were ignored.