]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Make sure we take --root into account everywhere.
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 9 Feb 2023 09:53:16 +0000 (10:53 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 9 Feb 2023 14:46:17 +0000 (14:46 +0000)
src/boot/bootctl-install.c
src/boot/bootctl-util.c
src/kernel-install/test-kernel-install.sh

index 3dcb4687d1d389309cc0d39e518f3be9bd499035..c795e75bc3dae51a62bf8ee9ab062770484c23ae 100644 (file)
@@ -43,10 +43,14 @@ static int load_etc_machine_info(void) {
          * for setting up the ESP in /etc/machine-info. The newer /etc/kernel/entry-token file, as well as
          * the $layout field in /etc/kernel/install.conf are better replacements for this though, hence this
          * has been deprecated and is only returned for compatibility. */
-        _cleanup_free_ char *s = NULL, *layout = NULL;
+        _cleanup_free_ char *p = NULL, *s = NULL, *layout = NULL;
         int r;
 
-        r = parse_env_file(NULL, "/etc/machine-info",
+        p = path_join(arg_root, "etc/machine-info");
+        if (!p)
+                return log_oom();
+
+        r = parse_env_file(NULL, p,
                            "KERNEL_INSTALL_LAYOUT", &layout,
                            "KERNEL_INSTALL_MACHINE_ID", &s);
         if (r == -ENOENT)
@@ -83,7 +87,7 @@ static int load_etc_kernel_install_conf(void) {
         _cleanup_free_ char *layout = NULL, *p = NULL;
         int r;
 
-        p = path_join(etc_kernel(), "install.conf");
+        p = path_join(arg_root, etc_kernel(), "install.conf");
         if (!p)
                 return log_oom();
 
@@ -506,7 +510,7 @@ static int install_entry_token(void) {
         if (!arg_make_entry_directory && arg_entry_token_type == ARG_ENTRY_TOKEN_MACHINE_ID)
                 return 0;
 
-        p = path_join(etc_kernel(), "entry-token");
+        p = path_join(arg_root, etc_kernel(), "entry-token");
         if (!p)
                 return log_oom();
 
index 859742a1261003e8934402fd19e51fd2bf51ab98..f89721244ac96f9101a688998458c28d34d42ea5 100644 (file)
@@ -120,7 +120,7 @@ int settle_entry_token(void) {
 
         case ARG_ENTRY_TOKEN_AUTO: {
                 _cleanup_free_ char *buf = NULL, *p = NULL;
-                p = path_join(etc_kernel(), "entry-token");
+                p = path_join(arg_root, etc_kernel(), "entry-token");
                 if (!p)
                         return log_oom();
                 r = read_one_line_file(p, &buf);
@@ -133,7 +133,7 @@ int settle_entry_token(void) {
                 } else if (sd_id128_is_null(arg_machine_id)) {
                         _cleanup_free_ char *id = NULL, *image_id = NULL;
 
-                        r = parse_os_release(NULL,
+                        r = parse_os_release(arg_root,
                                              "IMAGE_ID", &image_id,
                                              "ID", &id);
                         if (r < 0)
@@ -171,7 +171,7 @@ int settle_entry_token(void) {
         case ARG_ENTRY_TOKEN_OS_IMAGE_ID: {
                 _cleanup_free_ char *buf = NULL;
 
-                r = parse_os_release(NULL, "IMAGE_ID", &buf);
+                r = parse_os_release(arg_root, "IMAGE_ID", &buf);
                 if (r < 0)
                         return log_error_errno(r, "Failed to load /etc/os-release: %m");
 
@@ -185,7 +185,7 @@ int settle_entry_token(void) {
         case ARG_ENTRY_TOKEN_OS_ID: {
                 _cleanup_free_ char *buf = NULL;
 
-                r = parse_os_release(NULL, "ID", &buf);
+                r = parse_os_release(arg_root, "ID", &buf);
                 if (r < 0)
                         return log_error_errno(r, "Failed to load /etc/os-release: %m");
 
index f16bb9f50f9d4d328c942b9365bbf54b3c5b54b1..bc833e4cb263c66a3dca2f78be85ffc6138060b0 100755 (executable)
@@ -90,18 +90,21 @@ if test -x "$_KERNEL_INSTALL_BOOTCTL"; then
     echo "Testing bootctl"
     e2="${entry%+*}_2.conf"
     cp "$entry" "$e2"
-    export SYSTEMD_ESP_PATH=/
+    export SYSTEMD_ESP_PATH=/boot
+    # We use --root so strip the root prefix from KERNEL_INSTALL_CONF_ROOT
+    export KERNEL_INSTALL_CONF_ROOT="sources"
 
     # create file that is not referenced. Check if cleanup removes
     # it but leaves the rest alone
     :> "$BOOT_ROOT/the-token/1.1.2/initrd"
-    "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" cleanup
+    "$_KERNEL_INSTALL_BOOTCTL" --root="$D" cleanup
     test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd"
     test -e "$BOOT_ROOT/the-token/1.1.2/linux"
     test -e "$BOOT_ROOT/the-token/1.1.1/linux"
     test -e "$BOOT_ROOT/the-token/1.1.1/initrd"
+
     # now remove duplicated entry and make sure files are left over
-    "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "${e2##*/}"
+    "$_KERNEL_INSTALL_BOOTCTL" --root="$D" unlink "${e2##*/}"
     test -e "$BOOT_ROOT/the-token/1.1.1/linux"
     test -e "$BOOT_ROOT/the-token/1.1.1/initrd"
     test -e "$entry"
@@ -109,7 +112,7 @@ if test -x "$_KERNEL_INSTALL_BOOTCTL"; then
     # remove last entry referencing those files
     entry_id="${entry##*/}"
     entry_id="${entry_id%+*}.conf"
-    "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "$entry_id"
+    "$_KERNEL_INSTALL_BOOTCTL" --root="$D" unlink "$entry_id"
     test ! -e "$entry"
     test ! -e "$BOOT_ROOT/the-token/1.1.1/linux"
     test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd"