From 22cea9e8d71794b642a7e8b8572d077733eccdfd Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Sat, 19 Feb 2022 09:54:09 +0300 Subject: [PATCH 1/4] initramfs-module-copy-modules: add initramfs module to install modules Add initramfs module that installs provided kernel modules into the rootfs. To enable it, add 'copy_modules' kernel bootarg. Signed-off-by: Dmitry Baryshkov --- .../initrdscripts/files/copy-modules.sh | 17 +++++++++++++++++ .../initramfs-module-copy-modules_1.0.bb | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 recipes-support/initrdscripts/files/copy-modules.sh create mode 100644 recipes-support/initrdscripts/initramfs-module-copy-modules_1.0.bb diff --git a/recipes-support/initrdscripts/files/copy-modules.sh b/recipes-support/initrdscripts/files/copy-modules.sh new file mode 100644 index 000000000..12dc052f9 --- /dev/null +++ b/recipes-support/initrdscripts/files/copy-modules.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Copyright (C) 2022 Linaro Ltd. +# Licensed on MIT + +copy_modules_enabled() { + [ -n "${bootparam_copy_modules}" -a -d /lib/modules/`uname -r` ] +} + +copy_modules_run() { + if [ -n "$ROOTFS_DIR" ]; then + rm -rf $ROOTFS_DIR/lib/modules/`uname -r` + mkdir -p $ROOTFS_DIR/lib/modules + cp -a /lib/modules/`uname -r` $ROOTFS_DIR/lib/modules + else + debug "No rootfs has been set" + fi +} diff --git a/recipes-support/initrdscripts/initramfs-module-copy-modules_1.0.bb b/recipes-support/initrdscripts/initramfs-module-copy-modules_1.0.bb new file mode 100644 index 000000000..effc7df84 --- /dev/null +++ b/recipes-support/initrdscripts/initramfs-module-copy-modules_1.0.bb @@ -0,0 +1,15 @@ +SUMMARY = "initramfs-framework module for copying kernel modules from initramfs to rootfs" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" +RDEPENDS:${PN} = "initramfs-framework-base ${VIRTUAL-RUNTIME_base-utils}" + +SRC_URI = "file://copy-modules.sh" + +S = "${WORKDIR}" + +do_install() { + install -d ${D}/init.d + install -m 0755 ${WORKDIR}/copy-modules.sh ${D}/init.d/95-copy_modules +} + +FILES:${PN} = "/init.d/" From 0d67acb487bfca6cfe6b819343d5f730654aaeab Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 12 Nov 2021 14:51:20 +0300 Subject: [PATCH 2/4] initramfs-rootfs-image: add initramfs that pivots into rootfs Add small initramfs image that will detect, mount and switch into specified rootfs. At this moment this recipe does not pull any kernel modules on its own, users of the initramfs have to do that on their own. Signed-off-by: Dmitry Baryshkov --- .../images/initramfs-rootfs-image.bb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 recipes-kernel/images/initramfs-rootfs-image.bb diff --git a/recipes-kernel/images/initramfs-rootfs-image.bb b/recipes-kernel/images/initramfs-rootfs-image.bb new file mode 100644 index 000000000..37b513da9 --- /dev/null +++ b/recipes-kernel/images/initramfs-rootfs-image.bb @@ -0,0 +1,22 @@ +DESCRIPTION = "Ramdisk image for pivoting into rootfs" + +PACKAGE_INSTALL = " \ + base-passwd \ + initramfs-module-rootfs \ + initramfs-module-udev \ + ${VIRTUAL-RUNTIME_base-utils} \ + ${MACHINE_ESSENTIAL_EXTRA_RDEPENDS} \ + ${ROOTFS_BOOTSTRAP_INSTALL} \ +" + +# Do not pollute the initrd image with rootfs features +IMAGE_FEATURES = "debug-tweaks" +IMAGE_LINGUAS = "" + +LICENSE = "MIT" + +IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" +inherit core-image + +IMAGE_ROOTFS_SIZE = "8192" +IMAGE_ROOTFS_EXTRA_SPACE = "0" From 93e987a5c13604c08dedfd3968bdf7306f228f1b Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Sat, 19 Feb 2022 09:56:00 +0300 Subject: [PATCH 3/4] initramfs-rootfs-image: enable module installation on demand Signed-off-by: Dmitry Baryshkov --- recipes-kernel/images/initramfs-rootfs-image.bb | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes-kernel/images/initramfs-rootfs-image.bb b/recipes-kernel/images/initramfs-rootfs-image.bb index 37b513da9..e7d52dbfc 100644 --- a/recipes-kernel/images/initramfs-rootfs-image.bb +++ b/recipes-kernel/images/initramfs-rootfs-image.bb @@ -2,6 +2,7 @@ DESCRIPTION = "Ramdisk image for pivoting into rootfs" PACKAGE_INSTALL = " \ base-passwd \ + initramfs-module-copy-modules \ initramfs-module-rootfs \ initramfs-module-udev \ ${VIRTUAL-RUNTIME_base-utils} \ From 37be85ca493a235d9c8de206d280acc4153c0ed7 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Wed, 23 Mar 2022 22:53:34 +0300 Subject: [PATCH 4/4] initramfs-rootfs-image: exclude all kernel images from the image Exclude all the kernel images from this initramfs. This shrinks the initramfs for a few megs. Signed-off-by: Dmitry Baryshkov --- recipes-kernel/images/initramfs-rootfs-image.bb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipes-kernel/images/initramfs-rootfs-image.bb b/recipes-kernel/images/initramfs-rootfs-image.bb index e7d52dbfc..9bc9dc5da 100644 --- a/recipes-kernel/images/initramfs-rootfs-image.bb +++ b/recipes-kernel/images/initramfs-rootfs-image.bb @@ -21,3 +21,6 @@ inherit core-image IMAGE_ROOTFS_SIZE = "8192" IMAGE_ROOTFS_EXTRA_SPACE = "0" + +# Exclude all kernel images from the rootfs +PACKAGE_EXCLUDE = "kernel-image-*"