Valid physical block size combinations of LVM physical volumes

Before migrating data from an unencrypted volume to an encrypted LVM logical volume, check the physical block sizes of the involved volumes to ensure that you use only allowed block size combinations to avoid file system corruption and data loss. New LVM versions perform this check and reject actions that may corrupt the data.

If in your migration scenario the physical block size of a target physical volume (PV) is larger than the physical block size of the source PV, the file systems residing on logical volumes backed by the source PV may become corrupted. This is because the file system is aligned to the physical block size of the source PV and cannot be mapped to a larger block size. Therefore, never use a target volume with a larger block size than your source volumes.

The --sector-size parameter of a dm-crypt volume influences the physical block size. A dm-crypt volume encrypted with a sector size larger than the default 512 bytes results in a device with a physical block size of either the used sector size or the block size of the underlying device, whatever is higher.

This is the case for LUKS2 as well as for a plain mode dm-crypt volume. LUKS1 only supports the default block size of 512 bytes.

Migrating data from an unencrypted PV onto a dm-crypt encrypted PV might thus corrupt the file systems on the logical volumes backed by the source PV if the target dm-crypt volume uses a sector size of 4096 bytes, and the unencrypted source PV uses a physical block size of 512 bytes.

To query the physical block size of a device, use the following command:

# blockdev --getpbsz <device>

If the file systems on the affected LVs were created with a 4096 block size, then the problem does not occur. The file system may choose different block sizes based on various parameters. Thus, on larger volumes, it is very likely that the file system block size is 4096 by default.

Table 1 shows combinations of source and target physical volumes where migration can be performed. Table 2 shows combinations of source and target physical volumes where migration might corrupt the data on the source volumes.
Note: The tables offer a selection of possible combinations. There might be numerous other combinations available in your environment. The general rule is that you should never extend an existing LVM volume group with a device that has a larger physical block size than the existing physical volumes of the volume group.
Table 1. Allowed combinations

Allowed combinations of physical block sizes

Source physical volume Target physical volume
Comparison of block sizes
physical block size = n (for example, n = 4096) physical block size = n (for example, n = 4096)
physical block size = n physical block size < n
Comparison of block sizes on source PV and sector sizes on target dm-crypt volume
physical block size = 512 dm-crypt volume with sector-size = 512 (default)
physical block size = 4096 dm-crypt volume with sector-size = 512 (default)
physical block size = 4096 dm-crypt volume with sector-size = 4096
Comparison of block sizes of specific device types (selection)
SCSI-disk, SCSI-partition, SCSI-multipath-device with block size = 512 dm-crypt volume with sector-size = 512 (default)
DASD-partition (4096) dm-crypt volume with sector-size = 512 (default)
DASD-partition (4096) dm-crypt volume with sector-size = 4096
Loopback-device (512) dm-crypt volume with sector-size = 512 (default)
Other device mapper device (512) dm-crypt volume with sector-size = 512 (default)
Other device mapper device with physical block size > 512 dm-crypt volume with sector-size = 512 (default)
Table 2. Combinations of physical block sizes that might lead to data corruption

Combinations of physical block sizes that might lead to data corruption

Source physical volume Target physical volume
physical block size = n (for example, n = 512) physical block size > n (for example, 4096)
physical block size = 512 dm-crypt volume with sector-size = 4096
SCSI-disk, SCSI-partition, SCSI-multipath-device with block size = 512 dm-crypt volume with sector-size = 4096
Loopback-device (512) dm-crypt volume with sector-size = 4096
Other device mapper device with physical block size 512 < n < 4096 dm-crypt volume with sector-size = 4096