Shutdown waits for 1:30 minutes because of a nfs mount

Hello,

I have a Raspberry Pi Model B with a Wi-Fi dongle (WiPi RT5370). I have a Network Hard Drive (My Book Live 2TB) connected by nfs to the Raspberry. This is my /etc/fstab file:

192.168.1.2:/nfs/ /MyBookLive/ nfs noauto,udp,noatime,nolock,rsize=32768,wsize=32768,x-systemd.automount,nfsvers=3 0 0

The problem is that everytime I shutdown the Raspberry or I do a reboot, I have to wait for 1:30 minutes because, as I think, the Raspberry Pi is disconnecting first the Wi-Fi and after unmounting the hard drive.

I have tried to reduce that time of waiting modifying the DefaultTimeoutStopSec in /etc/systemd/system.conf and /etc/systemd/user.conf as a temporal solution, without any luck.

Could you help me to try to solve this problem or trying to reduce the time of waiting?
Thank you so much.

Is there a reason why you are using udp and setting rsize and wsize? Was this from testing your network, or did you just find those settings somewhere? Also, does the MyBook only support NFSv3?

You could try with getting rid of those settings and see if that helps. You could also try adding the setting _netdev (that tells mount that it’s a network device, so network access is needed)

As a test, just try this minimal entry in fstab (comment your current one just incase there is a good reason for some of those settings!)

192.168.1.2:/nfs/ /MyBookLive/ nfs noauto,user,x-systemd.automount,nfsvers=3,_netdev 0 0

See if that helps.

Thank you so much for your answer.

Is there a reason why you are using udp and setting rsize and wsize? Was this from testing your network, or did you just find those settings somewhere? Also, does the MyBook only support NFSv3?

No, I just saw in some forums that those were the best options for the Raspberry Pi with a NFS mount, but I don’t have any idea of what should be better. Anyway, and if you can suggest me some better options, I will be pleased to change them. The only thing I want with that NFS mount is streaming video from the network hard drive to the OSMC so… The fastest, the best. And the MyBook supports also NSFv4 but I don’t know what to use.

You could try with getting rid of those settings and see if that helps. You could also try adding the setting _netdev (that tells mount that it’s a network device, so network access is needed)

I have tried without udp, rsize and wsize. Later without those settings and with _netdev, and no luck…
And I also tried with your test entry but with identical result.

:slightly_smiling:

I had seen this problem on my Pi Model B, but I so rarely reboot it, I never really worried about it. But now since I played with it today, you have my interest up :smiley:

I think that you are right that the network is disconnecting before the drive. But near as I can tell so far, systemd seems to know that the mount is a network mount. So it should dismount the drive first, but doesn’t seem to.

I’ve never played with systemd yet, so it may take me a little while to figure this out.

One other thing, I’ve noticed on occasion the same thing with a USB mounted EXT4 drive on my Pi2… I’m thinking that the systemd setup is unmounting drives incorrectly…

I’ll let you know if I can figure out what’s happening.

I had this problem on my Debian laptop. Systemd had the race condition you mentioned.

Here’s the appropriate line in my laptop fstab for the NFS mount:

192.168.1.140:/volume1/Synology /media/Synology nfs x-systemd.requires=network.target,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

and here’s the OSMC RPi2 fstab line for the same NFS mount:
192.168.1.140:/volume1/Synology /media/Synology nfs x-systemd.automount,defaults,user,noauto,noatime,intr 0 0

Neither system hangs now.

That shouldn’t be the case. Shutdown ordering should be correct such that nfs mounts are taken down before the network. This is a problem that existed a long time ago but was fixed months ago.

You would need to ping your Pi from another machine during shutdown to confirm whether the network is actually going down too soon or not. If you can still ping it during this 1:30 period then something else is to blame.

I have tried pinging my Pi during the shutdown and the device stops the Wi-Fi at the very first moment.

In addition, my Wi-Fi dongle has a blue light which is on when the network device is running, and when I press the shutdown or reboot button, the light stops inmediately and it is completely impossible to ping or ssh the Pi.

Hello, I have tried your solution without any luck…

Maybe it is a problem of my Wi-Fi dongle, because I think that it is disconnecting too soon…

Edit /boot/cmdline.txt and change the word quiet to noquiet.

Boot up then shutdown. When it gets to the bit where it is waiting for NFS take a photo of the messages on the screen and post it here.

Did you try my laptop fstab line in your Pi? I believe I confused the issue by putting the Pi fstab line in the post. My Pi is plugged into the lan via powerline so it won’t have the wifi race condition.

The latest update upgrades systemd, so maybe a fix is there.

Here is the photo of the screen during the shutdown with the noquiet mode enabled.

Definitely, the Wi-Fi is one of the first things disconnected when the Pi is shutting down. Maybe changing the disconnection priority of the peripherals will do the trick, but I don’t know how to do it.

What I don’t see in your screenshot is “Stopped Connman connection service”.

Connman is responsible for bringing up and taking down the network. Do you see a line like this before or after what you have posted a photo of ?

Also can you temporarily try connecting over Ethernet (unplug your wifi adaptor as well) and see if you see this issue ? It’s possible that it’s a wifi only problem.

I have tried with Ethernet and the problem is the same.

And about the “Connman connection service”, that service is shutting down just after the wait of 1:30 minutes, as you can see in the next photo. So maybe the problem is with another service that kills my connection before the Connman, no?

Hi,

The problem still persist, and I have found a solution that works.

Create this file : /etc/systemd/system/umount-nfs.service
With this content :

[Unit]
Description=unmount nfs before stoping network
Requires=network.target
After=connman.service wpa_supplicant.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/umount -a -t nfs4

[Install]
WantedBy=multi-user.target

Then activate and start the service this way :

sudo systemctl daemon-reload
sudo systemctl enable umount-nfs.service
sudo systemctl start umount-nfs.service

This will unmount nfs4 volume before connman and wpa_supplicatant get stop.

Here my fstab nfs part:

192.168.200.102:/media /mnt/media nfs x-systemd.automount,user,noauto,noatime,intr,_netdev 0 0

Well it will be fixed in the next month update but congrats that you found an alternative already.
I think you just keep your solution till the next update

Out of interest, have you tried it without the _netdev option in /etc/fstab? You might find that x-systemd.automount effectively makes _netdev redundant.

for mount action, the _netdev is useless.
and without the service, the _netdev has no effect. so I may remove it without any problem.