1

I have a disk under a Logical Volume.

$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_prod/lv_prod
  LV Name                lv_prod
  VG Name                vg_prod
  LV UUID                mXj3Qv-t0GK-4idW-mRBA-17Nb-PSPK-Roulf3
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                <3.64 TiB
  Current LE             953797
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

Now, I want to add a new disk to extend the volume. The disk is attached through the USB interface.

$ fdisk -l /dev/sdg
Disk /dev/sdg: 3.65 TiB, 4000752599040 bytes, 7813969920 sectors
Disk model: Game Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

When I try to add it to extend the volume, I get the error.

$ vgextend vg_prod /dev/sdg
Devices have inconsistent logical block sizes (4096 and 512).

So I started to change the logical sector size for /dev/sdg to 4096.

$ fdisk -b 4096 /dev/sdg

When I print the partition table in fdisk, I do see the logical sector size as 4096.

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xf4a7867a.

Command (m for help): p
Disk /dev/sdg: 3.65 TiB, 4000752599040 bytes, 976746240 sectors
Disk model: Game Drive
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: 0xf4a7867a

When I create a partition, write changes, and list. It goes back to showing 512 as logical sector size.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (256-976746239, default 256):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (256-976746239, default 976746239):

Created a new partition 1 of type 'Linux' and of size 3.7 TiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo fdisk -l /dev/sdg

Disk /dev/sdg: 3.65 TiB, 4000752599040 bytes, 7813969920 sectors
Disk model: Game Drive
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: dos
Disk identifier: 0xf4a7867a

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdg1         256 976746239 976745984 465.8G 83 Linux

Is there a way to change my disk to have logical sector size 4096 so I could add it to the existing storage that I already have?

  • Don’t use the disk in this USB enclosure. There is no other way. – Daniel B Jul 15 '21 at 12:26
  • That's not exactly true. You can "emulate" a different logical block size by using `losetup` (e.g. `losetup -P -b 4096 -f /dev/sdg`). It's pretty much like using an enclosure that does the same thing. However, it's a bit tricky to use. For example, you'll need to use GPT so that the PV is not found by the system repeatedly. You'll also need to write a systemd service or udev rule to run the `losetup` command. (Things would be even more complicated if you need it ready before switching/mounting root from the initramfs.) You'll also need to use e.g. symlink in `/dev/disk/by-id/` for the command. – Tom Yan Jul 15 '21 at 12:58
  • As far as I know, there's rarely a way for you to change the logical block size of a SATA drive. However, if it's an NVMe SSD (unlikely the case for this drive I guess), it's likely you can use `nvme format` to change it. What `fdisk` does is the same as `losetup`, just in an even more temporary way. – Tom Yan Jul 15 '21 at 13:01
  • Also see https://sourceware.org/git/?p=lvm2.git;a=blob;f=conf/example.conf.in;h=b4a55ae6af9393944bd47a3a73dddcb6f780a1ec;hb=01b05cf51dd547354b4ad70e7f8f4ff7ff0bb152#l383. It does NOT sound like you can use PVs of different logical block size for the same LV though; it just allow you to put then into one VG for...whatever reasons. – Tom Yan Jul 15 '21 at 13:05
  • So I am not an expert so I believe a better and easier solution is to use some other hard drive that interfaces through a non-USB port? Should I be looking for specific specs when purchasing a new hard drive? – Muhammad Tauseef Jul 15 '21 at 13:36

1 Answers1

0

It seems you can set allow_mixed_block_sizes = 1 in lvm.conf (/etc/lvm/lvm.conf).

I guess that solution is likely to work well if you have a VG originally set up with (PVs with) 4K sectors and want to add PVs with 512b sectors.

I'd be careful if it is the the other way around.

Zrin
  • 146
  • 4