2017-09-02 738 views
0

我想設置自定義的初始化腳本在啓動時yocto圖像中的跑,我也跟着correct answer here啓動 - 這是相同的,因爲我想 - 因爲我使用煙火版本我設置在local.conf檔案這些變量如文檔中所述與systemd運行啓動腳本在與yocto

DISTRO_FEATURES_append = 「systemd」

VIRTUAL-RUNTIME_init_manager = 「systemd」

DISTRO_FEATURES_BACKFILL_CONSIDERED = 「sysvinit的」

虛擬RUNTIME_initscripts =「」

的問題是,initscript.service不叫系統啓動的時候,我不覺得在/ var事/儘管腳本log/messages中和服務文件被傳輸並且systemd存在。

我也嘗試使用這個選項作爲替代的init在yocto

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」

食譜

我有一個被稱爲元mylayer層,它的樹是:

CONF/layer.conf

食譜核心/ mylayer-initscript /(如上述鏈接中所述)

食譜核心/圖片/ apt-image.bb

的apt-圖像是我上面核心最小的,其內容

SUMMARY = "An image which add the support of using deb package management" 

inherit core-image 
include recipes­core/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 
} 

啓動腳本食譜內置圖像和所有文件是跟沒有改變的鏈接規定相同。

,如果你有興趣有關密鑰文件的食譜,這裏是它

# 
# 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的貼切形象

服務腳本

[Unit] 
Description=start initscript upon first boot 

[Service] 
Type=simple 
ExecStart=/bin/sh -c 'sleep 5 ; /usr/sbin/initscript.sh' 

初始化腳本。^ 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的結果是,只有R默認值或RW?

啓動腳本配方

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

你能分享你的食譜嗎? – jku

+0

您尚未顯示實際安裝服務文件(我瞭解問題在哪裏)的配方或服務文件本身。至於替代方法,我不確定postinst是否要在圖像配方中工作,通常它是在生成postinst函數所用包的配方中定義的。 – jku

+0

@jku好的,我把它們 –

回答

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