我想设置一个自定义初始化脚本,以便在yocto的图像中启动时运行,我已经跟随correct answer here - 它与我想要的一样 - 并且因为我使用pyro版本我将这些变量设置为文档中所述的local.conf文件
DISTRO_FEATURES_append =“systemd”
VIRTUAL-RUNTIME_init_manager =“systemd”
DISTRO_FEATURES_BACKFILL_CONSIDERED =“sysvinit”
VIRTUAL-RUNTIME_initscripts =“”
问题是当系统启动时没有调用initscript.service,并且我在/ var / log / messages中找不到东西,尽管脚本和服务文件已经传输并且systemd存在。
我也尝试使用此选项替换yocto中的init
pkg_postinst_keyfile() { #where keyfile is a recipe is added to IMAGE_INSTALL_append
if [ x"$D" = "x" ]; then
logger "key file is added"
else
exit 1
fi
}
同样,我无法在日志中找到“密钥文件已添加”的声明,尽管执行了配方并且密钥文件按照预期从配方传输到图像。
那么,正确答案有问题吗?我看到它很好但我不知道问题出在哪里。如果有人能给我一个使用Vinit做等效的实例吗?
目标机器是“qemux86-64”
食谱
我有一个叫做meta-mylayer的图层,它的树是:
apt-image 是我在核心最小化及其内容之上构建的图像CONF / layer.conf
recipes-core / mylayer-initscript /(如上面的链接所述)
食谱核/图像/ apt-image.bb
SUMMARY = "An image which add the support of using deb package management"
inherit core-image
include recipescore/images/core-image-minimal.bb
IMAGE_FEATURES += "package-management"
IMAGE_INSTALL_append = "gnupg coreutils keyfile initscript"
IMAGE_LINGUA = " "
LICENSE = "MIT"
IMAGE_ROOTFS_SIZE ?= "16192"
PACKAGE_FEED_URIS = "http://<public ip here>/my-repo/yahia-repo/expiremental \"
PACKAGE_FEED_BASE_PATHS = "deb"
PACKAGE_FEED_ARCHS = "all"
pkg_postinst_keyfile() {
if [ x"$D" = "x" ]; then
logger "key file is added"
else
exit 1
fi
}
initscript配方和所有文件与链接中所述相同,没有任何变化。
如果您对密钥文件配方感兴趣,可以使用
#
# The goal of this recipe is to move keyFile to target machine so it can be used as public key for
# authoriztion of deb repo.
#
# Author: Yahia Farghaly
SUMMARY = "Move keyFile example to /deb_key"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://keyFile \
file://sources.list"
#to inform yocto where to package the file
FILES_${PN} += " /deb_key"
S = "${WORKDIR}"
do_install() {
install -d ${D}/deb_key
install -m 0755 keyFile ${D}/deb_key
}
当然,我做 bitbake apt-image
服务脚本
[Unit]
Description=start initscript upon first boot
[Service]
Type=simple
ExecStart=/bin/sh -c 'sleep 5 ; /usr/sbin/initscript.sh'
initscript.h
#!/bin/sh
logger "starting initscript"
# do some work here. Mount rootfs as rw if needed.
logger "initscript work done"
echo "hi yahia" > /deb_key/hello
我不确定yocto的rootfs结果是默认的rw还是r-only?
initscript recipe
SUMMARY = "Initial boot script"
DESCRIPTION = "Script to do any first boot init, started as a systemd service which removes itself once finished"
LICENSE = "CLOSED"
PR = "r3"
SRC_URI = " \
file://initscript.sh \
file://initscript.service \
"
inherit allarch systemd
NATIVE_SYSTEMD_SUPPORT = "1"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "initscript.service"
do_compile () {
}
do_install () {
install -d ${D}/${sbindir}
install -m 0755 ${WORKDIR}/initscript.sh ${D}/${sbindir}
install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/initscript.service ${D}${systemd_unitdir}/system
}
答案 0 :(得分:1)
通过以下对服务脚本的更改为我工作。
[Unit]
Description=start initscript upon first boot
[Service]
Type=simple
ExecStart=/bin/sh -c 'sleep 5 ; /usr/sbin/initscript.sh'
[Install]
WantedBy=multi-user.target