You are not logged in.

#1 2013-03-16 16:27:56

maggie
Member
Registered: 2011-02-12
Posts: 255

[solved] Long delay booting with a downed NFS share

I have a NAS that shares by NFS but sometimes then NAS is switched off. I followed the instructions on the wiki to use x-systemd.device-timeout in my fstab but the I still hang on boot if the NAS is off.

192.168.0.2:/public   /media/public   nfs4   x-system.device-timeout=8   0   0

Last edited by maggie (2013-04-27 16:05:49)

Offline

#2 2013-03-16 16:43:48

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,644
Website

Re: [solved] Long delay booting with a downed NFS share

I believe you are missing 'noauto,x-systemd.automount' -- re-read that wiki page.

noauto,x-systemd.automount,x-systemd.device-timeout=8

Unrelated but in case you didn't know: you can define a hostname for your NAS in /etc/hosts so you don't need to use the numerical IP of the thing in your fstab.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2013-03-16 18:51:25

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: [solved] Long delay booting with a downed NFS share

Thanks you.

Offline

#4 2013-03-16 19:01:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] Long delay booting with a downed NFS share

I think using "nofail" would also do the trick. Though the "x-systemd.automount,noauto" combo is really nice.  I imagine both wouldn't hurt.

There is also something about "no_netdev" and "_netdev" in the man pages for mount. I assume that this gives the system some kind of information about how to respond in the event that the device I not available, but I don't actually use this one.

Offline

#5 2013-04-15 19:38:11

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: [solved] Long delay booting with a downed NFS share

Unsolved sad

If the share is mounted and the NAS box goes down, the system is very unresponsive.  How can I have systemd handle the mount so if it drops off, systemd will unmount it?

Offline

#6 2013-04-15 23:22:02

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] Long delay booting with a downed NFS share

I have an NFS share that I have converted to a native systemd unit.  So I have an automount unit matched up to a mount unit (that I actually just took from the generated ones in /run/systemd). 

So I added the x-systemd.automount stuff to the fstab, then checked out what it created for me.  I copied them over to /etc, and gave them an [Install] section.  I also added a StopWhenUnneeded=true to the [Unit] section.

You know... just look at these:

% cat /etc/systemd/system/run-media-wonderwoofy-torrents.automount

[Unit]
DefaultDependencies=no
Conflicts=umount.target
Before=umount.target remote-fs.target

[Automount]
Where=/run/media/wonderwoofy/torrents

[Install]
WantedBy=remote-fs.target

and that is matched up to this:

% cat /etc/systemd/system/run-media-wonderwoofy-torrents.mount

[Unit]
DefaultDependencies=no
After=remote-fs-pre.target
Wants=remote-fs-pre.target
Conflicts=umount.target
Before=umount.target 
After=network.target
StopWhenUnneeded=true

[Mount]
What=10.0.0.5:/srv/nfs4/torrents
Where=/run/media/wonderwoofy/torrents
Type=nfs4
FsckPassNo=0
Options=tcp,rsize=32768,wsize=32768,rw,user,hard,intr,nofail,_netdev

I am not sure if this is an abuse of the StopWhenUnneeded= parameter, but it works for me.  So it will mount the directory when I enter it, and then unmount it if I leave that directory (unless a file from that directory is in use).  It does spam my journal from time to time telling me that it can't unmount because a file is in use, when there is nothing to my knowledge that is using it.  But 'tis a small price to pay for such awesomeness.

Offline

#7 2013-04-16 22:47:03

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: [solved] Long delay booting with a downed NFS share

I removed the /etc/fstab entry I posted and creating your two files on my machine. I then rebooted and went into the directory but it was empty. Systemd did not mount it for me. What am I doing wrong?

cat /etc/systemd/system/media.mount 
[Unit]
DefaultDependencies=no
After=remote-fs-pre.target
Wants=remote-fs-pre.target
Conflicts=umount.target
Before=umount.target 
After=network.target
StopWhenUnneeded=true

[Mount]
What=192.168.1.2:/media
Where=/mnt/media
Type=nfs4
FsckPassNo=0
Options=tcp,rsize=32768,wsize=32768,rw,user,hard,intr,nofail,_netdev
cat /etc/systemd/system/media.automount
[Unit]
DefaultDependencies=no
Conflicts=umount.target
Before=umount.target remote-fs.target

[Automount]
Where=/mnt/media

[Install]
WantedBy=remote-fs.target

I do not see anything in my journalctl that shows it tried.

Last edited by maggie (2013-04-16 22:48:17)

Offline

#8 2013-04-17 14:41:49

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,644
Website

Re: [solved] Long delay booting with a downed NFS share

Take systemd out of the loop since its functions in this regard are as enigmatic as the female orgasm:

Step 1) Make /usr/local/bin/auto_share and edit the vars to meet your needs:

% cat /usr/local/bin/auto_share
#!/bin/bash

SERVER_EXPORT='10.1.10.101:/share'
MOUNT_TARGET='/mnt/share'

# Nothing to do if user does not have requisite binaries.
[[ -z $(which ping) ]] && echo 'Install iputils or whatever package provides ping' && exit 0
[[ -z $(which mountpoint) ]] && echo 'Install util-linux or whatever package provides mountpoint' && exit 0

ping -c 1 10.1.10.101 &>/dev/null
if [ $? -ne 0 ]; then
	# server is down so unmount
	#
	# if we query the mount point and it was previously mounted, the script freezes
	# so just unmount forcing while lazy
	umount -l -f $MOUNT_TARGET &>/dev/null
else
	# server is up
	#
	# check if mount point is live and try to mount if not
	mountpoint -q $MOUNT_TARGET || mount -t nfs4 $SERVER_EXPORT $MOUNT_TARGET
fi

Just put that in your root crontab and enjoy.

Step 2) Make systemd run this at boot:

% cat /etc/systemd/system/auto_media.service
[Unit]
Description=NFS automount

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/auto_media

[Install]
WantedBy=multi-user.target
% sudo systemctl enable auto_media

Step 3) Place it to run once/min in root's crontab:

# crontab -e
*/1 * * * * 	/usr/local/bin/auto_media

Last edited by graysky (2013-07-14 21:51:32)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#9 2013-04-19 22:07:31

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: [solved] Long delay booting with a downed NFS share

Thank you graysky. Your script seems to be perfect for my setup!

Offline

#10 2013-04-21 17:11:56

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: [solved] Long delay booting with a downed NFS share

maggie wrote:

Thank you graysky. Your script seems to be perfect for my setup!

then you should update your thread title to solved instead of not solved.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB