]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homed: in images that lack mkfs.btrfs automatically fall back to ext4 16938/head
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Sep 2020 15:30:03 +0000 (17:30 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 Sep 2020 16:02:35 +0000 (18:02 +0200)
It's better to tweak suboptimal defaults than to just fail with
compiled-in defaults.

src/home/homework-luks.c

index 01374baf67696d6e17f2df57a117b55275b5de68..b3082f144a60dd936a6dec15e922f59cdba13b0a 100644 (file)
@@ -1887,6 +1887,23 @@ int home_create_luks(
         if (!supported_fstype(fstype))
                 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "Unsupported file system type: %s", fstype);
 
+        r = mkfs_exists(fstype);
+        if (r < 0)
+                return log_error_errno(r, "Failed to check if mkfs binary for %s exists: %m", fstype);
+        if (r == 0) {
+                if (h->file_system_type || streq(fstype, "ext4") || !supported_fstype("ext4"))
+                        return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkfs binary for file system type %s does not exist.", fstype);
+
+                /* If the record does not explicitly declare a file system to use, and the compiled-in
+                 * default does not actually exist, than do an automatic fallback onto ext4, as the baseline
+                 * fs of Linux. We won't search for a working fs type here beyond ext4, i.e. nothing fancier
+                 * than a single, conservative fallback to baseline. This should be useful in minimal
+                 * environments where mkfs.btrfs or so are not made available, but mkfs.ext4 as Linux' most
+                 * boring, most basic fs is. */
+                log_info("Formatting tool for compiled-in default file system %s not available, falling back to ext4 instead.", fstype);
+                fstype = "ext4";
+        }
+
         if (sd_id128_is_null(h->partition_uuid)) {
                 r = sd_id128_randomize(&partition_uuid);
                 if (r < 0)