[v5,04/12] rootfs: Copy the newly created initrd.img to the work directory

Message ID 20251030094451.1303871-5-Quirin.Gylstorff@siemens.com
State New
Headers show
Series Add support for dracut | expand

Commit Message

Quirin Gylstorff Oct. 30, 2025, 9:44 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This allows to change the permissions of the initrd to 0644. And
all followup steps do not need sudo.

This is necessary as dracut creates the initrd with 0600 permissions.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 meta/classes/rootfs.bbclass | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Quirin Gylstorff Oct. 30, 2025, 12:04 p.m. UTC | #1
On 10/30/25 10:44, 'Quirin Gylstorff' via isar-users wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> This allows to change the permissions of the initrd to 0644. And
> all followup steps do not need sudo.
> 
> This is necessary as dracut creates the initrd with 0600 permissions.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>   meta/classes/rootfs.bbclass | 14 ++++----------
>   1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
> index 1f2ad80b..6b30744b 100644
> --- a/meta/classes/rootfs.bbclass
> +++ b/meta/classes/rootfs.bbclass
> @@ -594,17 +594,11 @@ rootfs_generate_initramfs() {
>               echo "Total number of modules: $mods_total"
>               echo "Generating initrd for kernel version: $kernel_version"
>               sudo -E chroot "${ROOTFSDIR}" sh -c ' \
> -                ${ROOTFS_INITRAMFS_GENERATOR_CMDLINE};'
> +                ${ROOTFS_INITRAMFS_GENERATOR_CMDLINE}; \
> +                find /boot -name "initrd.img-$kernel_version*" -exec install --mode 0644 {} /isar-work/initrd.img \; \
> +                '
This patch does not change the behavior:
  - copy the last generated initrd to workdir

The  loop was added to support mulitple kernel installations with commit 
f6cd9f9ee.

Quirin>           done
> -        if [ -n "${INITRD_DEPLOY_FILE}" ]; then
> -            if [ -f "${ROOTFSDIR}/initrd.img" ]; then
> -                # debian (mkinitramfs)
> -                cp ${ROOTFSDIR}/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
> -            else
> -                # ubuntu (dracut)
> -                cp ${ROOTFSDIR}/boot/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
> -            fi
> -        fi
> +        install --owner $(id -u) --group $(id -g) ${WORKDIR}/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
>       else
>           echo "no kernel in this rootfs, do not generate initrd"
>       fi

Patch

diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 1f2ad80b..6b30744b 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -594,17 +594,11 @@  rootfs_generate_initramfs() {
             echo "Total number of modules: $mods_total"
             echo "Generating initrd for kernel version: $kernel_version"
             sudo -E chroot "${ROOTFSDIR}" sh -c ' \
-                ${ROOTFS_INITRAMFS_GENERATOR_CMDLINE};'
+                ${ROOTFS_INITRAMFS_GENERATOR_CMDLINE}; \
+                find /boot -name "initrd.img-$kernel_version*" -exec install --mode 0644 {} /isar-work/initrd.img \; \
+                '
         done
-        if [ -n "${INITRD_DEPLOY_FILE}" ]; then
-            if [ -f "${ROOTFSDIR}/initrd.img" ]; then
-                # debian (mkinitramfs)
-                cp ${ROOTFSDIR}/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
-            else
-                # ubuntu (dracut)
-                cp ${ROOTFSDIR}/boot/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
-            fi
-        fi
+        install --owner $(id -u) --group $(id -g) ${WORKDIR}/initrd.img ${DEPLOYDIR}/${INITRD_DEPLOY_FILE}
     else
         echo "no kernel in this rootfs, do not generate initrd"
     fi