0

What I did

  • Use the graphical installer of Debian buster to create the following partitions on one hard drive.
primary partition /boot
primary partition (for lvm)
  • Create one volume group G.
  • Create logical volume X in volume group G.
  • Create logical volume Y in volume group G.
  • Create logical volume Z in volume group G.

X, Y, Z are not the actual names of the logical volumes.

Surprise

When I create the logical volumes with the menus of the installer, the installer would list the logical volumes that I created.

Somehow in the list, the ordering of X, Y, and Z is scrambled. I expect to see X first, then Y, then Z. But in the list, I might see another ordering (something like Y, X, Z).

My expectation

I expect that the ordering of the physical locations of X, Y, and Z (on the hard drive) is same as the order that I create them:

Order of creation: X, Y, Z
Expected order of physical location on hard drive:
    +---+---+---+
    | X | Y | Z |
    +---+---+---+
    There is no gap between X and Y and no gap between Y and Z.

Question

Will I get what I want?

3
  • They're logical volumes. Why does it matter what order they're created? Mar 17, 2021 at 23:00
  • 1
    "I expect that the ordering of the physical locations of X, Y, and Z ... is same as the order that I create them:" that's an incorrect expectation. They're logical volumes so you should have no expectation that the physical allocation has any bearing on the logical ordering Mar 17, 2021 at 23:02
  • 1
    Does it show them scrambled, or in alphabetical order?
    – ilkkachu
    Mar 18, 2021 at 7:22

1 Answer 1

3

Logical volumes are not partitions, their order is not important. Actually, there is nothing like "order" with LVs. You can have multiple physical volumes in the volume group and LVs allocated on multiple PVs and even with one PV LVs can be allocated in multiple "segments" -- e.g. you can get something like x1 | y1 | x2 | y2 written on the disk. (This doesn't normally happen, but it's possible to create LVs like that. That's why they are called logical volumes, you don't really care about their physical allocation.)

LVM tools like lvs print logical volumes in alphabetical order:

$ sudo lvs test
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  a    test -wi-a----- 12,00m                                                    
  b    test -wi-a----- 12,00m

if you want to see where are the LVs really allocated, you can use pvdisplay -m

  --- Physical Segments ---
  Physical extent 0 to 2:
    Logical volume      /dev/test/b
    Logical extents     0 to 2
  Physical extent 3 to 5:
    Logical volume      /dev/test/a
    Logical extents     0 to 2
  Physical extent 6 to 24:
    FREE

In this example you can see that LV b is allocated on the first three physical extents and a is "second".

I'm not sure how Debian installer works internally, but if you want for some reason be sure that certain LVs are allocated in a specific way (maybe on a specific PV), you can create them manually first and tell the installer to reuse existing LVs. You can select both specific PV and extent ranges when creating LVs using lvcreate (see lvcreate man page) but if you are not trying to do something special, you don't need to care about this. Just trust LVM, it will allocate the LVs in some logical way.

1
  • 1
    I'm pretty sure if you create LVs on a new empty VG and PV, with the default settings, they will end up on the disk in the order they were created. Conceptually, that shouldn't matter, but the LVs do have physical locations on the disk and if there's no fragmentation, an unambiguous order. On spinning disks, the performance characteristics depend partly on the location so it's not like it's totally without real-world effects either, though how significant that is, and if one often cares is a different matter.
    – ilkkachu
    Mar 18, 2021 at 7:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .