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 512kpartx -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.
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 onblockdev --getss