2017-03-28 14 views
2

Linuxの機能(例:CAP_NET_ADMIN)をいくつか与えたいと思います。 私はYoctoを使用しています。私のファイルシステムは読み取り専用でなければならず、ソフトウェアをフラッシュした後に変更してはいけません(これは通常動作するsetcapでpkg_postinstができないことを意味します)。yoctoを使用したLinuxの機能

ターゲットの起動後にファイル構造を変更せずにファイルに機能を与える方法はありますか?

答えて

1

pkg_postinstスクリプトは、読み取り専用のrootfsを構築している間にすでに実行されているため、このアプローチが有効です。ただし、スクリプトで呼び出すコマンドがビルドホストで使用可能であることを確認する必要があります。そうしないと、スクリプトの実行が失敗し、デバイスの最初の起動まで延期されます。 setcapコマンドが利用可能であることを確認する方法は、Yoctoリリースに依存します。これはYocto 2.3で変更されます。ここに完全な例のレシピがあります:

LICENSE = "MIT" 

do_install() { 
    install -d ${D}/${bindir} 
    touch ${D}/${bindir}/foobar 
} 

pkg_postinst_${PN}() { 
    setcap cap_chown+e "$D/${bindir}/foobar" 
} 
# Dependency when installing on the target. 
RDEPENDS_${PN} = "libcap" 
# Dependency for rootfs construction, Yocto > 2.3. 
PACKAGE_WRITE_DEPS = "libcap-native" 
# Dependency for rootfs construction, Yocto <= 2.3 (untested). 
# Enabling this makes builds slightly less efficient with 
# Yocto > 2.3 because it implies that libcap-native is 
# needed for building this recipe, which isn't the case. 
# DEPENDS += "libcap-native" 

xattrsを保存するように注意してください。デフォルトの.tarイメージ形式はそれらを削除します。 https://github.com/01org/meta-intel-iot-security/blob/master/meta-security-framework/classes/xattr-images.bbclassの先頭から:

# xattr support is expected to be compiled into mtd-utils. We just need to 
# use it. 
EXTRA_IMAGECMD_jffs2_append = " --with-xattr" 

# By default, OE-core uses tar from the host, which may or may not have the 
# --xattrs parameter which was introduced in 1.27. For image building we 
# use a recent enough tar instead. 
# 
# The GNU documentation does not specify whether --xattrs-include is necessary. 
# In practice, it turned out to be not needed when creating archives and 
# required when extracting, but it seems prudent to use it in both cases. 
IMAGE_DEPENDS_tar_append = " tar-replacement-native" 
EXTRANATIVEPATH += "tar-native" 
IMAGE_CMD_TAR = "tar --xattrs --xattrs-include=*" 

これは重要な場合は、画像レシピに入れてください。

+0

お返事ありがとうございます。問題は、ホスト上でスクリプトが失敗しないようにする方法です。スクリプトが失敗するエラーが発生しました:setcapのExecフォーマットエラー – Quizard

+0

私たちはmkfs.ubifsを使用しています。これはxattrsを保存しますか? – Quizard

+0

依存関係をどのように宣言する必要があるのか​​をもう一度理解しました。それは現在文書化されていません。ドキュメントのバグもあります:https://bugzilla.yoctoproject.org/show_bug.cgi?id=11274 –

0

最後に、mtd-utilsをmtd-utils-2.0.0にアップデートすることで問題を解決しました(mkfs.ubifsは拡張属性をサポートしています)。

さらに、IMAGE_PREPROCESS_COMMANDを使用して、イメージが処理される直前に機能を設定しています。

関連する問題