5

i have been wrestling with adding a (asustor) nas to my network last week and finally got to the point where i can mount folders via nfs in ubuntu and from my raspberry-pi running rune-audio.

i mount these in root/nfs/"folder" and added it to the nautilus sidebar. now i would like to auto mount these upon boot and have read through:
https://help.ubuntu.com/community/Autofs and,
How to setup Automount/Autofs

I have installed autofs.

but i don't seem to understand how to convert the assignment in terminal when i manually mount it to a rule for auto.master:

Manual mount rule used: sudo mount 192.168.0.200:/volume1/Public /nfs/Public

help on this "conversion" would be greatly appreciated.

that is i assume that adding that rule to the standard auto.master is enough or should i work with indirect rules? incorperating auto.nfs?

many thanks in advance on any assistance.

Addition:

I due to the help of steeldriver i indeed got the folder mounted.
But i forgot to mention that besides the rule mentioned above:
sudo mount 192.168.0.200:/volume1/Public /nfs/Public.

i also need to mount:

sudo mount 192.168.0.200:/share/USB1 /nfs/Music.

i assumed this would be similar to implement, but when it tried the following:
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/volume1/Public
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/share/USB1

but this only gave me a Music folder with the public content, not the USB1 content. what am i doing wrong here?

2 Answers2

12

To mount NFS shares we need to install nfs-common:

sudo apt-get install nfs-common

To save us from retyping this after every reboot we add the following line to /etc/fstab:

<nfs-server-IP>:/   /mnt   nfs    auto  0  0

If after mounting, the entry in /proc/mounts appears as :// (with two slashes), then you might need to specify two slashes in /etc/fstab, or else umount might complain that it cannot find the mount.

The auto option mounts on startup. However this will not work if your client uses a wifi connection managed at the user level (after login), because the network will not be available at boot time. In Ubuntu 12.04 LTS and later, wifi connections are managed at the system level by default, so auto-mounting of NFS shares at boot time should work fine

Source: https://help.ubuntu.com/community/SettingUpNFSHowTo

With WIFI it's better to use Autofs:

We start by installing AutoFS:

sudo apt install autofs

We edit /etc/auto.master:

sudo nano /etc/auto.master

Content:

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#/misc  /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
#/net   -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
#+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
#+auto.master

/media/nfs /etc/auto.nfs --ghost

Comment out (#) "+auto.master" and "+dir:/etc/auto.master.d" and add the lines at the bottom. I spent 2hours trying to get this to work and somehow it does not work without adding the --ghost option. If someone knows why please comment. Now /media/nfs is the dir that will contain your NFS shares (you dont have to create that, autofs does that for you) and /etc/auto.nfs is the configuration file for your shares. We will make that now:

sudo nano /etc/auto.nfs

Insert shares:

Backup      10.0.1.100:/Backup
Multimedia  10.0.1.100:/Multimedia

Now Backup the the dir 10.0.1.100:/Backup will take in /media/nfs.

Restart autofs:

sudo systemctl restart autofs

That's it, enjoy your shares.

Izzno
  • 944
4

It's been a while since I've done this, but from what I remember the usual configuration is that the auto.master contains nothing but a location for the mount, and the name of a protocol-specific map file e.g.

In /etc/auto.master:

# configure nfs automount (for ad-hoc connection to local NAS) 
/nfs   /etc/auto.nfs

The map file /etc/auto.nfs would be something like:

# configure nfs automount (for ad hoc connection to local NAS)
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/Volume1/Public

If you are using Ubuntu 16.04 or later, the systemd way to reload the autofs maps seems to be

sudo systemctl reload autofs.service

or (if that's not enough)

sudo systemctl restart autofs.service

After that, the NAS volume should mount on demand e.g.

ls /nfs/Public

Note that if your numeric UIDs are not the same on the NAS and the local system, you may need to set up user mapping between the systems.

steeldriver
  • 142,475