2017-03-28 1 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를 사용하여 이미지가 처리되기 전에 직접 기능을 설정하고 있습니다.