[英]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.我正在尝试使用Yocto 项目为我的嵌入式设备生成自定义 Linux 映像。
I have a requirement to add a persistent custom kernel parameter to /etc/sysctl.conf
of the generated image.我需要向生成的映像的
/etc/sysctl.conf
添加一个持久的自定义内核参数。
ie IE
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
). /etc/sysctl.conf
由Yocto
基础系统 ( meta/recipes-extended/procps/procps/sysctl.conf
) 附带的procps
包生成。 However, I believe editing the sysctl.conf
in the base system is not the recommended approach.但是,我认为在基本系统中编辑
sysctl.conf
不是推荐的方法。
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
).我知道如何通过更新
/etc/sysctl.conf
(或者,最好是/etc/sysctl.d/xxx.conf
)来持久地更改内核变量。 My question is, how to generate the Linux image with the necessary update applied?我的问题是,如何生成应用了必要更新的 Linux 映像?
You can add something like this in image recipe or local.conf
:您可以在 image recipe 或
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:如果你想覆盖
/etc/sysctl.conf
文件,你可以创建一个meta-custom/recipes-extended/procps/procps_%.bbappend
文件:
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
Then create a folder meta-custom/recipes-extended/procps/files
and copy your custom sysctl.conf
file in it.然后创建一个文件夹
meta-custom/recipes-extended/procps/files
并将您的自定义sysctl.conf
文件复制到其中。
Finally you can create a meta-custom/recipe-custom/custom-config/custom-config.bb
recipe with:最后,您可以创建一个
meta-custom/recipe-custom/custom-config/custom-config.bb
配方:
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/
并将您的
kernel_core_pipe_limit.conf
复制到meta-custom/recipe-custom/custom-config/files/
Just create a file with .conf
extension under /etc/sysctl.d
.只需在
/etc/sysctl.d
下创建一个扩展名为.conf
/etc/sysctl.d
。
echo 'kernel.core_pipe_limit = 1' > /etc/sysctl.d/bla_bla_change_kernel_core_pipe_limit.conf
From man sysctl :来自man sysctl :
--system
Load settings from all system configuration files. Files are
read from directories in the following list in given order
from top to bottom. Once a file of a given filename is
loaded, any file of the same name in subsequent directories is
ignored.
/run/sysctl.d/*.conf
/etc/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf
The sysctl --system
should be called on system startup. sysctl --system
应该在系统启动时调用。 On systems with systemd this is done via systemd-sysctl.service
service.在带有 systemd 的系统上,这是通过
systemd-sysctl.service
服务完成的。 Thus it should load all the /etc/sysctl.d
.因此它应该加载所有
/etc/sysctl.d
。 The syntax is the same as /etc/sysct.conf
syntax files.语法与
/etc/sysct.conf
语法文件相同。
The answer up there are wrong in my opinion.在我看来,上面的答案是错误的。 There is already a recipe providing sysctl.conf.
已经有一个提供 sysctl.conf 的方法。 It is
procps
.它是
procps
。 What you need to do is override the default configuration with a bbappend.您需要做的是使用 bbappend 覆盖默认配置。 More about append files on the online Yocto documention
有关在线 Yocto 文档中附加文件的更多信息
Create a procps folder, procps_%.bbappend and systctl.conf in recipes-extended in your layer such as创建一个procps文件夹, procps_%.bbappend和systctl.conf在 recipes-extended 层中,例如
meta-my-layer/recipes-extended/
└── procps
├── files
│ └── sysctl.conf
└── procps_%.bbappend
procps_%.bbappend : procps_%.bbappend :
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"`
(example of) sysctl.conf : (示例) sysctl.conf :
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
In case you want to keep default configuration and append to it, you only need a do_install_append step with an echo appending your text.如果您想保留默认配置并附加到它,您只需要一个do_install_append步骤,并在您的文本后附加一个 echo。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.