Skip to contentSkip to conversation

Remove kernel image and modules from rootfs

DISCUSSION Konstantin Kletschke 2 participants 5 messages Dec 21, 2022 – Jan 5, 2023

lore
Share & tools
lore
#0 lore raw

Hi,

I am creating a rootfs/bootloader/kernel to run on a beaglebone black usually and it works great.

So I have in conf/local.conf

MACHINE ?= "beaglebone-yocto"

and an own layer meta-insidem2m which defines some image settings in recipes-core/images/insidem2m-s.bb among other recipes for packages and package modification.

Now I wan't to create a rootfs without the kernel image and the kernel modules to make it as small as possible to use it as a basis to run as a docker image.

Now I wonder how to instruct bitbake to not put the kernel image (and modules) into the rootfs.

I read this was done by

RDEPENDS_${KERNEL_PACKAGE_NAME}-base = ""

but this is now deprecated for kirkstone and should be done this way:

RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

But rootfs always still is equipped with kernel and modules. I tried all permutations of

#RDEPENDS_kernel-base = "" #MACHINE_ESSENTIAL_EXTRA_RDEPENDS = "" #RDEPENDS_kernel-base = "" #PREFERRED_PROVIDER_virtual/kernel = "linux-dummy" # Don't include kernels in standard images ##RDEPENDS:kernel-base = "" #RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = "" #MACHINE_EXTRA_RRECOMMENDS = "" #RDEPENDS_${KERNEL_PACKAGE_NAME}-base = ""

in my conf/local.conf but no avail...

How is this done correctly?
Are there any variables to check I might have (being) set preventing me to do this? Or is it necessary to split out a new MACHINE, i.e. can this only be done in an own created machine which has to be split out?

I thought setting such at the bottom of conf/local.conf always "wins".

Kind Regards
Konstantin

Signature · 14 lines
INSIDE M2M GmbH
Konstantin Kletschke
Berenbosteler Straße 76 B
30823 Garbsen

Telefon: +49 (0) 5137 90950136
Mobil: +49 (0) 151 15256238
Fax: +49 (0) 5137 9095010

[email protected]
http://www.inside-m2m.de 

Geschäftsführung: Michael Emmert, Ingo Haase, Dr. Fred Könemann, Derek Uhlig
HRB: 111204, AG Hannover
#1 lore raw

Hi Konstantin,

Quoted 20 lines · Konstantin Kletschke

Hi,

I am creating a rootfs/bootloader/kernel to run on a beaglebone black usually and it works great.

So I have in conf/local.conf

MACHINE ?= "beaglebone-yocto"

and an own layer meta-insidem2m which defines some image settings in recipes-core/images/insidem2m-s.bb among other recipes for packages and package modification.

Now I wan't to create a rootfs without the kernel image and the kernel modules to make it as small as possible to use it as a basis to run as a docker image.

Now I wonder how to instruct bitbake to not put the kernel image (and modules) into the rootfs.

Quoted 8 lines

I read this was done by

RDEPENDS_${KERNEL_PACKAGE_NAME}-base = ""

but this is now deprecated for kirkstone and should be done this way:

RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

This makes sense, I'll send a patch updating the documentation to reflect this change. I thought we already had discussed about this and someone sent a patch but doesn't seem so :/

Quoted 13 lines

But rootfs always still is equipped with kernel and modules. I tried all permutations of

#RDEPENDS_kernel-base = "" #MACHINE_ESSENTIAL_EXTRA_RDEPENDS = "" #RDEPENDS_kernel-base = "" #PREFERRED_PROVIDER_virtual/kernel = "linux-dummy" # Don't include kernels in standard images ##RDEPENDS:kernel-base = "" #RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = "" #MACHINE_EXTRA_RRECOMMENDS = "" #RDEPENDS_${KERNEL_PACKAGE_NAME}-base = ""

Quoted 9 lines

in my conf/local.conf but no avail...

How is this done correctly?
Are there any variables to check I might have (being) set preventing me to do this? Or is it necessary to split out a new MACHINE, i.e. can this only be done in an own created machine which has to be split out?

I thought setting such at the bottom of conf/local.conf always "wins".

No.

So I believe you need to add:
MACHINE_EXTRA_RRECOMMENDS:beaglebone-yocto = "" MACHINE_ESSENTIAL_EXTRA_RDEPENDS:remove:beaglebone-yocto = "kernel-image kernel-devicetree" RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""
to your local.conf

I suggest you create your own machine configuration file which requires beaglebone-yocto.conf where you'll be able to set:
MACHINE_EXTRA_RRECOMMENDS = ""
MACHINE_ESSENTIAL_EXTRA_RDEPENDS = ""
RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

since one is not supposed to share their local.conf :)

You can check the value of a variable by running bitbake-getvar -r virtual/kernel MACHINE_EXTRA_RRECOMMENDS for example.

Cheers,
Quentin

#2 lore raw
Quoted 8 lines · Quentin Schulz
Quoted 4 lines

but this is now deprecated for kirkstone and should be done this way:

RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

This makes sense, I'll send a patch updating the documentation to reflect this change. I thought we already had discussed about this and someone sent a patch but doesn't seem so :/

Thank you :-)

Quoted 6 lines

So I believe you need to add:
MACHINE_EXTRA_RRECOMMENDS:beaglebone-yocto = "" MACHINE_ESSENTIAL_EXTRA_RDEPENDS:remove:beaglebone-yocto = "kernel-image kernel-devicetree"
RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""
to your local.conf

Dear Quentin, this is correct. It worked this way.
I admit, I was not aware the config snippets I copied need to be modified for the local.conf in a way the machine name has to be appended!

Quoted 5 lines

I suggest you create your own machine configuration file which requires beaglebone-yocto.conf where you'll be able to set:
MACHINE_EXTRA_RRECOMMENDS = "" MACHINE_ESSENTIAL_EXTRA_RDEPENDS = "" RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

Meanwhile I did something similair, I cloned the machine beaglebone-yocto into my tree with thos modifications on top and this works too.

Thanks for your enormous useful hint to the modification needed for local.conf and the tip to create a machine, inherit beaglebone-yocto and modify those three variables.

Quoted 2 lines

You can check the value of a variable by running bitbake-getvar -r virtual/kernel MACHINE_EXTRA_RRECOMMENDS for example.

Thank you, very useful.

Meanwhile I found out, for my puspose it could be useful to do something like

CORE_IMAGE_BASE_INSTALL:remove = " packagegroup-core-boot packagegroup-base-extended"

in the image config, which might be even more useful for my approach to my use case.

I now can approch my goal with local.conf, an additional machine or the CORE_IMAGE_BASE_INSTALL modification.

One question though:

can the MACHINE variable only be modified in the local.conf (the reference manual - glossary does not mention other places)?

If I go with the additional machine approach I am searching for a way to build different images in my distro based on different machines. Is that possible?

Kind Regards
Konstantin Kletschke

Signature · 14 lines
INSIDE M2M GmbH
Konstantin Kletschke
Berenbosteler Straße 76 B
30823 Garbsen

Telefon: +49 (0) 5137 90950136
Mobil: +49 (0) 151 15256238
Fax: +49 (0) 5137 9095010

[email protected]
http://www.inside-m2m.de 

Geschäftsführung: Michael Emmert, Ingo Haase, Dr. Fred Könemann, Derek Uhlig
HRB: 111204, AG Hannover
#3 lore raw

Hi Konstantin,

Quoted 20 lines · Konstantin Kletschke
Quoted 8 lines · Quentin Schulz
Quoted 4 lines

but this is now deprecated for kirkstone and should be done this way:

RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

This makes sense, I'll send a patch updating the documentation to reflect this change. I thought we already had discussed about this and someone sent a patch but doesn't seem so :/

Thank you :-)

Quoted 6 lines

So I believe you need to add:
MACHINE_EXTRA_RRECOMMENDS:beaglebone-yocto = "" MACHINE_ESSENTIAL_EXTRA_RDEPENDS:remove:beaglebone-yocto = "kernel-image kernel-devicetree"
RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""
to your local.conf

Quoted 5 lines

Dear Quentin, this is correct. It worked this way.
I admit, I was not aware the config snippets I copied need to be modified for the local.conf in a way the machine name has to be appended!

So, you needed the extra :beaglebone-yocto because the machine configuration file is parsed after local.conf, therefore since beaglebone-yocto.conf file has:
MACHINE_EXTRA_RRECOMMENDS = "kernel-modules kernel-devicetree"
MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "kernel-image kernel-devicetree"
your local.conf changes would be overridden while parsing the machine configuration file.

By using the OVERRIDE mechanism, we kinda cheat this by making the variables in local.conf "more important" than the machine conf file's.

You don't need the :beaglebone-yocto OVERRIDE for the :remove but it's "better" this way so that if you build multiple machines with the same local.conf, you don't impact other machines as well.

Quoted 10 lines
Quoted 5 lines

I suggest you create your own machine configuration file which requires beaglebone-yocto.conf where you'll be able to set:
MACHINE_EXTRA_RRECOMMENDS = "" MACHINE_ESSENTIAL_EXTRA_RDEPENDS = "" RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base = ""

Meanwhile I did something similair, I cloned the machine beaglebone-yocto into my tree with thos modifications on top and this works too.

Would highly recommend not doing that though, having two configruation files with the same filename is not nice to your users, because then the order of inclusion of the layers will decide which file gets picked.

Create your own my-beaglebone and in there have:
MACHINEOVERRIDES =. "beaglebone-yocto:"
require conf/machine/beaglebone-yocto.conf

The first line will allow recipes to use the :beaglebone-yocto OVERRIDE to match both the original beaglebone-yocto and your my-beaglebone machines.

Quoted 7 lines

Thanks for your enormous useful hint to the modification needed for local.conf and the tip to create a machine, inherit beaglebone-yocto and modify those three variables.

Quoted 2 lines

You can check the value of a variable by running bitbake-getvar -r virtual/kernel MACHINE_EXTRA_RRECOMMENDS for example.

Quoted 7 lines

Thank you, very useful.

Meanwhile I found out, for my puspose it could be useful to do something like

CORE_IMAGE_BASE_INSTALL:remove = " packagegroup-core-boot packagegroup-base-extended"

Be careful, :remove are final, you cannot re-add its content later on. SO if you expect users to reuse and extend your image recipe while having :remove in there, you'll have unhappy users :)

Quoted 11 lines

in the image config, which might be even more useful for my approach to my use case.

I now can approch my goal with local.conf, an additional machine or the CORE_IMAGE_BASE_INSTALL modification.

One question though:

can the MACHINE variable only be modified in the local.conf (the reference manual - glossary does not mention other places)?

It can be modified in any configuration file I believe, though local.conf is the only one that makes sense to me, anything else is bad practice.

However, you can pass MACHINE=my-beaglebone to bitbake, e.g.:
MACHINE=my-beaglebone bitbake my-image

would build my-image for this machine specifically.

Quoted 4 lines

If I go with the additional machine approach I am searching for a way to build different images in my distro based on different machines. Is that possible?

What exactly should be different between your images per machines? If we're talking about some specific BSP components differing (e.g. kernel, bootloader, tf-a, op-tee, etc... basically anything NOT userspace), it's better IMHO to specify those machine specific packages as MACHINE_EXTRA_RRECOMMENDS or MACHINE_ESSENTIAL_EXTRA_RDEPENDS in your machine configuration file. If it's something else, you can either (ab)use the OVERRIDE mechanism (:my-beaglebone) to specify packages to install only for one machine. E.g. in your image recipe:
IMAGE_INSTALL:append:my-beaglebone = " some-my-beaglebone-package"

If you want the same package but in different version or a different implementation (e.g. dropbear vs openssh, barebox vs uboot), have a look at virtual recipes (you can find consumers of those virtual recipes where virtual/somthing is used).

Finally, it might make more sense to just have multiple image recipes, each machine having its own image recipe for example.

Remember, distro is for policy (should my system be configured to run with x11, wayland, alsa, whatever), machine is for HW and recipes are for SW applications configured for a given policy and compiled for a given machine. If your HW is identical but you want some differences in your images, you might want to have a look at distro configruation files rather than different machines (at least on the theoretical and best practice level, it's the preferred way).

Cheers,
Quentin

#4 lore raw

Hi Quentin,

Quoted 2 lines · Quentin Schulz

So, you needed the extra :beaglebone-yocto because the machine configuration file is parsed after local.conf, therefore since beaglebone-yocto.conf file

I was not aware of that, thaught always local.conf is master/last.

Quoted 7 lines
Quoted 3 lines

Meanwhile I did something similair, I cloned the machine beaglebone-yocto into my tree with thos modifications on top and this works too.

Would highly recommend not doing that though, having two configruation files with the same filename is not nice to your users, because then the order of inclusion of the layers will decide which file gets picked.

I fully agree, this felt strange from the beginning to me and I wondered why I had the luck that ot worked. Indeed my meta-insidem2m layer is ordered last.

Quoted 6 lines

Create your own my-beaglebone and in there have:
MACHINEOVERRIDES =. "beaglebone-yocto:"
require conf/machine/beaglebone-yocto.conf

The first line will allow recipes to use the :beaglebone-yocto OVERRIDE to match both the original beaglebone-yocto and your my-beaglebone machines.

Thanks for this really nice and useful advice!

Quoted 6 lines
Quoted 2 lines

CORE_IMAGE_BASE_INSTALL:remove = " packagegroup-core-boot packagegroup-base-extended"

Be careful, :remove are final, you cannot re-add its content later on. SO if you expect users to reuse and extend your image recipe while having :remove in there, you'll have unhappy users :)

You are right, I reread the part in the reference manual and played around with it utilizing the bitbake-getvar you showed to me. I did not really have understood this before. Additionally removeing thos packagegroups probably removes too much from the image. This is what I meanwhile realized - regarding our pretended use case.

Quoted 1 line

What exactly should be different between your images per machines? If we're

I have a meta-insidem2m layer which up until now contains all my stuff I need to cope with yocto and requires no modifications to upstream stuff. Additionally it contains one bblayers.conf and local.conf, which are placed in build/config but not modified.
This meta-insidem2m has a distro and 3 images configured. The MACHINE is beaglebone-yocto for all the same. The images only differ in the IMAGE_INSTALL set, they are insidem2m-s insidem2m-m and insidem2m-xl. I use the -s as a NFS rootfs for our Bealgsbone Blacks and the -xl variant is the one which gets installed on them for production use. All from one tree w/o further configuration.

Now I have a customer's requirement for use to live from a docker container and to utilize a self compiled rootfs in that to have full control over this regarding content and availability.

So I thougt I need a insidem2m-xs variant additionally like the already existing ones (processor architecure matches regarding userspace) and now I need insidem2m-s minus kernel, bootloader and init system.

And this in a way like making this right and not abusing mechanisms.

I learned removing bootloader and kernel requires an additional machine set up _if_ I want to use my local.conf for all images.
I have to do this smart (renaming with MACHINEOVERRIDES and require), check.
Then I can call "bitabke insidem2m-[s|m|xl]" for my normal images, "MACHINE=my-bbb bitbake insidem2m-xs" for an image w/o kernel and stuff for my docker filesystem. as said, this way local.conf is fixed, everything else also.

This is the smartest approach, right?

Quoted 1 line

IMAGE_INSTALL:append:my-beaglebone = " some-my-beaglebone-package"

I think, this will become useful also to my use case. I do not yet know, which packages in the end are required in our resulting rootfs. This will become handy...

Quoted 2 lines

Finally, it might make more sense to just have multiple image recipes, each machine having its own image recipe for example.

May be this is most importand for me and not covered from my understanding,yet : Can a machine[.conf] have its onw own image[.bb]? In a single meta-xyz layer?
This way "bitbake image" would autoselect a proper machine.

Kind Regards
Konstantin

Signature · 14 lines
INSIDE M2M GmbH
Konstantin Kletschke
Berenbosteler Straße 76 B
30823 Garbsen

Telefon: +49 (0) 5137 90950136
Mobil: +49 (0) 151 15256238
Fax: +49 (0) 5137 9095010

[email protected]
http://www.inside-m2m.de 

Geschäftsführung: Michael Emmert, Ingo Haase, Dr. Fred Könemann, Derek Uhlig
HRB: 111204, AG Hannover