1

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?

8
  • I am not familiar with their usage myself, but Linux Capabilities look promising. Dec 4, 2015 at 13:11
  • @FelixDietrich thanks for that. I took a look, but it doesn't seem to obvious! Dec 4, 2015 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. Dec 5, 2015 at 10:38
  • Thanks @FelixDietrich. I'm currently thinking that the "correct" solution for this is something around fakeroot. Dec 6, 2015 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. Dec 9, 2015 at 4:20

1 Answer 1

0

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:

--numeric-owner
Always use numbers for user/group names.

--xattrs
Enable extended attributes support.

1
  • The problem is creating with the correct permission in the first place. Jul 11, 2017 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .