By-passing default permissions when mounting HFS+ volumes in linux

8,553

Solution 1

bindfs is the answer. It will take an already mounted file system and provide a view of it with whichever uid you'd like:

sudo apt-get install bindfs
mkdir ~/myUIDdiskFoo
sudo bindfs -u $(id -u) -g $(id -g) /media/diskFoo ~/myUIDdiskFoo

Edit:

Also, reading the doc I realized that the map option (1.10 and later) might fit better:

sudo bindfs --map=502/1000 /media/diskFoo ~/myUIDdiskFoo

Solution 2

Actually I'm looking to do something similar when I've come across this question. Is my understanding, looking from your first post, that the mount option requested is asking what user uid should be used instead of the default of your linux system( ie uid 1000). So instead you should be using 502 which is the expect owner of the file system you're trying to mount.

I've tested this in my own situation, and it worked great, with uid 99 for a filesystem to shared between my systems. With this I won't need to go around changing uids. So thanks for sharing. This may not be of much for you anymore but may help someone else. Cheers

Solution 3

In the end, I created a linux user with the same UID of my mac os x user, but it can't browse every directory in my home on mac hfs+ volume because a lot of files were owned by mac user "unknown", UID 99 (see http://googlemac.blogspot.com/2007/03/user-99-unknown.html).

It seems that they did so to let you mount and read your volume when you connect it to a different computer. When a regular user look at those files owned by UID 99, he sees them as he is their owner. Quite strange. Only root sees them as they are.

So I rebooted in Mac Os X, logged in with a different user with administrative privileges and used chown -R 502:20 /Users/gerlos/* to change the owner of every file in my home. Now I can read everything without any problem.

Remarks:

  • default kubuntu gui tool to create new users on Kubuntu 11.10 can't create users with UID less than 1000. Use adduser on the terminal instead.
  • you can know your user UID using the "id" command on the terminal.
  • on mac os x, you need to be root to see the real owner of the files. So expect different results if you type "ls -n /Users/gerlos" and "sudo ls -n /Users/gerlos".
Share:
8,553

Related videos on Youtube

gerlos
Author by

gerlos

bio I'm just someone curious about Nature, Science and Tech. Love astronomy, photography, FLOSS and freedom. "It's not who you are underneath - it's what you do that defines you." Sono un tipo curioso di Natura, Scienza e Tecnologia. Amo l'astronomia, la fotografia, il software libero e la libertà. "Non è tanto chi sono quanto quello che faccio che mi qualifica..."

Updated on September 18, 2022

Comments

  • gerlos
    gerlos over 1 year

    I have a dual booting macbook pro with Snow Leopard and Kubuntu 11.10, and want to read (don't care about write) my home Mac home directory when I'm running Kubuntu.

    I can mount it without any problems, but my user on Kubuntu on can't see the files on the HFS+ owned by the mac user, because of different uid (502 on Mac, 1000 on Kubuntu).

    Looking at kernel docs about HFS+ I read that:

    When mounting an HFSPlus filesystem, the following options are accepted:
    [CUT]
        uid=n, gid=n
            Specifies the user/group that owns all files on the filesystem
            that have uninitialized permissions structures.
            Default:  user/group id of the mounting process.
    

    So I tried using these options:

    $ sudo mount -t hfsplus -o uid=1000,gid=1000 /dev/sda2 /mnt/Mac
    

    But they seem doing nothing: I still see the same permissions when I look around using ls -l. I may be missing something, any clue?

    I know that I can change my user id on Ubuntu to match it with Mac Os X, but I'd prefer avoiding it if possible.

  • gerlos
    gerlos over 10 years
    That difference in OSX between the "real" unix user and the user recognized by the Finder gave me a lot of headache... it can even make some apps on OSX behave strangely (eg. Dropbox won't sync your files). To avoid any problem, log in your OSX system, open a terminal and make sure your unix user owns everything your OS X user already owns. Maybe I don't understand something, but in my experience using the GUI isn't enough.
  • gerlos
    gerlos over 10 years
    Very cool solution. It solves the problem without changing default behaviours the OSes, and makes possible a lot of more options. Just be careful if the system is shared with other users, this may expose private files to unexpected audience.
  • Catskul
    Catskul over 10 years
    Yeah. I was surprised that the system mount utility doesn't offer this ability. Alternatively you can use bindfs' map functionality to simply map user 502 to 1000 which might be safer and more of what you had intended.
  • gerlos
    gerlos over 10 years
    Right. Best solution is to leave alone UIDs and permissions, mount your HFS+ file system as you normally do, and then mount your home under the HFS+ file system using bindfs, so everything appears to be owned by your linux user. This way you won't ever need to use custom UIDs, neither to change permissions in HFS+ file system, so you preserve the default behaviour in both systems. Since you can remount with bindfs each user's home, you can preserve private files even in shared systems, still keeping them accessible to users.
  • J. Simon van der Walt
    J. Simon van der Walt almost 7 years
    As I don't have the reputation to comment, I'm just going to note that there is a small mistake in Catskul's answer, an = missing, should be: sudo bindfs --map=502/1000 /media/diskFoo ~/myUIDdiskFoo
  • Admin
    Admin almost 2 years
    Consider rather --mirror=<user name> option.