Monday, April 23, 2012

Mac Os X: Mount NFS Share / Set an NFS Client

How do I access my enterprise NAS server by mounting NFS filesystem onto my Mac OS X based system using GUI and command line based tools?

NFS (Network File System) is the common for file sharing on NAS server and Linux / UNIX systems like, HP-UX, Solaris, Mac OS X, and others. Mac OS X can be setup as an NFS client to access shared files on the network.

Our Sample Setup

        nas01                                   Laptop/Desktop
+--------------+ +--------+
| UNIX/Linux | | Mac |
| NFS +---------------------------+ OS X |
| SERVER | mount nas01:/mp3 /nfs | Client |
+--------------+ +--------+
| (192.168.3.100)
(shared dirs)
/
--/Sales
--/Mp3
--/Data
--/wwwroot
(192.168.3.1)
nas01 allows your users or client compute to access files over a network. Mac OS can mount file system over a network and work as they are mounted locally. This is perfect for sharing files or centralized home directories. See how to setup an NFS server under RHEL / CentOS Linux and Ubuntu Linux here.

How Do I Find Out Shared Directories?

To mount an NFS file system, the resource must be made available on the NAS or NFS server. To verify that resource available open the terminal and type the following command:
$ showmount -e nas01
$ showmount -e nfs-server-ip-address-here
$ showmount -e nas01.lan.nixcraft.net.in

Sample outputs:
Fig.01: UNIX showmount command lists all clients that have remotely mounted a filesystem from NFS server
Fig.01: UNIX showmount command lists all clients that have remotely mounted a filesystem from NFS server
The showmount command show remote NFS mounts (resources).

Mac OS X Nfs mount Command

First, create a directory to mount an nfs share, enter:
$ sudo mkdir /private/nfs
$ sudo mkdir /private/mp3

To mount an NFS file system, enter:
$ sudo mount -t nfs nas01:/mp3 /private/nfs
OR
$ sudo mount -t nfs 192.168.3.1:/mp3 /private/nfs

Tip: Operation not permitted Error

If you get an error which read as follows:
 192.168.3.1:/mp3 Operation not permitted
Try to mount it as follows with -o resvport command:
$ sudo mount -t nfs -o resvport 192.168.3.1:/mp3 /private/nfs
From the man page:
resvport
Use a reserved socket port number. This is useful for mounting
servers that require clients to use a reserved port number on the
mistaken belief that this makes NFS more secure. (For the rare
case where the client has a trusted root account but untrustwor-
thy users and the network cables are in secure areas this does
help, but for normal desktop clients this does not apply.)

Verify: NFS Is Working or Not

Type the following commands:
$ df -H
$ cd /private/nfs
$ ls -l

Sample outputs (note I've mounted it at /private/mp3/ dir):
Fig.02: UNIX df command
Fig.02: UNIX df command which displays information about total space and available space for NFS

How Do I Copy Files?

Use the cp command:
$ cp /path/to/file.doc /private/nfs/
$ cp -a /path/to/*pl /private/nfs/
$ cp /private/nfs/mp3/*.mp3 ~/mp3

Using the Finder

The Finder is the default file manager used on the Mac OS and Mac OS X operating systems that is responsible for the overall user-management of files, disks, network volumes and the launching of other applications. Open Finder > Shared (select from the left sidebar) > NFS server (nas01 or 192.168.3.1):
Fig.03: The Finder in action (browse an NFS share)
Fig.03: The Finder in action (browse an NFS share)

Now, you can copy and paste files as usual.

Recommend mount Command Options

I suggest that you run the mount command it as follows to get better a performance:
$ sudo mount -t nfs -o soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp nas01:/sales /private/sales
OR
$ sudo mount -t nfs nfs -o soft,timeo=900,retrans=3,vers=3, proto=tcp nas01:/sales /private/sales
See mont_nfs(8) for more information.

GUI Method: HowTo Set Mac OS X As an NFS Client

To mount an NFS share from OS X using GUI tools, follow these steps:
[1] Start Finder, and go to Applications / Utilities / Disk Utility:
Fig.04: Starting Disk Utility
Fig.04: Starting Disk Utility

You will see the disk utility as follows:
Fig.05: Click the 'Mounts' icon at the top of the Directory Utility panel
Fig.05: Click the 'Mounts' icon at the top of the Directory Utility panel
[2] Alternatively, you can select "Disk utility" > click on File > Mount NFS as follows:
Fig.06: Mounting an NFS using - Disk Utility > File > Mount option
Fig.06: Mounting an NFS using - Disk Utility > File > Mount option

You will see an "NFS mounts" window as follows:
Fig.07: OS X NFS Mounts to set it as an NFS Client
Fig.07: OS X NFS Mounts to set it as an NFS Client

[3] Click on "+" icon:
Fig.08: Setting up an NFS mount options in the dialog box
Fig.08: Setting up an NFS mount options in the dialog box

You need to enter your remote NFS server URL (IP address or dns name) in the following format:
nfs://192.168.3.1/mp3
nfs://nas01/mp3

Where,
  1. 192.168.3.1: NFS server IP address.
  2. nas01: NFS server dns name.
  3. mp3: Shared nfs directory name.
You need to set mount location as follows:
/Volumes/mp3
/Volumes/mp3 is nothing but the mount location. This is a convenient place. In this example, you entered the URL as nfs://192.168.3.1/mp3, enter /Volumes/mp3 as the mount location. Please note that don't create the subdirectory (mp3); it will be created dynamically when the share is mounted.

Optional

Click the arrow in front of "Advanced Mount Parameters". A new text entry box is displayed. Enter: resvport (this is only required if you get some sort of error [see above for more info or read mount_nfs man page]).
[4] Finally, click "Verify" button at the bottom right:
Fig.09: Verify NFS mount configuration which only checks that your NFS server is enabled and working correctly.
Fig.09: Verify NFS mount configuration which only checks that your NFS server is enabled and working correctly.

[5] You will see a popup window, stating that "The NFS server appears to be functional" > Click "OK" button to continue. Finally, Click "Save" button. You may be prompted for the password to make changes. Your NFS share should appear at the mount location you entered above i.e. /Volumes/mp3.
Fig.10: NFS Share mounted
Fig.10: NFS Share mounted
You can access /Volumes/mp3 using the Finder:

Fig.11: The finder in action
Fig.11: The finder in action

You can also use command line options:
$ ls /Volumes/mp3
$ cd /Volumes/mp3
$ cp /path/to/something.file.in file.out
$ rsync -av user@server3.nixcraft.com:/var/www/html/ server.backups/

See also:

  • Ubuntu Linux: NFS Client Configuration To Mount NFS Share
  • Mount NFS file system over a slow and busy network

No comments:

Post a Comment