Error "Devices have inconsistent logical block sizes" when handling Vgextend failure

Explain the reason why vgextend reports Devices have inconsistent logical block sizes, and provide checking disk sector size, LVM planning and alternative solutions.

Reasons why Devices have inconsistent logical block sizes appear

The problem is that the logical block size of the disk newly added to Vgextend is different from the logical block size of the original disk in VG. For example, if the original VG is built on a disk device with a logical block size of 512, but the newly added device during Vgextend is a logical block size of 4K, this problem will occur.

Solution 1: Enable allow_mixed_block_sizes=1 in lvm.conf

Open the /etc/lvm/lvm.conf file and modify allow_mixed_block_sizes=1

But this way, is it safe to mix block sizes on the same LV? https://serverfault.com/questions/1150643/is-it-safe-to-use-allow-mixed-block-sizes-1-in-lvm-when-using-ext4-with-4k-blo

Solution 2: Modify the logical block sizes of some hard drives to make all hard drives consistent

Check the logical block sizes of the hard disk

lsblk

1
2
3
4
5
6
7
$ lsblk -td
NAME    ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED       RQ-SIZE  RA WSAME
sda             0   8192   8192    4096     512    0 mq-deadline     256 128    0B
sdb             0   4096      0    4096     512    0 mq-deadline     256 128    0B
sdc             0   4096      0    4096     512    1 mq-deadline     256 128    0B
nvme1n1         0    512      0     512     512    0 none           1023 128    0B
nvme0n1         0    512      0     512     512    0 none           1023 128    0B

PHY-SEC shows the physical sector size and LOG-SEC shows the logical sector size.

sysfs

1
2
3
4
$ cat /sys/class/block/sda/queue/physical_block_size
4096
$ cat /sys/class/block/sda/queue/logical_block_size
512

sda is the device name

fdisk

1
2
3
4
5
6
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 745.22 GiB, 800176914432 bytes, 1562845536 sectors
Disk model: P1635N08CLAR800 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 8192 bytes / 8192 bytes

Sector size physical shows the physical sector size and Sector size logical shows the logical sector size.

smartctl

1
2
3
4
5
6
7
$ sudo smartctl -a /dev/nvme0n1
...
Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
 0 +     512       0         2
 1 -    4096       0         1
...

View Supported LBA Sizes, supported LBA, + section is the currently selected LBA Size

Modify Modify sector LBA size

Warning: Changing the sector size of a hard disk will irrecoverably erase all data.

Some NVMe and “enterprise” SATA drives support modifying their reported sector sizes via standard NVMe (Format NVM for NVMe Command Set Standard 1.0 or above) or ATA (SET SECTOR CONFIGURATION EXT for ATA Command Set Standard 1.0 or above) respectively. For mechanical hard disks, this operation optimizes hard disk performance by modifying their logical sector size to be consistent with the physical sector size. For NVMe SSDs, both logical and physical sector sizes are changed.

SATA SSDs generally do not support modifying the sector size. Some Intel SATA SSDs can only modify the reported physical sector size, but not the logical sector size. Modifying the sector size involves a series of complex operations, including low-level formatting. As an alternative, you can optimize performance by manually specifying the sector size when creating the file system on the hard drive.

Modify mechanical hard drive

Use the hdparm tool to determine whether the hard drive’s sector size can be changed:

Hard drives that do not support modifying the logical sector size will only report the current sector size.

1
2
3
4
$ sudo hdparm -I /dev/sda | grep 'Sector size:'
        Logical/Physical Sector size:           512 bytes
$ sudo hdparm -I /dev/sdb | grep 'Sector size:'
        Logical/Physical Sector size:           512 bytes

Supports hard disk modification of logical sector size

1
2
3
4
5
6
$ sudo hdparm -I /dev/sdc | grep 'Sector size:'
        Logical  Sector size:                   512 bytes [ Supported: 2048 256 ]
        Physical Sector size:                  4096 bytes
$ sudo hdparm -I /dev/sdk | grep 'Sector size:'
        Logical  Sector size:                   512 bytes [ Supported: 2048 256 ]
        Physical Sector size:                  4096 bytes
Use the hdparm tool to modify the sector size of the mechanical hard disk

If your SATA mechanical hard drive supports multiple logical sector sizes and the optional SET SECTOR CONFIGURATION EXT ATA command (for example, Seagate promotes hard drives with FastFormat functionality), you can use hdparm to switch between the different supported logical sector sizes. This can be set to 4096 bytes (i.e. 4Kn) using the following command:

1
# hdparm --set-sector-size 4096 --please-destroy-my-drive /dev/sdX

After the modification hdparm should report a logical sector size of 4096 bytes:

1
2
3
# hdparm -I /dev/sdX | grep 'Sector size:'
        Logical  Sector size:                  4096 bytes [ Supported: 512 4096 ]
        Physical Sector size:                  4096 bytes

Modify NVMe SSD

Although solid-state drives (SSDs) often use larger physical blocks (usually 4 KiB, 8 KiB, and sometimes larger), they typically report their logical block size as 512 bytes. You can use the Identify Namespace command through the nvme-cli package to view the formatted logical block address size (FLBAS) of the NVMe hard drive:

1
2
3
$ sudo nvme id-ns -H /dev/nvme0n1 | grep "Relative Performance"
LBA Format  0 : Metadata Size: 0   bytes - Data Size: 512 bytes - Relative Performance: 0x2 Good (in use)
LBA Format  1 : Metadata Size: 0   bytes - Data Size: 4096 bytes - Relative Performance: 0x1 Better 

Metadata Size is the size of additional metadata bytes per logical block address (Logical Block Address, LBA). This feature is not yet fully supported on Linux, so it is best to use a format with a value of 0. Relative Performance represents the performance level provided by various formats (including degraded, good, better and best).

smartctl can also display the logical block address size supported by the device

1
2
3
4
5
6
# smartctl -c /dev/nvme0n1
...
Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
 0 +     512       0         2
 1 -    4096       0         1

The logical block address size can be modified by passing a target value to the nvme format command using the –lbaf parameter:

1
2
3
4
5
6
7
8
# nvme format --lbaf=1 /dev/nvme0n1
You are about to format nvme0n1, namespace 0x1.
WARNING: Format may irrevocably delete this device's data.
You have 10 seconds to press Ctrl-C to cancel this operation.

Use the force [--force] option to suppress this warning.
Sending format operation ... 
Success formatting namespace:1

lbaf corresponds to the id value, and the modification takes a few seconds to complete.

记录并分享
Built with Hugo
Theme Stack designed by Jimmy