# Ubuntu – 16.04 nfs mount problems at boot time

16.04nfssystemd

First of all thank you for your time. I've been fighting for two days with this problem. I have the same environment in ubuntu 14.04 and is working perfect. So, let's start:

I want to mount a NFS at boot time. This NFS will have /etc/apache2 and other config folders. So, my fstab (working in 14.04) look like this:

X.X.X.X:/share_NFS         /mnt/nas        nfs   auto,nolock,soft,intr,nfsvers=3,tcp,bg,rw      0       0


Then, I bind every folder that I want to mount in the NFS like this:

/mnt/nas/config/apache2         /etc/apache2            none    auto,rbind,defaults     0       0

/mnt/nas/config/php5            /etc/php5               none    auto,rbind,defaults     0       0

/mnt/nas/config/logrotate.d     /etc/logrotate.d        none    auto,rbind,defaults     0       0

/mnt/nas/config/postfix         /etc/postfix            none    auto,rbind,defaults     0       0

/mnt/nas/www                    /var/www                none    auto,rbind,defaults     0       0


My problem:
The problem is when I boot the machine. Sometimes it's mounted correctly and sometimes not. If I reboot the machine, I have 25% of probability that NFS is not mounted correctly. If I make a "mount -a" it mounts fine.

I'm almost certain that there is a systemd problem. I found a lot of problems and some bugs with NFS and remote-fs.target dependencies in systemd. But anyone has a clear a solution. For example, I changed some dependencies of remote-fs.target just to require network-online, but it didn't work for me.

i think that is a matter of how systemd start the remote-fs.target and NFS.

I noticed that for every mountpoint of /etc/fstab, systemd generates a unit ended with .mount. So, if I look for this units:

systemctl show mnt-nas.mount

I saw this:

Names=mnt-nas.mount

Requires=system.slice -.mount

Wants=network-online.target

RequiredBy=etc-logrotate.d.mount etc-php5.mount remote-fs.target var-www.mount etc-apache2.mount etc-postfix.mount

Conflicts=umount.target

Before=etc-logrotate.d.mount umount.target etc-php5.mount remote-fs.target var-www.mount etc-apache2.mount etc-postfix.mount

After=systemd-journald.socket remote-fs-pre.target system.slice network.target -.mount network-online.target

RequiresMountsFor=/mnt


My questions:
Has anyone had this problem? has anyone get this kind of behaviour mounting NFS at boot time? How you solved if you had?

Thank you very much!

• Well, finally I've solved the problem.

In this case, I had two problems:

• By default, remote-fs.target is NOT depending on network-online.target . This is an known ¿bug? reported by the comunity. So, this si what makes that sometimes work and sometimes not (depends if ethernet has link or not when nfs is mounted).

• Second problem, in my case, I mount rbinds after mount the NFS. The source of the rbinds is a folder of the NFS mountpoint (so, it's clear that is has to be mounted later). When systemd generates the ".mount" unit files for every mountpoint of the fstab, all rbinds were depending of local-fs.target. Of course, this is a problem in this case because it could mount the rbinds (local-fs.target) before the nfs mountpoint (remote-fs.target).

So, to solve this situation what I made is:

• First, I edited the file /lib/systemd/system/remote-fs-pre.target and added:

Wants=network-online.target

After=network-online.target

• Then, in /etc/fstab I indicated to the NFS mountpoint the next options:

X.X.X.X:/nfs_share /mnt/nas nfs _netdev,noauto,x-systemd.automount,nolock,soft,intr,nfsvers=3,tcp,bg,rw 0 0

And finally, we indicate to systemd that rbinds are network device (so, systemd will put them on remote-fs.target) and also I indicated that /mnt/nas has to be mounted strictly.

/mnt/nas/config/php /etc/php none noauto,_netdev,x-systemd.automount,x-systemd.requires=/mnt/nas,rbind,defaults 0 0

With this change, I fix the order of launching the mounts propertly in systemd