Skip to main content
2 of 5
formatting for clarity
Geid
  • 41
  • 4

cryptsetup block size preventing from using it

I used cryptsetup to encrypt a disk. I followed this tutorial, which uses the default values. Afterwards I used the disk with no issues and backed up my data. Now I connect it again and returns error when attempt at mount, when I use cryptsetup openLuks I get this message:

device-mapper: reload ioctl on HD (252:0) failed: Invalid argument
The device size is not multiple of the requested sector size.

The default parameters of cryptsetup set the block size to 4096b, as the output of luksDump shows:

Data segments:
  0: crypt
    offset: 16777216 [bytes]
    length: (whole device)
    cipher: aes-xts-plain64
    sector: 4096 [bytes]

but as the output of fdisk -l shows, the block size of the device is 512b:

Disk /dev/sda: 465,76 GiB, 500107861504 bytes, 976773167 sectors
Disk model: USB 3.0 Cable   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Adjusting Device size

I tried cryptsetup with the --device-size option to 500107857920 bytes, the closest multiple of 4096b, but it gives me the same error.

Reencrypt with different sector size

I tried cryptsetup reencrypt --keep-key --sector-size 512 , but returns error:

Data device is not aligned to encryption sector size (4096 bytes).
Failed to initialize LUKS2 reencryption in metadata.

Resizing partition

I have considered the option of resizing the partition but gparted doesn't recognize it, idk if it's the lack of label or just because it doesn't have access to the encrypted partition table:

(parted) print                                                            
Error: /dev/sda: unrecognised disk label
Model: Seagate USB 3.0 Cable (scsi)                                       
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 

What else other than reformatting the whole disk?

I suspect my math is wrong when specifying disk size, but I've checked multiple times, or maybe there is another approach to align the partition.

The backup was a slow process since it involved multiple disks and machines and carefully checking different versions, I'd love to not do it again.

Related links:

Geid
  • 41
  • 4