Wednesday, November 18, 2009

Automount Home Directories Over NFS in Linux

On RedHat Enterprise/CentOS...
assuming your home server is called "fs1" and is sharing out /home over NFS. You'll also want to make sure that both your home directory server and the server you're running autofs on has the same passwd/user info - ids, gids.

1. Make sure autofs is installed and running:

sudo chkconfig autofs on
sudo service autofs start

2. add "/home /etc/auto.home" to /etc/auto.master

3. create the file /etc/auto.home and add these lines:

* -fstype=nfs,rw,nosuid,soft fs1:/home/&

4. if you already have a /home dir, move it out of the way:

sudo mv /home /home.old

5. reload autofs

sudo service autofs reload

6. ls /home

You should see the users' home directories.


Anonymous said...

Thanks for this. I needed a quick tutorial on this.

Pablo Lemos Ochandio said...


Recently, Im trying to setup a system that use AD2003R2 as repository of users accounts and one redhat machine as server with some dmz services. My users can autenticate agains the ad2003r2 correct but when the oddjobd daemon (mkhomedir) try to create the home of the users into a netapp nas (export via NFS) i have a error:

"oddjob-mkhomedir[2445]: error creating /home/users/user1: Permission denied"

I have selinux disabled.

Could you help me?

THANKS a lot

Rivald said...

Sure. It sounds like the Netapp NAS is setting the uid 0 to nobody. On Linux, they call this no_root_squash. Oddjob is running as root - so if you can set the netapp to allow root to modify data, it should work.

If that won't work, you could possibly set the permissions on the share directory to 777 (rwxrwxrwx) but I would not recommend that.

Pablo Lemos Ochandio said...

Thanks a lot !!!

Im going to try it right now and tell you!!

Thanks again!!!

Pablo Lemos Ochandio said...

Hi Rivald!!

NO luck :_( . I setup a NFS server under a VM machine (redhat 6) to debug the process. The exports have the no_root_squash but i have the same problem.

The oddjob_mkhomedir can not make the home directory into the NFS server. The logs of the NFS server dont display anything relevant for that i think the problem is the oddjob service.

If i logon into the redhat machine and mount manually the export of the NFS and create the home directory i dont have the error of permission denied. For that i think the problem is the oddjob service :_(

Im very desesperate with that service :_(

Any suggestion??

Thanks a lot

Rivald said...

Hmmm - is selinux running on the machine running oddjob to create home directories?

You can do a getenforce. If it's enforcing, I'd suggest trying setenforce 0 and try to get oddjob to create the directory again.

Pablo Lemos Ochandio said...

Hi Rivald

Yes i have selinux disabled and iptables shutdown during my testing.

I modified the /etc/idmapd.conf parameter to refer my domain in both (server and client NFS)

and NFS and oddjob_mkhomedir works ok but when i try to use autofs to mount only the user's home dir during the logon obtain the permission denied message.

Im very frustrate. I think im quite close but there are a little step that i dont know it.


Rivald said...

I'll probably have to try a test of this myself with virtual machines. What OS are you running on the client machine? RHEL 6.x? I believe you said you are using RHEL 6 on the NFS server, correct?

Pablo Lemos Ochandio said...

Hi Rivald

My LAB have:

Windows2003R2 as LDAP server
RedHat Enterprise Linux v6 for logon users
CentOS v6 as NFS server to export home users

THANKS a lot

Rivald said...

I'm running into the same problem as you. I'll have to think about it. I think the problem is automounter itself, as the /home/users directory is a virtual directory. I'll take another look later in the day.

Pablo Lemos Ochandio said...

Thanks a lot for your interest!!!!

Ill wait ur progress !!!

Rivald said...

I have a work around. Since I've done minimal provisioning in this test environment, NFSv4 is problematic.

1. change the autofs mount to a direct mount of /home on the NFS server. This means it'll mount the entire directory - which might be a performance issue if you have a lot of users, but a dozen or so should be no problem. To change the map to a direct map:

edit /etc/auto.master:

remove /home/users /etc/auto.home (or whatever line you have for the home dir)

add a direct map like so:

/- /etc/

2. Inside /etc/, you'll want the line:

/home/users mynfs.server:/home

3. Set the system to prefer NFSv3 like so:

edit /etc/nfsmount.conf

change these two lines to 3 instead of 4:



4. restart autofs

oddjobd should be able to create the home directories automatically now. This works in my little lab config, at least. I'll fix my NFSv4 config shortly.

I think the problem is that autofs was trying to create a directory that should be a key for the automount map. So, if user bob logs in for the first time, your NFS client system was trying to create /home/users/bob. If you had tried to do a directory listing of /home/users/bob on this system before logging in with bob, it would have failed as it wouldn't be able to find the directory. Your NFS server would have reported:

Jun 4 21:06:26 mynfsserver rpc.mountd[39356]: can't stat exported dir /home/bob: No such file or directory

Automounter will block it from even attempting to create a new directory in /home/users.

More later, but you might want to give that a try. At least it's a work around.

Pablo Lemos Ochandio said...

Hi RIvald!!!

I finish to try your recommendations and works great!!!! You are right. It mount all the /home dir in my NFS netapp but it unmount it when i log off the machine and the autofs makes the home dir if the user is the first time that log in the machine

Im happy with the solution.


Selva Kumar said...

Have u tried configuring LDAP Server and client on RHEL7/CentOS7 with NFS for home directory sharing. pls check Configure LDAP Server Step by step

Debra J said...

Awesome post Rivald
after three days of trying to get autofs to work through auto.home, i did a direct map and it worked