Re: [poky] [PATCH v3] genericarm64 core-image-initramfs-boot: remove some kernel drivers

Richard Purdie <[email protected]> Fri, 17 Apr 2026 10:10:07 +0100
Newsgroups org.yoctoproject.lists.poky
Message-ID <026091996b0e9f36733c8933fdf6f872625be247.camel@linuxfoundation.org>
On Mon, 2026-04-13 at 10:27 +0300, Mikko Rapeli via lists.yoctoproject.org =
wrote:
> genericarm64 supports a lot of HW and thus large collection of kernel
> drivers are enabled and installed to images by default.
> Subset of the kernel drivers are needed in initramfs to mount rootfs
> from local mass storage devices. This increases initramfs size a lot
> and with new kernel config updates even more. Thus remove kernel
> drivers from initramfs image which are not needed for mounting
> rootfs from local mass storage devices. GPU, Bluetooth, NFC,
> sound, networking etc support is not needed in the initramfs.
>=20
> According to buildhistory core-image-initramfs-boot size is reduced
> from 118 to 83 Mb.
>=20
> Signed-off-by: Mikko Rapeli <[email protected]>
> ---
> =C2=A0.../images/core-image-initramfs-boot.bbappend | 28 ++++++++++++++++=
+++
> =C2=A01 file changed, 28 insertions(+)
> =C2=A0create mode 100644 meta-yocto-bsp/recipes-core/images/core-image-in=
itramfs-boot.bbappend
>=20
> v3: added PATHS_TO_REMOVE variable so that it can be customized
> =C2=A0=C2=A0=C2=A0 as suggested by Jose Quaresma <[email protected]=
>
>=20
> v2: https://lists.yoctoproject.org/g/poky/message/13894
>=20
> diff --git a/meta-yocto-bsp/recipes-core/images/core-image-initramfs-boot=
.bbappend b/meta-yocto-bsp/recipes-core/images/core-image-initramfs-boot.bb=
append
> new file mode 100644
> index 000000000000..2298c2f94740
> --- /dev/null
> +++ b/meta-yocto-bsp/recipes-core/images/core-image-initramfs-boot.bbappe=
nd
> @@ -0,0 +1,28 @@
> +POSTFUNCS =3D ""
> +POSTFUNCS:genericarm64 =3D "reduce_initrd_size"
> +
> +PATHS_TO_REMOVE =3D ""
> +# these kernel modules are not needed for rootfs mount from local mass s=
torage
> +# and can be loaded from main rootfs by udev
> +PATHS_TO_REMOVE:genericarm64 =3D "\
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
bluetooth \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
gpu \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
media \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
net \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
nfc \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/drivers/=
usb/gadget \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/fs/fuse =
\
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/net/blue=
tooth \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/net/brid=
ge \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/net/netf=
ilter \
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/net/nfc =
\
> +=C2=A0=C2=A0=C2=A0 ${WORKDIR}/rootfs/${libdir}/modules/*/kernel/sound \
> +"
> +
> +do_rootfs[postfuncs] +=3D "${POSTFUNCS}"
> +reduce_initrd_size () {
> +=C2=A0=C2=A0=C2=A0 if [ -n "${PATHS_TO_REMOVE}" ]; then
> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rm -rf ${PATHS_TO_REMOVE}
> +=C2=A0=C2=A0=C2=A0 fi
> +}
> +

This is a tough one. There are some simple things like "POSTFUNCS"
being a bit generic as a name. I also worry a little this may trip up
yocto-check-layer with the added variable POSTFUNCS, even if it is
empty. I think if we're creating this as API, listing the directories:

    drivers/bluetooth \
    drivers/gpu \
    drivers/media \
    drivers/net \
    drivers/nfc \
    drivers/usb/gadget \
    fs/fuse \
    net/bluetooth \
    net/bridge \
    net/netfilter \
    net/nfc \
    sound \

and then adding the prefix would probably be cleaner too. Those are all
easier tweaks.

The bigger challenge is "generic" kernel adding all this. Ideally you
wouldn't install these things to the initramfs in the first place, then
you wouldn't need to delete them. I'm not sure how you could
detect/filter and install only the subset of modules you want, or how
that list of modules would be maintained/updated.

A different package to "kernel-modules" could be one idea, how you
construct that, again, I'm less sure. The above filter list could be
used to iterate the modules and filter by path I guess?

Now we've merged the firmware update, the builds are breaking but some
of these kinds of changes are probably too late for the release/LTS.

Perhaps we just have to increase the size of the initramfs for now :(

Cheers,

Richard