0

This seems to be a problem regarding the sector size of the mapped device for a logical volume between different machines.

More specifically, I'd like to know if and how the sector size of a mapped device corresponding to a logical volume can be configured.

Here is a description of the problem, comparing two machines.

Machine 1

I have an entire disk image in a logical volume mytestlv in a volume group named MyVolumeGroup.

This disk image has its own partition table (completely independent of the actual disk it's stored on).

For example, fdisk /dev/mapper/MyVolumeGroup-mytestlv shows this:

Disk /dev/mapper/MyVolumeGroup-mytestlv: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: ...

Device                                    Start      End  Sectors Size Type
/dev/mapper/MyVolumeGroup-mytestlv-part1    2048     4095     2048   1M BIOS boot
/dev/mapper/MyVolumeGroup-mytestlv-part2    4096  4198399  4194304   2G Linux swap
/dev/mapper/MyVolumeGroup-mytestlv-part3 4198400 62914526 58716127  28G Linux filesystem

If I need access to the data on a partition of that disk image, I can use kpartx and mount the partition.

kpartx -a /dev/mapper/MyVolumeGroup-mytestlv creates these devices files, which can be used to mount a partition within that disk image, for example:

/dev/mapper/MyVolumeGroup-mytestlvl
/dev/mapper/MyVolumeGroup-mytestlv2
/dev/mapper/MyVolumeGroup-mytestlv3

Machine 2

This was now copied onto a different machine (content is exactly the same, checksums of both entire /dev/mapper/MyVolumeGroup-mytestlv are identical).

Using the configured block size, fdisk /dev/mapper/MyVolumeGroup-mytestlv shows this:

/dev/mapper/MyVolumeGroup-mytestlv: 30 GiB, 32212254720 bytes, 7864320 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device                                  Boot Start     End Sectors Size Id Type
/dev/mapper/MyVolumeGroup-mytestlv-part1          1 7864319 7864319  30G ee GPT

Differences

The logical sector size is 512 on Machine 1, but 4096 on Machine 2.

On Machine 1, blockdev --getss /dev/mapper/MyVolumeGroup-mytestlv returns 512.

On Machine 2, blockdev --getss /dev/mapper/MyVolumeGroup-mytestlv returns 4096.

Workaround

On Machine 2, forcing the sector size to 512 with fdisk helps it see the partition table correctly.

fdisk --sector-size 512 /dev/mapper/MyVolumeGroup-mytestlv
Disk /dev/mapper/MyVolumeGroup-mytestlv: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: ...

Device                                    Start      End  Sectors Size Type
/dev/mapper/MyVolumeGroup-mytestlv-part1    2048     4095     2048   1M BIOS boot
/dev/mapper/MyVolumeGroup-mytestlv-part2    4096  4198399  4194304   2G Linux swap
/dev/mapper/MyVolumeGroup-mytestlv-part3 4198400 62914526 58716127  28G Linux filesystem

Unfortunately, other tools such as sfdisk or kpartx don't seem to have those options.

If I create a loopback device explicitly from that LV, then that loopback device has a sector size of 512, and everything works (in fact, versions of losetup that are not too old have an explicit sector size option). After losetup --show -f /dev/mapper/MyVolumeGroup-mytestlv:

  • blockdev --getss /dev/loop0 returns 512
  • kpartx -a /dev/loop0 creates /dev/mapper/loop0p{1,2,3}

Where is that sector size configured?

I'd like to be able to use fdisk, sfdisk, kpartx without relying on an additional losetup.

On Machine 2, cat /sys/block/dm-2/queue/hw_sector_size returns 4096 (/dev/mapper/MyVolumeGroup-mytestlv is actually a soft-link to /dev/dm-2). I've tried to change this using echo 512 > /sys/block/dm-2/queue/hw_sector_size, but this doesn't seem to be possible.

  • Is there a way to tell LVM that I'd like the sector size for the device corresponding to /dev/mapper/MyVolumeGroup-mytestlv to be 512?

  • Is that something that affects all the logical volumes in the group or on the system?

I can't see any options with lvcreate or lvdisplay related to this.

2
  • Did you try lvchange -r ?
    – admstg
    Jun 7 at 12:36
  • @admstg I've just tried lvchange -r 512 /dev/mapper/MyVolumeGroup-mytestlv. It says: "Command on LV MyVolumeGroup/mytestlv uses options that are invalid with LV properties: lv_is_thick_origin. Command not permitted on LV MyVolumeGroup/mytestlv.". No change on blockdev --getss
    – Bruno
    Jun 7 at 12:43

1 Answer 1

1

The default sector size comes from the underlying hardware, as far as I've understood it.

So on Machine 1, the underlying disks is/are apparently in Advanced Format 512e mode, probably because Machine 1's disk controller is not capable of using 4k sectors natively. Another possibility is that on Machine 1, one of the physical volumes of MyVolumeGroup cannot support 4k sector size, and so the entire volume group must use the sector size that its least capable disk can support.

On the other hand, Machine 2 and all the physical volumes of its MyVolumeGroup seem to be fully capable of using 4k sector size natively (Advanced Format 4Kn). It defaults to doing so because that is way more efficient than emulating the old 512-byte sector size.

You must log in to answer this question.

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