13

I'm trying to mount an ext3 file system from another Linux installation so that the user, not root, will have full access to all the files. (I really do need user to have access to those files, because I would like to use them from another computer via sshfs, and sshfs will only give the user's access rights to the files.)

If I run mount /dev/sda1 /mnt/whatever all files are only accessible by root.

I've also tried mount -o nosuid,uid=1000,gid=1000 /dev/sda1 /mnt/whatever as instructed by a SuperUser question discussing ext4 but that fails with an error, and dmesg reports:

EXT3-fs: Unrecognized mount option "uid=1000" or missing value

How can I mount the filesystem?

Anthony Geoghegan
  • 12,605
  • 7
  • 59
  • 62
Ilari Kajaste
  • 325
  • 1
  • 2
  • 6
  • 1
    I'd say that [Gilles' answer](http://superuser.com/questions/196653/how-do-i-manually-mount-a-linux-file-system-read-write-as-a-normal-user/196684#196684) in the SuperUser question you mentioned is the correct one. Indeed, then [man page mount(8)](http://linux.die.net/man/8/mount) does not list `uid=...` and `gid=...` options for none of the ext2/3/4 filesystems. – Riccardo Murri Jun 09 '11 at 11:26
  • @Riccardo Thanks, that was the correct solution! First mounting the ext into some directory regularly, then mounting that directory with `bindfs -u $(id -u) -g $(id -g)` into the final destination. Write it up as an answer, maybe? – Ilari Kajaste Jun 09 '11 at 12:21
  • 1
    Since the answer is [Gilles'](http://unix.stackexchange.com/users/885/gilles) and he's very active on this forum as well, I'll leave it up to him to re-post it here and collect the deserved credit. – Riccardo Murri Jun 09 '11 at 12:51

1 Answers1

21

On an ext4 filesystem (like ext2, ext3, and most other Unix-originating filesystems), the effective file permissions don't depend on who mounted the filesystem or on mount options, only on the metadata stored within the filesystem.

If you have a removable filesystem that uses different user IDs from your system, you can use bindfs to provide a view of any filesystem with different ownership or permissions. The removable filesystem must be mounted already, e.g. on /mnt/sda1; then, if you want a particular user to appear as the owner of all files, you can run something like

mkdir /home/$user/sda1
bindfs -u $user -g $group /mnt/sda1 /home/$user/sda1
Anthony Geoghegan
  • 12,605
  • 7
  • 59
  • 62
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 1
    Thank you from me as well! With a little tweak, this also works for devices like e. g. hot-plugged SATA DVD-ROMs (which was the device I had problems with). HOWEVER, the device will always be mounted `000` for some reason (d---------) so you have to specify `-p 700` to the `bindfs` line to access the files on the DVD via `dolphin`/`nautilus` etc., for instance. – syntaxerror Nov 17 '13 at 23:27
  • Would be nice if `bindfs` could accept dictionaries for translating any set of UIDs and GIDs... – Alexey Dec 24 '16 at 14:42