At work I’m trying to set up an NFS mount on my desktop. Our servers mount a given directory on our filer as /auto. I want to do the same thing on my (Ubuntu) PC so that I don’t have to ssh to the server to do my development anymore. Our filer is (for the sake of this post) company-filer05.
I want to access company-filer05/projects as /auto on my computer and company-filer05/company-linux-rhel4.0-x86-32 as /usr/company for access to things like perl (binaries and modules).
I’m pretty new to network file sharing (NFS), so I’m trying to figure out how it all works. I found a lot of guides that worked a little bit, but nothing that worked for me completely. I should mention that my PC is behind the company firewall, so I didn’t have to deal with that. This is what I finally did to get it working.
First, create the directory that will act as the mount point.
| Create the local directory you'll use to access the remote files. | |
1 | sudo mkdir /auto |
Notes
- I used sudo because I’m making the file at root /.
- If you do not do this step, you will get this error when you try to execute the mounts:
1mount error: can not change directory into mount target /auto
Next, open your /etc/fstab file. I use vim, though you can use gedit or anything else, of course.
| Edit your /etc/fstab file. | |
1 | sudo vim /etc/fstab |
The file should look something like this:
| A default /etc/fstab file. | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda2 UUID=0a3618da-0ebf-446e-a58e-56927ed6af3e / ext3 defaults,errors=remount-ro,relatime 0 1 # /dev/sda4 UUID=e0712dd8-8e27-4498-934b-39db3d99821a /home ext3 defaults,relatime 0 2 # /dev/sda3 UUID=23023707-e2a4-4cfc-867f-c08792e26873 /share ext3 defaults,relatime 0 2 # /dev/sda1 UUID=46c1d2f4-b189-4b6e-9223-3d284ea4ab2e none swap sw 0 0 /dev/hda /media/cdrom0 udf,iso9660 user,noauto,exec 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto,exec 0 0 |
Add the following line to the bottom (or anywhere, I guess) to mount company-filer05/projects as /auto:
| Set the up the mount map in /etc/fstab | |
1 2 | ### Mount /auto from rtp-filer04b. //company-filer05/projects/ /auto cifs credentials=/home/username/.smb_credentials,dir_mode=0777,file_mode=0777 0 0 |
Save and close the file.
Notes
- I used sudo because this is a system file that I can’t edit without admin privileges.
- Instead of cifs, use smb if that’s better for your setup. Search on Google for cifs vs. smb to find out more.
- Note that we set the dir_mode and file_mode parameters. That acts as a mask to give us these permissions (0777) on all mounted files. Does anyone know how to make it give true, unmasked permissions?
- Notice that we set a credentials file (credentials=/home/username/.smb_credentials). We haven’t created that, but we will in the next step. It will contain our username and password to access the filer.
We’re almost done. Next, let’s create the credentials file that will hold our username and password to the filer. We do that instead of putting it into the fstab file so that our password isn’t just plainly visible to anyone. Replace “my_username” and “my_password” below with your username and password respectively, of course.
| Create the ~/.smb_credentials file that contains our filer username and password. | |
1 2 3 | # Create the file. echo "username=my_username" >> .smb_credentials echo "password=my_password" >> .smb_credentials |
Your ~/.smb_credentials file should now look like this:
| A sample ~/.smb_credentials file. | |
1 2 | username=my_username password=my_password |
Almost done. Now all we have to do is mount the files. We’ll use the mount command with the -a (Mount all filesystems (of the given types) mentioned in fstab) option.
| Manually execute the system mounts. | |
1 | sudo mount -a |
If everything worked, you won’t get any messages. To check if it worked, just go to the mount point and check if it now has the remote contents. You can do this for as many mount points as you like, of course.
I do have one outstanding question myself: I don’t want the files to be masked with 0777 — or anything else. I would like to have them be whatever they really are on the server, but I don’t know how to do that. Does anyone else?
