Este conteúdo não está disponível no idioma selecionado.

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

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

  1. Create a volume group (VG):

    # vgcreate <vg_name> <PV> ...

    Where:

    • <vg_name> is the name of the VG.
    • <PV> are the PVs.
  2. You can allocate PV to create different volume types, such as linear or raid:

    1. 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.

          Note

          If the PV does not have sufficient free extents for the entire LV, then the lvcreate fails.

        • 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.

          Note

          In 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, lv1 extents will be allocated from sda:

          # lvcreate -n lv1 -L1G vg /dev/sda

          In this example, lv2 extents will be allocated from either sda, or sdb, or a combination of both:

          # lvcreate -n lv2 -L1G vg /dev/sda /dev/sdb

          In this example, lv3 extents 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
    2. 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 example raid5, mirror, snapshot).
      • <mirror_images> creates a raid1 or a mirrored LV with the specified number of images. For example, -m 1 would result in a raid1 LV 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, lv4 first raid image will be allocated from sda and second image will be allocated from sdb:

        # lvcreate --type raid1 -m 1 -n lv4 -L1G vg /dev/sda /dev/sdb

        In this example, lv5 first raid image will be allocated from sda, second image will be allocated from sdb, and third image will be allocated from sdc:

        # lvcreate --type raid1 -m 2 -n lv5 -L1G vg /dev/sda /dev/sdb /dev/sdc

11.2. LVM allocation policies

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 --alloc or 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 contiguous policy 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 contiguous restriction is applied independently to each stripe or raid image that needs space.

  • The cling policy 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 normal does 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 normal policy would not use them, the anywhere policy will. This may reduce performance by placing two stripes on the same PV.

You can change the allocation policy by using the vgchange command.

Note

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

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/sdk1

    You can also allow allocation where it had previously been disallowed by using the -xy arguments of the pvchange command.

Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat
Voltar ao topo