]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Use sectorsize for partition tables on block devs 35776/head
authorscarlet-storm <12461256+scarlet-storm@users.noreply.github.com>
Sat, 28 Dec 2024 08:44:11 +0000 (14:14 +0530)
committerscarlet-storm <12461256+scarlet-storm@users.noreply.github.com>
Tue, 17 Feb 2026 12:53:35 +0000 (18:23 +0530)
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.

src/home/homework-luks.c

index e7dc26794cdab08046b730839879f880694cdef3..9f7af06a4e780f1758ae65c602ec5edb54c260a1 100644 (file)
@@ -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,