I want to mount the device /dev/sda3
to the directory /foo/bar/baz
. After mounting the directory should have the uid of user johndoe
. So I did:
sudo -u johndoe mkdir /foo/bar/baz
stat -c %U /foo/bar/baz
johndoe
and added the following line to my /etc/fstab
:
/dev/sda3 /foo/bar/baz ext4 noexec,noatime,auto,owner,nodev,nosuid,user 0 1
When I do now sudo -u johndoe mount /dev/sda3
the command stat -c %U /foo/bar/baz
results in root
rather than johndoe
. What is the best way to mount this ext4-filesystem with uid johndoe
set?
bindfs
is the answer. It will take an already mounted file system and provide a view of it with whichever uid you'd like:It's not possible to force an owner on a disk with an ext4 filesystem. Only filesystems which do not support Linux permissions like fat have an attribute for ownership/groupship:
uid=value
andgid=value
. See the manual page on mount.You should change the owner on the mounted filesystem as in:
If you need to change the permissions recursively:
...and if the group needs to be changed to
johndoe
as well:Assuming the group set for the files has appropriate permissions, you should be able to just find out it's Group ID (GID) and add yourself to it.
To find out the group id of a file, use
ls -n
. Example output:You want the fourth field for GID, which in my case is the second
1000
.Once you run that you should have full rein where ever the file attributes for group allow it.
As noted in the other answer relating to user permissions, if you need to fix the group on some files, run one of these: