Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 11. Controlling LVM allocation
By default, a volume group uses the normal allocation policy which avoids placing parallel stripes on the same physical volume. You can change it to contiguous, anywhere, or cling by using vgcreate with the --alloc option. Other policies are needed only for special extent allocation cases.
11.1. Allocating extents from specified devices Link kopierenLink in die Zwischenablage kopiert!
You can restrict the allocation from specific devices by using the device arguments at the end of the command line with the lvcreate and the lvconvert commands. You can specify the actual extent ranges for each device for more control. The command only allocates extents for the new logical volume (LV) by using the specified physical volume (PV) as arguments. It takes available extents from each PV until they run out and then takes extents from the next PV listed. If there is not enough space on all the listed PVs for the requested LV size, then command fails. Note that the command only allocates from the named PVs. Raid LVs use sequential PVs for separate raid images or separate stripes. If the PVs are not large enough for an entire raid image, then the resulting device use is not entirely predictable.
Procedure
Create a volume group (VG):
# vgcreate <vg_name> <PV> ...Where:
-
<vg_name>is the name of the VG. -
<PV>are the PVs.
-
You can allocate PV to create different volume types, such as linear or raid:
Allocate extents to create a linear volume:
# lvcreate -n <lv_name> -L <lv_size> <vg_name> [ <PV> ... ]Where:
-
<lv_name>is the name of the LV. -
<lv_size>is the size of the LV. Default unit is megabytes. -
<vg_name>is the name of the VG. [ <PV …> ]are the PVs.You can specify one of the PVs, all of them, or none on the command line:
If you specify one PV, extents for that LV will be allocated from it.
NoteIf the PV does not have sufficient free extents for the entire LV, then the
lvcreatefails.- If you specify two PVs, extents for that LV will be allocated from one of them, or a combination of both.
If you do not specify any PV, extents will be allocated from one of the PVs in the VG, or any combination of all PVs in the VG.
NoteIn these cases, LVM might not use all of the named or available PVs. If the first PV has sufficient free extents for the entire LV, then the other PV will probably not be used. However, if the first PV does not have a set allocation size of free extents, then LV might be allocated partly from the first PV and partly from the second PV.
In this example,
lv1extents will be allocated fromsda:# lvcreate -n lv1 -L1G vg /dev/sdaIn this example,
lv2extents will be allocated from eithersda, orsdb, or a combination of both:# lvcreate -n lv2 -L1G vg /dev/sda /dev/sdbIn this example,
lv3extents will be allocated from one of the PVs in the VG, or any combination of all PVs in the VG:# lvcreate -n lv3 -L1G vg
-
Allocate extents to create a raid volume:
# lvcreate --type <segment_type> -m <mirror_images> -n <lv_name> -L <lv_size> <vg_name> [ <PV> ... ]Where:
-
<segment_type>is the specified segment type (for exampleraid5,mirror,snapshot). -
<mirror_images>creates araid1or a mirrored LV with the specified number of images. For example,-m 1would result in araid1LV with two images. -
<lv_name>is the name of the LV. -
<lv_size>is the size of the LV. Default unit is megabytes. -
<vg_name>is the name of the VG. <[PV …]>are the PVs.The first raid image will be allocated from the first PV, the second raid image from the second PV, and so on.
In this example,
lv4first raid image will be allocated fromsdaand second image will be allocated fromsdb:# lvcreate --type raid1 -m 1 -n lv4 -L1G vg /dev/sda /dev/sdbIn this example,
lv5first raid image will be allocated fromsda, second image will be allocated fromsdb, and third image will be allocated fromsdc:# lvcreate --type raid1 -m 2 -n lv5 -L1G vg /dev/sda /dev/sdb /dev/sdc
-
11.2. LVM allocation policies Link kopierenLink in die Zwischenablage kopiert!
LVM allocation policies control how physical extents are assigned to logical volumes using contiguous, cling, normal, and anywhere strategies.
When an LVM operation must allocate physical extents for one or more logical volumes (LVs), 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 are considered. These ranges apply only to the specified physical volumes (PVs).
-
Each allocation policy is tried in turn, starting with the strictest policy (
contiguous). The process ends with the policy specified using--allocor the default for the particular LV or volume group (VG). For each policy, working from the lowest-numbered logical extent of the empty LV space, as much space as possible is allocated. This is done in accordance with policy restrictions. If more space is needed, LVM moves on to the next policy.
The allocation policy restrictions are as follows:
The
contiguouspolicy requires each logical extent to be physically adjacent to the immediately preceding logical extent. The first logical extent of a logical volume (LV) is an exception.When an LV is striped or mirrored, the
contiguousrestriction is applied independently to each stripe or raid image that needs space.-
The
clingpolicy requires that the PV used for any logical extent be added to an existing LV. The PV must already be used by at least one earlier logical extent in that LV. -
An allocation policy of
normaldoes not choose a physical extent on the same PV as one used by a parallel LV. This applies when both extents are at the same offset in different stripes or RAID images. -
If sufficient free extents exist but a
normalpolicy would not use them, theanywherepolicy will. This may reduce performance by placing two stripes on the same PV.
You can change the allocation policy by using the vgchange command.
Future updates can bring code changes in layout behavior according to the defined allocation policies. For example, if you supply two empty physical volumes with identical free physical extents, LVM currently uses them in the listed order. However, future releases might not maintain this behaviour. If you need a specific LV layout, build it through a sequence of lvcreate and lvconvert steps. Structure them so that the allocation policies applied to each step leave LVM no discretion over the layout.
11.3. Preventing allocation on a physical volume Link kopierenLink in die Zwischenablage kopiert!
You can prevent allocation of physical extents on the free space of one or more physical volumes with the pvchange command. This might be necessary if there are disk errors, or if you will be removing the physical volume.
Procedure
Use the following command to disallow the allocation of physical extents on
device_name:# pvchange -x n /dev/sdk1You can also allow allocation where it had previously been disallowed by using the
-xyarguments of thepvchangecommand.