From f4b2a4244d61315133c8a3e5eaa0c37fa17f6870 Mon Sep 17 00:00:00 2001 From: Daniel Rossier Date: Mon, 28 Sep 2026 12:25:17 +0200 Subject: [PATCH] usr-linux: copy the user space without imposing the builder's ownership Both usr-linux:do_deploy copies (onto p2, and into the extracted tree re-packed as rootfs.cpio) ran `sudo rsync -a`. Run as root, -a also carries owner, group and mode over from build/deploy -- a tree the builder owns, 0775 -- onto the directories the rootfs already has: /, /root, /etc and /usr ended up owned by the builder, / group-writable, and /root lost its 0700. -rlt instead: recursive, symlinks, times. Without -o/-p the files are created root-owned with their source mode, and the existing directories keep their owner and mode. --keep-dirlinks and check=True are unchanged. Checked on virt64 (IB_RAMFS_SOURCE = "rootfs"): deploy.sh usr-linux, then rootfs.cpio lists /, /etc, /usr as root 0755 and /root as root 0700; the only non-root entries are buildroot's own service directories. --- build/meta-usr/recipes-usr/linux/usr-linux_1.0.bb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build/meta-usr/recipes-usr/linux/usr-linux_1.0.bb b/build/meta-usr/recipes-usr/linux/usr-linux_1.0.bb index 77a39b530..63587c568 100644 --- a/build/meta-usr/recipes-usr/linux/usr-linux_1.0.bb +++ b/build/meta-usr/recipes-usr/linux/usr-linux_1.0.bb @@ -81,8 +81,10 @@ python do_deploy() { # and a half-copied user space must not end up there. On failure the # tree is dropped and rootfs.cpio stays as it was; the next deploy # starts over from it. + # + # -rlt, not -a: see the p2 copy below. try: - utils_sudo(["rsync", "-a", "--keep-dirlinks", + utils_sudo(["rsync", "-rlt", "--keep-dirlinks", deploy_src + "/", f"{IB_ROOTFS_PATH}/fs/"], check=True) except Exception: utils_sudo(["rm", "-rf", os.path.join(d.getVar('WORKDIR'), "fs")]) @@ -115,9 +117,15 @@ python do_deploy() { # rootfs directory symlinks (e.g. /lib -> usr/lib) instead of replacing # them with real directories. check=True: a failed copy must fail the # deploy, not leave a rootfs silently without the apps. + # + # -rlt, not -a: run as root, -a also imposes the build tree's owner and + # mode on the directories the rootfs already has -- /, /root, /etc and + # /usr end up owned by the builder (/ group-writable) and /root loses + # its 0700. Without -o/-p the files are created root-owned with their + # source mode, and the existing directories keep theirs. try: - utils_sudo(["rsync", "-a", "--keep-dirlinks", + utils_sudo(["rsync", "-rlt", "--keep-dirlinks", deploy_src + "/", rootfs_dst + "/"], check=True) finally: __do_fs_umount(d)