16

I can successfully mount an ext4 partition, the problem is that all the files on the partition are owned by the user with userid 1000. On one machine, my userid is 1000, but on another it's 1010. My username is the same on both machines, but I realise that the filesystem stores userids, not usernames.

I could correct the file ownership with something like the following:

find /mnt/example -exec chown -h 1010 {} \;

But then I would have to correct the file ownerships again back to 1000 when I mount this external drive on another machine.

What I would like is to give mount an option saying map userid 1000 to 1010, so that I don't have to actually modify any files. Is there a way to do this?

  • I search for this question a year and a half later, found this, wanted to upvote, only to discover that I asked this question myself! – Flimm Mar 31 '16 at 9:13
  • You can still make it a favourite, even if you can't upvote :-O – Anthon Mar 31 '16 at 9:19
19

Take a look at the bindfs package. bindfs is a FUSE filesystem that allows for various manipulations of file permissions, file ownership etc. on top of existing file systems.

You are looking specifically for the --map option of bindfs:

--map=user1/user2:@group1/@group2:..., -o map=...
    Given a mapping user1/user2, all files owned by user1 are shown as owned by user2. When user2 creates files, they are chowned to user1 in the underlying directory. When files are chowned to user2, they are chowned to user1 in the underlying directory. Works similarly for groups.

    A single user or group may appear no more than once on the left and once on the right of a slash in the list of mappings. Currently, the options --force-user, --force-group, --mirror, --create-for-*, --chown-* and --chgrp-* override the corresponding behavior of this option.

    Requires mounting as root. 

So to map your files with user id 1001 in /mnt/wrong to /mnt/correct with user id 1234, run this command:

sudo bindfs --map=1001/1234 /mnt/wrong /mnt/correct
| improve this answer | |
  • I'm getting fuse: unknown option `--map=1004/1002' on my Ubuntu 12.04.5 LTS server. I wonder if my version of bindfs or fuse is outdated... – Zero3 Dec 7 '15 at 17:33
1

You can use bindfs. It can bind the filesystem to some other mountpoint with different uid/gid. However I think I would just change the uid so it is the same on both systems.

| improve this answer | |

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.