I'm doing quite a bit of development using Yocto to target an embedded system.

As its final output, Yocto generates a tarball of the filesystem, which I then untar onto an ext4 partition of an SD card, which becomes the root filesystem of the embedded system.

In order to set all the permissions correctly on the SD card ext4 partition, I'm currently untarring the file using sudo, which means repeated operations deleting files and so on with root privileges - it's only a matter of time before I accidentally delete some system files due to an erroneous / or something.

Clearly I only need root with respect to the embedded filesystem, not my own machine.

Is there some way to untar the file as a normal user and end up with the correct UIDs on the resultant filesystem? It would be fine to change the way the device is mounted if that solves the problem. Or perhaps some chroot trick?

  • I am not familiar with their usage myself, but Linux Capabilities look promising. – Felix Dietrich Dec 4 '15 at 13:11
  • @FelixDietrich thanks for that. I took a look, but it doesn't seem to obvious! – Henry Gomersall Dec 4 '15 at 18:25
  • I played around with it a bit: I can untar an archive and set owner and permissions as normal user when I give tar the cap_chown and cap_fowner capabilities (setcap "cap_chown+ep cap_fowner+ep" /bin/tar; remove with setcap -r /bin/tar). Problem is: you have not contained tar to a path, and – if I understand capabilities correctly – tar can now set owner, permission, attributes of any file on your system regardless of access rights. One could try and contain tar with apparmor or SELinux, but I haven't looked into it. – Felix Dietrich Dec 5 '15 at 10:38
  • Thanks @FelixDietrich. I'm currently thinking that the "correct" solution for this is something around fakeroot. – Henry Gomersall Dec 6 '15 at 16:54
  • I don't think that fakeroot will help you when unpacking the archive: while you might not get errors when tar uses chown*/*chmod it will not actually succeed setting owner and permissions on the real system outside the fakeroot environment. – Felix Dietrich Dec 9 '15 at 4:20

Maybe tar's -p option is what you're looking for?

From man 1 tar:

-p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser)

--numeric-owner and --xattrs may also be of interest:

Always use numbers for user/group names.

Enable extended attributes support.

  • The problem is creating with the correct permission in the first place. – Henry Gomersall Jul 11 '17 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.