使用yocto的Linux功能

使用yocto的Linux功能,linux,yocto,linux-capabilities,Linux,Yocto,Linux Capabilities,我想给几个文件提供Linux功能(例如CAP_NET_ADMIN)。 我使用的是Yocto,我的文件系统应该是只读的,在刷新软件后不得更改(这意味着不可能使用setcap进行pkg_postinst) 是否有其他方法可以在引导目标后不更改文件结构的情况下为文件提供功能?pkg\u postinst脚本在构建只读rootfs时已经被执行,因此这种方法是有效的。您必须确保在脚本中调用的命令在生成主机中可用,否则脚本的执行将失败,并延迟到设备上的第一次引导。如何确保setcap命令可用取决于Yocto

我想给几个文件提供Linux功能(例如CAP_NET_ADMIN)。 我使用的是Yocto,我的文件系统应该是只读的,在刷新软件后不得更改(这意味着不可能使用setcap进行pkg_postinst)


是否有其他方法可以在引导目标后不更改文件结构的情况下为文件提供功能?

pkg\u 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"

如果重要的话,请将其放入您的图像配方。

最后,我通过将mtd-utils更新为mtd-utils-2.0.0(mkfs.ubifs支持扩展属性)解决了这个问题


此外,我现在使用IMAGE_PREPROCESS_命令直接在处理图像之前设置功能。

谢谢您的回答。现在的问题是如何使脚本在主机上不失败。现在出现错误,脚本失败,setcapWe使用的是mkfs.ubifs:Exec format error。这会保留xattrs吗?我已经(再次)弄明白了依赖项现在需要如何声明。它目前还没有文档记录,文档错误也被归档了:我不知道ubifs如何处理xattrs。变量包_WRITE_DEPS在yocto 2.0中也可用吗?
# 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=*"