]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add multiple initrd file support to kernel-install
authorMike Auty <mike.auty@gmail.com>
Thu, 17 Jan 2019 18:06:09 +0000 (18:06 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Jan 2019 12:49:52 +0000 (13:49 +0100)
Instead of having just a single INITRD field, add support for all
additional parameters being INITRD fields in order.

Signed-off-by: Mike Auty <mike.auty@gmail.com>
man/kernel-install.xml
src/kernel-install/90-loaderentry.install
src/kernel-install/kernel-install

index 84204df150b2e48e1ed7dcfad7531487e5f6e11e..50e1320105d07a71f323d78b3fe0183bb210c43b 100644 (file)
@@ -29,7 +29,7 @@
       <arg choice="plain">COMMAND</arg>
       <arg choice="plain"><replaceable>KERNEL-VERSION</replaceable></arg>
       <arg choice="plain"><replaceable>KERNEL-IMAGE</replaceable></arg>
-      <arg choice="opt"><replaceable>INITRD-FILE</replaceable></arg>
+      <arg choice="opt" rep="repeat"><replaceable>INITRD-FILE</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
@@ -62,7 +62,7 @@
     <para>The following commands are understood:</para>
     <variablelist>
       <varlistentry>
-        <term><command>add <replaceable>KERNEL-VERSION</replaceable> <replaceable>KERNEL-IMAGE</replaceable> [<replaceable>INITRD-FILE</replaceable>]</command></term>
+        <term><command>add <replaceable>KERNEL-VERSION</replaceable> <replaceable>KERNEL-IMAGE</replaceable> [<replaceable>INITRD-FILE</replaceable> ...]</command></term>
         <listitem>
           <para>This command expects a kernel version string and a path to a kernel image file as
           arguments. <command>kernel-install</command> creates the directory
@@ -70,7 +70,7 @@
           and calls the executables from <filename>/usr/lib/kernel/install.d/*.install</filename> and
           <filename>/etc/kernel/install.d/*.install</filename> with the following arguments:
 
-          <programlisting>add <replaceable>KERNEL-VERSION</replaceable> <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename> <replaceable>KERNEL-IMAGE</replaceable> <replaceable>INITRD-FILE</replaceable></programlisting>
+          <programlisting>add <replaceable>KERNEL-VERSION</replaceable> <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename> <replaceable>KERNEL-IMAGE</replaceable> [<replaceable>INITRD-FILE</replaceable> ...]</programlisting>
           </para>
 
           <para>Two default plugins execute the following operations in this case:</para>
@@ -84,9 +84,9 @@
             <listitem><para><filename>90-loaderentry.install</filename> copies <replaceable>KERNEL-IMAGE</replaceable>
             to
             <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/linux</filename>.
-            If <replaceable>INITRD-FILE</replaceable> is provided, it also copies <replaceable>INITRD-FILE</replaceable>
+            If an <replaceable>INITRD-FILE</replaceable> is provided, it also copies <replaceable>INITRD-FILE</replaceable>
             to
-            <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL_VERSION</replaceable>/initrd</filename>.
+            <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL_VERSION</replaceable>/<replaceable>INITRD-FILE</replaceable></filename>.
             It also creates a boot loader entry according to the <ulink
             url="https://systemd.io/BOOT_LOADER_SPECIFICATION">Boot Loader Specification</ulink> in
             <filename>/boot/loader/entries/<replaceable>MACHINE-ID</replaceable>-<replaceable>KERNEL-VERSION</replaceable>.conf</filename>.
index 3437bb3cbcb6f6e429bf28a0a2ee07efa9795c6f..e5fb232f35c24826fadc97d99042a41d367fd59c 100644 (file)
@@ -6,7 +6,7 @@ COMMAND="$1"
 KERNEL_VERSION="$2"
 BOOT_DIR_ABS="$3"
 KERNEL_IMAGE="$4"
-INITRD_FILE="$5"
+INITRD_OPTIONS_START="5"
 
 if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
     exit 0
@@ -83,14 +83,17 @@ cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
     exit 1
 }
 
-if [[ -f "${INITRD_FILE}" ]]; then
-    cp "${INITRD_FILE}" "$BOOT_DIR_ABS/initrd" &&
-        chown root:root "$BOOT_DIR_ABS/initrd" &&
-        chmod 0644 "$BOOT_DIR_ABS/initrd" || {
-         echo "Could not copy '$INITRD_FILE' to '$BOOT_DIR_ABS/initrd'." >&2
-         exit 1
-    }
-fi
+for initrd in "${@:${INITRD_OPTIONS_START}}"; do
+    if [[ -f "${initrd}" ]]; then
+        initrd_basename="$(basename ${initrd})"
+        cp "${initrd}" "$BOOT_DIR_ABS/${initrd_basename}" &&
+            chown root:root "$BOOT_DIR_ABS/${initrd_basename}" &&
+            chmod 0644 "$BOOT_DIR_ABS/${initrd_basename}" || {
+             echo "Could not copy '${initrd}' to '$BOOT_DIR_ABS/${initrd_basename}'." >&2
+             exit 1
+        }
+    fi
+done
 
 mkdir -p "${LOADER_ENTRY%/*}" || {
     echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
@@ -103,8 +106,10 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
     echo "machine-id $MACHINE_ID"
     echo "options    ${BOOT_OPTIONS[*]}"
     echo "linux      $BOOT_DIR/linux"
-    [[ -f $BOOT_DIR_ABS/initrd ]] && \
-        echo "initrd     $BOOT_DIR/initrd"
+    for initrd in "${@:${INITRD_OPTIONS_START}}"; do
+        [[ -f $BOOT_DIR_ABS/$(basename ${initrd}) ]] && \
+            echo "initrd     $BOOT_DIR/$(basename ${initrd})"
+    done
     :
 } > "$LOADER_ENTRY" || {
     echo "Could not create loader entry '$LOADER_ENTRY'." >&2
index 7240df904c7004ad933462d3ed0f2854fdac9ed0..7973818bcadb0b04952866d491d329debbce2495 100644 (file)
@@ -24,7 +24,7 @@ SKIP_REMAINING=77
 usage()
 {
     echo "Usage:"
-    echo "        $0 add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE]"
+    echo "        $0 add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE ...]"
     echo "        $0 remove KERNEL-VERSION"
 }
 
@@ -72,7 +72,7 @@ fi
 
 KERNEL_VERSION="$1"
 KERNEL_IMAGE="$2"
-INITRD_FILE="$3"
+INITRD_OPTIONS_START="3"
 
 if [[ -f /etc/machine-id ]]; then
     read MACHINE_ID < /etc/machine-id
@@ -124,7 +124,7 @@ case $COMMAND in
 
         for f in "${PLUGINS[@]}"; do
             if [[ -x $f ]]; then
-                "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE" "$INITRD_FILE"
+                "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE" "${@:${INITRD_OPTIONS_START}}"
                 x=$?
                 if [[ $x == $SKIP_REMAINING ]]; then
                     ret=0