Linux: Mounting an NFS Share



  • If you followed my last example for creating a Simple NFS File Server and Share, we can now mount that share to another machine on our network. To get started, we need the IP address of the NFS Server that we will be mounting the share from (assuming that you are following my examples, this is the IP address of the server from the previous example.)

    We can start my listing all shares available from the NFS server. For our example, we will assume that the NFS server's IP address is 192.168.2.2. Make sure to always substitute your server's IP address.

    showmount -e 192.168.2.2

    This should show us the share that we created in the other example. If not, check your file server setup, make sure that you can ping the server, etc.

    Now, like with any filesystem, in order to use it we need a place to mount it. To make things quick and simple, there is a portion of the file hierarchy designated for this under /mnt. But you could mount anywhere that makes sense. A very common location would be something like /data. In our case, we will make a new spot at /mnt/nfs1

    mkdir /mnt/nfs1
    

    Now we can manually mount the share to this new location with the mount command. Other than a small extra amount of detail to tell the local system where the NFS share is located, nothing special is needed. The mount command will even detect the use of NFS automatically for us, so no need to speficy the filesystem in question.

    mount 192.168.2.2:/var/nfs_share1 /mnt/nfs1
    

    That is it. You should be able to "cd /mnt/nfs1" and create, read, modify files or whatever. You can view details about this mount point in the usual ways with things like the mount, df, and similar commands.

    Configure NFS Share to Mount at Boot Automatically

    Like other filesystems, we can make an NFS share be mounted automatically when our system boots. To do this, we add it to the /etc/fstab file where our other mounts are specified.

    vi /etc/fstab
    

    Navigate to the bottom of the file and for our mount point example, just add this line:

    192.168.2.2:/var/nfs_share1 /mnt/nfs1 nfs rw,sync,hard,intr 0 0
    

    Now you can reboot to verify that it mounts and is available after a system restart.


    Part of a series on Linux Systems Administration by Scott Alan Miller



  • I have always wished that the mount command had to switch to put the damn thing Into fstab.



  • @JaredBusch said in Linux: Mounting an NFS Share:

    I have always wished that the mount command had to switch to put the damn thing Into fstab.

    You mean like --perm and it just appended into fstab? That would rock.



  • @scottalanmiller said in Linux: Mounting an NFS Share:

    @JaredBusch said in Linux: Mounting an NFS Share:

    I have always wished that the mount command had to switch to put the damn thing Into fstab.

    You mean like --perm and it just appended into fstab? That would rock.

    Yeah pretty much anything like that



  • Can you explain why if I just mount an NFS share, using the command below, I can get a data transfer/throughput speed of approx 300 MB/s

    mount 192.168.2.2:/var/nfs_share1 /mnt/nfs1
    

    BUT,

    If I put an entry in fstab, it dramatically slows the transfer to about 35-40 MB/s

    192.168.2.2:/var/nfs_share1 /mnt/nfs1 nfs rw,sync,hard,intr 0 0
    

    What causes that?



  • @fuznutz04 said in Linux: Mounting an NFS Share:

    Can you explain why if I just mount an NFS share, using the command below, I can get a data transfer/throughput speed of approx 300 MB/s

    mount 192.168.2.2:/var/nfs_share1 /mnt/nfs1
    

    BUT,

    If I put an entry in fstab, it dramatically slows the transfer to about 35-40 MB/s

    192.168.2.2:/var/nfs_share1 /mnt/nfs1 nfs rw,sync,hard,intr 0 0
    

    What causes that?

    sync



  • "The default export behavior for both NFS Version 2 and Version 3 protocols, used by exportfs in nfs-utils versions prior to nfs-utils-1.0.1 is "asynchronous". This default permits the server to reply to client requests as soon as it has processed the request and handed it off to the local file system, without waiting for the data to be written to stable storage. This is indicated by the async option denoted in the server's export list. It yields better performance at the cost of possible data corruption if the server reboots while still holding unwritten data and/or metadata in its caches. This possible data corruption is not detectable at the time of occurrence, since the async option instructs the server to lie to the client, telling the client that all data has indeed been written to the stable storage, regardless of the protocol used."

    http://nfs.sourceforge.net/nfs-howto/ar01s05.html



  • So when you mount with the mount command without specifying, you get async. When you put it into fstab, you manually overrode the async to go with sync. So a major change.



  • @scottalanmiller are the nfs shares faster than Windows SMB shares?



  • @scottalanmiller so safer, but slower essentially.



  • @fuznutz04 said in Linux: Mounting an NFS Share:

    @scottalanmiller so safer, but slower essentially.

    Slower usually is safer.



  • @krisleslie said in Linux: Mounting an NFS Share:

    @scottalanmiller are the nfs shares faster than Windows SMB shares?

    NFS is generally faster than SMB. SMB is traditionally super slow, NFS is screaming fast. SMB has improved over time, but NFS typically beats it.



  • @fuznutz04 said in Linux: Mounting an NFS Share:

    @scottalanmiller so safer, but slower essentially.

    Sync is safer for writes, but yeah, way slower.



  • @scottalanmiller Do you typically use the Sync then as a best practice, even though it is much slower to ensure there is no corruption?



  • @fuznutz04 said in Linux: Mounting an NFS Share:

    @scottalanmiller Do you typically use the Sync then as a best practice, even though it is much slower to ensure there is no corruption?

    Totally depends on the need. A database, hell yeah sync that. A general document file server? Nah, async is fine.



  • @scottalanmiller Sounds solid. The speed difference is dramatic. Thanks.