linuxlinux-kernelembedded-linuxyoctoprocps

Add New Kernel Parameter To Custom Linux Image Generated By Yocto


I am experimenting with Yocto project for generating custom Linux images for my embedded devices.

I have a requirement to add a persistent custom kernel parameter to /etc/sysctl.conf of the generated image.

i.e.

kernel.core_pipe_limit = 1

/etc/sysctl.conf is generated by procps package that comes with Yocto base system (meta/recipes-extended/procps/procps/sysctl.conf). However, I believe editing the sysctl.conf in the base system is not the recommended approach.

I am using a new layer for defining my custom configurations. I hope there is a way to apply a patch to a base package via a custom layer after deploying the base layer.

How can I do this?


I am aware how to persistently change a kernel variable by updating /etc/sysctl.conf (or, preferably, /etc/sysctl.d/xxx.conf). My question is, how to generate the Linux image with the necessary update applied?


Solution

  • You can add something like this in image recipe or local.conf:

    set_kernel_opt(){
        mkdir -p ${IMAGE_ROOTFS}/etc/sysctl.d
        echo 'kernel.core_pipe_limit = 1' > ${IMAGE_ROOTFS}/etc/sysctl.d/kernel_core_pipe_limit.conf
    }
    
    ROOTFS_POSTPROCESS_COMMAND += "set_kernel_opt;"
    

    If you want to override /etc/sysctl.conf file, you can create a meta-custom/recipes-extended/procps/procps_%.bbappend file with:

    FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
    

    Then create a folder meta-custom/recipes-extended/procps/files and copy your custom sysctl.conf file in it.


    Finally you can create a meta-custom/recipe-custom/custom-config/custom-config.bb recipe with:

    LICENSE = "CLOSED"
    
    SRC_URI = " \
       file://kernel_core_pipe_limit.conf \
    "
    
    PV = "1.0"
    
    S = "${WORKDIR}"
    
    inherit allarch
    
    do_install() {
        install -d ${D}${sysconfdir}/sysctl.d
        install -m 0644 ${B}/kernel_core_pipe_limit.conf ${D}${sysconfdir}/sysctl.d/
    }
    
    do_configure[noexec] = "1"
    do_compile[noexec] = "1"
    

    And copy your kernel_core_pipe_limit.conf in meta-custom/recipe-custom/custom-config/files/