Fix for specific case #30393 where 4k sector luks container is created
on a 512b device. In this case the partition table needs to be 512b,
else the kernel will not be able to find the partition, and we will
have to create a loop device to translate the partition table to 4k.
image_sector_size = UINT32_MAX;
/* Let cryptsetup decide if the sector size is not specified in home record */
luks_sector_size = 0;
- } else
- luks_sector_size = image_sector_size = user_record_luks_sector_size(h);
-
+ } else {
+ if (S_ISBLK(st.st_mode)) {
+ /* For physical block devices always use the actual device logical
+ * sector size. Else the partition will not be discoverable by kernel. */
+ image_sector_size = UINT32_MAX;
+ luks_sector_size = user_record_luks_sector_size(h);
+ } else
+ image_sector_size = luks_sector_size = user_record_luks_sector_size(h);
+ }
r = make_partition_table(
setup->image_fd,
image_sector_size,