From: scarlet-storm <12461256+scarlet-storm@users.noreply.github.com> Date: Sat, 28 Dec 2024 08:44:11 +0000 (+0530) Subject: Use sectorsize for partition tables on block devs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48b9d7e980e5ca182af0f9e06a5c67e727f606d2;p=thirdparty%2Fsystemd.git Use sectorsize for partition tables on block devs 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. --- diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index e7dc26794cd..9f7af06a4e7 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -2365,9 +2365,15 @@ int home_create_luks( 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,