You are not logged in.
I had an external WD My Book that I was using as a storage device with LUKS on it. I recently got a larger PC case and shucked the drive to use internally but when I do so I am no longer able to open the LUKS container. If I put the drive back into its old external case and plug it in via a USB port it works just fine. Looking at some of the output for these devices it appears to be an issue with the sectos, these messages from dmesg led me to this conclusion:
# dmesg | grep -i mapper
[ 1646.354443] device-mapper: table: 254:3: crypt: Device size is not multiple of sector_size feature (-EINVAL)
[ 1646.354447] device-mapper: ioctl: error adding target to tableIs there an easy way to fix this or would I be better off transfering all the data off the drive and repartitioning/encrypting it?
When plugged in with SATA
# fdisk -l /dev/sdb
Disk /dev/sdb: 3.64 TiB, 4000753476096 bytes, 7813971633 sectors
Disk model: WDC WD40EFRX-68W
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes# blkid
/dev/sdb: UUID="b1815fe3-1f90-4836-86ac-c489f036b704" TYPE="crypto_LUKS"# lsblk -t /dev/sdb
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME
sdb 0 4096 0 4096 512 1 mq-deadline 64 128 0BWhen plugged in by USB
# fdisk -l /dev/sdb
Disk /dev/sdb: 3.64 TiB, 4000752599040 bytes, 976746240 sectors
Disk model: My Book 1230
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytesblkid
/dev/sdb: UUID="b1815fe3-1f90-4836-86ac-c489f036b704" TYPE="crypto_LUKS"
/dev/mapper/vault: LABEL="valut1" UUID="f30a128c-6fe5-4d41-87f6-1e9c2fd7fc4f" BLOCK_SIZE="4096" TYPE="ext4"# lsblk -t /dev/sdb
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME
sdb 0 4096 0 4096 4096 1 mq-deadline 2 128 0B
└─vault 0 4096 0 4096 4096 1 128 128 0BOffline
Unfortunately you somehow have an odd number of 512e sectors on that drive, instead of multiple of 4K sectors. And you're probably using 4K sector size for LUKS (check with cryptsetup luksDump).
The thing is, instead of simply ignoring the last partial 4K sector, LUKS errors out altogether instead. So it does not open at all anymore.
To work around it, you have to specify the size when you open with cryptsetup open --device-size option.
Alternatively create a loop device with losetup --sizelimit and open that (but that's an extra layer then).
In future I would recommend using a partition table, with a partition of the correct size, then it does not matter if the whole device has an odd number of sectors.
But in your case, a partition table will break between internal and external use, as the external uses 4K logical sectors geometry, and the internal uses 512e sectors. Partition tables still depend on the sector size. So you have to re-write partition table depending how it's connected (you can use losetup --sector-size to read a partition table of the wrong format, as the kernel is probably still not flexible enough to detect either variant by itself...).
A sector-size agnostic alternative might be LVM. But even so I don't like using drives without partition table, it only causes problems...
Another workaround would be cryptsetup reencrypt and change the sector size of LUKS to 512 instead of 4096, then in the internal use case the LUKS device would be slightly larger (and you should not use that space as it would be missing, in the enclosure). But I'd still rather set it up with partitions instead.
Last edited by frostschutz (2022-10-15 14:24:59)
Offline