Some time ago, I had some trouble when mounting a directory from one linux computer onto another. I needed to simulate a shared file system so I could get Globus GRAM PBS jobmanager to work on my installation, composed of the two Linux nodes forming a cluster. As I did not have such a file system, I managed to get things to work by having the same user on both computers and exposing the .globus directory from the user's home directory in one of the nodes using Samba, and mounting that directory on the other node.
The thing is, when you have a cluster it makes sense that the home directory be shared (eg. using NFS, though in this case I used Samba). It is also usually the case that the same /etc/passwd is used, or NIS or LDAP based solutions are set up.
When the /etc/passwd file is shared, or in some other way the UID for each user accross the various computers is the same, sharing a directory as I wanted to do works fine. The problem I had was that I had set up a user on both computers for my tests, but the UID assigned to them was different on each one. So, when I mounted the directory I exposed on one computer onto the other, listing the files would show me the wrong owner on the latter. Actually, it would show me the name of the local user mapped to the UID that my test user had on the computer that exposed the directory - that is, the other computer.
Because of that problem, I had to resort to making the UID and GID for my test user equal on both computers. To achieve that, I found this interesting link: http://docsrv.sco.com:507/en/OSAdminG/uaT.chguid.html
Briefly, I first changed the GID for my test user to a new group id, so as for this GID to be the same on both computers (depending on the scenario, it may suffice with issuing the GID change command on just one computer, if the GID used on the other computer is available). To do this I used the command 'groupmod -g newGID groupName'. Before doing this, the previous GID number must be noted down somewhere as it will be needed later.
It was then necessary to update the GID of all files that previously referenced the now obsolete group number. This is done by finding all the files that reference the old GID, and issuing a chgrp command on them, executing ' find base_dir -group oldGID -print | xargs -t chgrp groupName'. If the user only had files inside the home dir, setting base_dir to that home directory should be enough.
Then, the user id must be updated. Again, depending on the scenario this may need to be done on one or both computers. The command ' usermod -g groupName -u newUID userName' changes the user id and sets its primary group membership to the appropriate group. The old UID must be noted down for use with the next command to be executed.
As with the GID change, some files will now be orphan. You can spot an orphan file because when you list it it will show the UID, i.e. the number, instead of the user name (the same applies to groups). For files inside the user's home directory, the UID will be updated automatically. For other files, it will be necessary to issue a 'find base_dir -user oldUID -print | xargs -t chown userName' command, which will find all files referencing the old UID and change their ownership to the user, thus effective updating the UID.
Now, when mounting the directory with 'mount -t smbfs -o username=userName,password=password,workgroup=WORKGROUP,uid=userName,gid=groupName //shared_dir local_dir' the right user and group will be shown on the computer in which local_dir resides. The uid and gid options are needed if the mount command is issued as a user other than userName, so that mounted files are owned by the user used for the tests.
No comments:
Post a Comment