]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #3757 from poettering/efi-search
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 25 Jul 2016 20:17:48 +0000 (16:17 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 25 Jul 2016 20:34:18 +0000 (16:34 -0400)
1  2 
src/boot/bootctl.c
src/gpt-auto-generator/gpt-auto-generator.c
src/nspawn/nspawn.c

index 37fa049ecf3ea6c26a6eb30dca62c7cd97f47647,f0a88ab3aca71ba227f5d2e868a42ac6a4555b23..ff8c7a38ddf79130bbf363652bd81af0cd18b23f
@@@ -1035,67 -1067,84 +1067,84 @@@ static int verb_status(int argc, char *
          if (r < 0)
                  return r;
  
-         switch (arg_action) {
-         case ACTION_STATUS: {
-                 _cleanup_free_ char *fw_type = NULL;
-                 _cleanup_free_ char *fw_info = NULL;
-                 _cleanup_free_ char *loader = NULL;
-                 _cleanup_free_ char *loader_path = NULL;
-                 sd_id128_t loader_part_uuid = {};
-                 if (is_efi_boot()) {
-                         read_loader_efi_var("LoaderFirmwareType", &fw_type);
-                         read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
-                         read_loader_efi_var("LoaderInfo", &loader);
-                         read_loader_efi_var("LoaderImageIdentifier", &loader_path);
-                         if (loader_path)
-                                 efi_tilt_backslashes(loader_path);
-                         r = efi_loader_get_device_part_uuid(&loader_part_uuid);
-                         if (r < 0 && r == -ENOENT)
-                                 log_warning_errno(r, "Failed to read EFI variable LoaderDevicePartUUID: %m");
-                         printf("System:\n");
-                         printf("     Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
-                         r = is_efi_secure_boot();
-                         if (r < 0)
-                                 log_warning_errno(r, "Failed to query secure boot status: %m");
-                         else
-                                 printf("  Secure Boot: %s\n", r ? "enabled" : "disabled");
+         r = find_esp(NULL, NULL, NULL, &uuid);
+         if (r < 0)
+                 return r;
  
-                         r = is_efi_secure_boot_setup_mode();
-                         if (r < 0)
-                                 log_warning_errno(r, "Failed to query secure boot mode: %m");
-                         else
-                                 printf("   Setup Mode: %s\n", r ? "setup" : "user");
-                         printf("\n");
-                         printf("Loader:\n");
-                         printf("      Product: %s\n", strna(loader));
-                         if (!sd_id128_is_null(loader_part_uuid))
-                                 printf("    Partition: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
-                                        SD_ID128_FORMAT_VAL(loader_part_uuid));
-                         else
-                                 printf("    Partition: n/a\n");
-                         printf("         File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
-                         printf("\n");
-                 } else
-                         printf("System:\n    Not booted with EFI\n");
-                 r = status_binaries(arg_path, uuid);
+         if (is_efi_boot()) {
+                 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL;
+                 sd_id128_t loader_part_uuid = SD_ID128_NULL;
+                 read_loader_efi_var("LoaderFirmwareType", &fw_type);
+                 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
+                 read_loader_efi_var("LoaderInfo", &loader);
+                 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
+                 if (loader_path)
+                         efi_tilt_backslashes(loader_path);
+                 r = efi_loader_get_device_part_uuid(&loader_part_uuid);
+                 if (r < 0 && r != -ENOENT)
+                         log_warning_errno(r, "Failed to read EFI variable LoaderDevicePartUUID: %m");
+                 printf("System:\n");
+                 printf("     Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
+                 r = is_efi_secure_boot();
                  if (r < 0)
-                         return r;
+                         log_warning_errno(r, "Failed to query secure boot status: %m");
+                 else
+                         printf("  Secure Boot: %s\n", r ? "enabled" : "disabled");
  
-                 if (arg_touch_variables)
-                         r = status_variables();
-                 break;
-         }
+                 r = is_efi_secure_boot_setup_mode();
+                 if (r < 0)
+                         log_warning_errno(r, "Failed to query secure boot mode: %m");
+                 else
+                         printf("   Setup Mode: %s\n", r ? "setup" : "user");
+                 printf("\n");
+                 printf("Loader:\n");
+                 printf("      Product: %s\n", strna(loader));
 -                if (!sd_id128_equal(loader_part_uuid, SD_ID128_NULL))
++                if (!sd_id128_is_null(loader_part_uuid))
+                         printf("    Partition: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
+                                SD_ID128_FORMAT_VAL(loader_part_uuid));
+                 else
+                         printf("    Partition: n/a\n");
+                 printf("         File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
+                 printf("\n");
+         } else
+                 printf("System:\n    Not booted with EFI\n");
  
-         case ACTION_INSTALL:
-         case ACTION_UPDATE:
-                 umask(0002);
+         r = status_binaries(arg_path, uuid);
+         if (r < 0)
+                 return r;
+         if (arg_touch_variables)
+                 r = status_variables();
  
-                 r = install_binaries(arg_path, arg_action == ACTION_INSTALL);
+         return r;
+ }
+ static int verb_install(int argc, char *argv[], void *userdata) {
+         sd_id128_t uuid = SD_ID128_NULL;
+         uint64_t pstart = 0, psize = 0;
+         uint32_t part = 0;
+         bool install;
+         int r;
+         r = must_be_root();
+         if (r < 0)
+                 return r;
+         r = find_esp(&part, &pstart, &psize, &uuid);
+         if (r < 0)
+                 return r;
+         install = streq(argv[0], "install");
+         RUN_WITH_UMASK(0002) {
+                 r = install_binaries(arg_path, install);
                  if (r < 0)
                          return r;
  
index 39355de953464683c2e0f40c951c67b0b74a6944,e4c913f2c413f0cac17d4ae7017c77c44bb22fac..6cc1aad70553ed2ca2861383b27a5f98702c63cc
@@@ -528,21 -479,74 +479,72 @@@ static int add_boot(const char *what) 
                  return 0;
          }
  
-         if (!sd_id128_equal(type_id, id)) {
-                 log_debug("Partition for /boot does not appear to be the partition we are booted from.");
-                 return 0;
-         }
+         if (is_efi_boot()) {
+                 _cleanup_blkid_free_probe_ blkid_probe b = NULL;
+                 const char *fstype = NULL, *uuid_string = NULL;
+                 sd_id128_t loader_uuid, part_uuid;
  
-         r = add_automount("boot",
-                        what,
-                        "/boot",
-                        "vfat",
-                        true,
-                        "umask=0077",
-                        "EFI System Partition Automount",
-                        120 * USEC_PER_SEC);
+                 /* If this is an EFI boot, be extra careful, and only mount the ESP if it was the ESP used for booting. */
  
-         return r;
+                 r = efi_loader_get_device_part_uuid(&loader_uuid);
+                 if (r == -ENOENT) {
+                         log_debug("EFI loader partition unknown.");
+                         return 0;
+                 }
 -                if (r < 0) {
 -                        log_error_errno(r, "Failed to read ESP partition UUID: %m");
 -                        return r;
 -                }
++                if (r < 0)
++                        return log_error_errno(r, "Failed to read ESP partition UUID: %m");
+                 errno = 0;
+                 b = blkid_new_probe_from_filename(what);
+                 if (!b) {
+                         if (errno == 0)
+                                 return log_oom();
+                         return log_error_errno(errno, "Failed to allocate prober: %m");
+                 }
+                 blkid_probe_enable_partitions(b, 1);
+                 blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
+                 errno = 0;
+                 r = blkid_do_safeprobe(b);
+                 if (r == -2 || r == 1) /* no result or uncertain */
+                         return 0;
+                 else if (r != 0)
+                         return log_error_errno(errno ?: EIO, "Failed to probe %s: %m", what);
+                 (void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
+                 if (!streq_ptr(fstype, "vfat")) {
+                         log_debug("Partition for %s is not a FAT filesystem, ignoring.", esp);
+                         return 0;
+                 }
+                 errno = 0;
+                 r = blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &uuid_string, NULL);
+                 if (r != 0) {
+                         log_debug_errno(errno, "Partition for %s does not have a UUID, ignoring.", esp);
+                         return 0;
+                 }
+                 if (sd_id128_from_string(uuid_string, &part_uuid) < 0) {
+                         log_debug("Partition for %s does not have a valid UUID, ignoring.", esp);
+                         return 0;
+                 }
+                 if (!sd_id128_equal(part_uuid, loader_uuid)) {
+                         log_debug("Partition for %s does not appear to be the partition we are booted from.", esp);
+                         return 0;
+                 }
+         } else
+                 log_debug("Not an EFI boot, skipping ESP check.");
+         return add_automount("boot",
+                           what,
+                           esp,
+                           "vfat",
+                           true,
+                           "umask=0077",
+                           "EFI System Partition Automount",
+                           120 * USEC_PER_SEC);
  }
  #else
  static int add_boot(const char *what) {
Simple merge