Yocto - 根据图像类型选择正确的配置文件 [英] Yocto - select the right configuration file based on image type

查看:29
本文介绍了Yocto - 根据图像类型选择正确的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我非常标准的 Yocto 构建中,我包含了 openssh.它的配置文件,/etc/ssh/sshd_config,对于生产和开发映像自然应该是不同的(例如,一个人希望在开发映像上而不是在生产映像上以 root 登录).生产和开发图像是我层下的 recipes-core/images 中不同的配方(.bb 文件),其中还包括一些其他内容.为了实现对 sshd_config 文件的自定义,我在我的层下创建了 recipes-connectivity/openssh 目录,使用 openssh_%.bbappend 和仅以下内容:

In my pretty standard Yocto build I have the openssh included. Its configuration file, /etc/ssh/sshd_config, should naturally be different for production and development images (for example one would like root login on development image and not on production one). The production and the development images are different recipes (.bb files) in recipes-core/images under my layer, which includes some other stuff as well. In order to achieve customization for the sshd_config file, I've created recipes-connectivity/openssh directory under my layer with openssh_%.bbappend with just the following content:

SUMMARY = "OpenSSH configuration"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

files 目录中,我有自己的sshd_conf.这工作正常,使用我的文件而不是 openssh 的默认文件.但是我怎么能有两个单独的文件来影响两个不同的结果 rootfs?我见过的最接近的是 this问题这个答案似乎太简单了,不可能是真的.我已经尝试将我的图像名称用于文件夹,但我得到的只是两个生成的图像构建中的默认 conf 文件.第二个答案接缝合理,但 AFAIK 我无法替换来自其他配方的文件(如果我错了,请纠正我),所以对于有效的 OP 来说,这可能是一个非常具体的案例.运行安装后脚本不是一种选择,因为 rootfs 在目标上是只读的.研究手册中的 _append_xxxx 内容也没有将我推向正确的方向.

And in the files directory, I've got my own sshd_conf. This works fine, my file is used instead of openssh's default one. But how can I have, say, two separate files that will affect the two different resulting rootfs's? The closest I've seen is this question, and this answer seems just too simple to be true. I've tried using my image names for folders, but all I got is the default conf file in both resulting image builds. The second answer seams reasonable, but AFAIK I can't replace a file coming from other recipe (please correct me if I'm wrong), so probably that was quite a specific case for the OP that worked. Running a post-install script is not an option, since the rootfs is read-only on the target. Studying the _append_xxxx stuff in the manual did not push me to the right direction as well.

希望有人可以分享一些经验,因为这似乎是一个非常简单的问题,应该有一些内置的解决方案.

Hope someone could share some experience on that, as this seems a pretty straightforward issue that should have some built-in solution.

谢谢.

推荐答案

通过迄今为止我收到的友好帮助和其他几个答案,我找到了一个可行的解决方案.

With the kind help I've received so far and several other answers, I've reached a working solution.

在我的层中有recipes-connectivity/openssh/openssh_%.bbappend,内容如下:

In my layer there's the recipes-connectivity/openssh/openssh_%.bbappend with the following contents:

do_install_append () {
    rm ${D}${sysconfdir}/ssh/sshd_config
}

这会删除由原始 openssh 配方安装的 sshd_config 文件.

This removes the sshd_config file installed by the original openssh recipe.

接下来,我的层中有两个额外的配方:recipes-core/openssh_conf_prod/openssh_conf_dev_0.1.bbrecipes-core/openssh_conf_prod/openssh_conf_prod_0.1.bb.在 files 子目录下的两个配方目录中,都有一个 opensshd_conf 文件,对于 devprod 来说是不同的.不过,对于这两种情况,.bb 配方相同:

Next, there are two additional recipes in my layer: recipes-core/openssh_conf_prod/openssh_conf_dev_0.1.bb and recipes-core/openssh_conf_prod/openssh_conf_prod_0.1.bb. In both recipe directories under files subdirectory there's an opensshd_conf file, different for dev and prod. The .bb recipes are identical for both cases, though:

DEPENDS = "openssh"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

SRC_URI = "file://sshd_config"

S = "${WORKDIR}"

do_install() {
    install -d ${D}${sysconfdir}/ssh
    install ${WORKDIR}/sshd_config ${D}${sysconfdir}/ssh
}

(*) 注意开头的 DEPENDS.

(*) Note the DEPENDS in the beginning.

配方所做的只是验证是否存在要将文件复制到的目标目录,并将其在 files 目录下的文件复制到目标 rootfs.

What the recipe does is just verifies there's a destination directory to copy the file to, and copies the file it has under the files directory to the target rootfs.

然后,当然,我配方的recipes-core/images 目录下的proddev 图像文件包含每个相关的openssh_conf_devopenssh_conf_prod 配方,例如 CORE_IMAGE_EXTRA_INSTALL_append 变量.

Then, of course, the prod and dev image files under my recipe's recipes-core/images directory include each the relevant openssh_conf_dev or openssh_conf_prod recipes under, for example, the CORE_IMAGE_EXTRA_INSTALL_append variable.

总结一下,流程是:

  1. openssh 正在按照图像配方的要求进行安装.
  2. sshd_config 正在被 openssh 的新 .bbappend 配方删除.
  3. 每种类型的图像调用自己的配方,将正确的配置文件添加到正确的文件夹中.
  1. openssh is being installed as required by the image recipe.
  2. The sshd_config is being deleted by the new .bbappend recipe for openssh.
  3. Each type of image calls its own recipe, which adds the right configuration file to the right folder.

我不确定这有多优雅,但它确实有效.

I am not sure how elegant this is, but it does the job.

这篇关于Yocto - 根据图像类型选择正确的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆