How does _netdev mount option in /etc/fstab work?
Solution 1
From man systemd.mount
for version 231 of systemd:
Mount units referring to local and network file systems are distinguished by their file system type specification. In some cases this is not sufficient (for example network block device based mounts, such as iSCSI), in which case _netdev may be added to the mount option string of the unit, which forces systemd to consider the mount unit a network mount.
Solution 2
SysV Init
The /etc/init.d/mountall.sh
init script mounts local filesystems only:
mount -a -t nonfs,nfs4,smbfs,cifs,ncp,ncpfs,coda,ocfs2,gfs,gfs2,ceph -O no_netdev
Other filesystems are mounted by separate init scripts, like for example /etc/init.d/mountnfs.sh
, which declare (via LSB headers) their dependency on $network
. Thus these get scheduled later, after the network is brought up, while mountall.sh
can run much earlier.
systemd
Local mount units are pulled in by local-fs.target
, remote ones by remote-fs.target
. systemd-fstab-generator
scans /etc/fstab
, generates mount units and assigns these to the above targets based on conditions similar to the above.
delay_connect
This option means that sshfs will not initiate the SSH connection to the remote server at mount time, but will only do so on the first filesystem operation actually requiring it. This delays error reporting, but might be a useful workaround in some cases, for example if your init system hasn't got enough information to order the mount operation correctly. "The network" being "up" is a rather loose term, and even though one can add arbitrary extra dependencies to mount units that doesn't help if the trigger event is not part of the bootup transaction (in systemd parlance).
Solution 3
Upstart/Udev
For upstart
and/or udev
based systems this is slightly different.
It seems udev
will still try to mount the NFS filesystems and netfs
is a safety net for when that fails.
Please correct me if I'm wrong. either way, this answer is only relevant for some recent legacy systems (Ubuntu 14.04 LTS, RHEL6).
Related videos on Youtube
Comments
-
Piotr Dobrogost almost 2 years
I'd like to know what is the exact mechanism (implementation) used to defer mounting until after network interface is up when one uses
_netdev
option in/etc/fstab
?
Doessystemd
alter this behavior?
Also, what doesdelay_connect
option to sshfs provide what_netdev
does not?From
mount
man page:_netdev
The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).From
sshfs
man page:-o delay_connect
delay connection to server -
Piotr Dobrogost about 8 yearsSo, you are saying that
_netdev
is not meant to be an argument passed to the process which performs mount (and which is specific to the type of mount likeext4/btrfs/cifs/fuse
) but is meant to be read by other processes/scripts which based upon this flag decide when during the boot process these mounts should be executed. Yes? If so then I suspect this is the reason why this argument starts with underscore so that to differentiate it from other formal arguments. -
Ferenc Wágner about 8 yearsYes. If you pass the
_netdev
option to themount
command, it will be visible in/proc/mounts
but have no other effect. -
Piotr Dobrogost about 8 yearsBonus question; is this documented somewhere?
-
Ferenc Wágner about 8 yearsThe mount manual contains: "FILESYSTEM-INDEPENDENT MOUNT OPTIONS — Some of these options are only useful when they appear in the
/etc/fstab
file." Well,_netdev
(documented somewhat later) is a fine example for this. -
Piotr Dobrogost about 8 yearsThe _netdev option is ignored in mount(8) by default. The options is used by initscripts only. – bugzilla.redhat.com/show_bug.cgi?id=607309#c4
-
Marek Zakrzewski over 7 yearsAwsome! No idea why this answer hasn't been up-voted yet.
-
Paolo Benvenuto over 4 yearsit doesn't work in debian stretch.
-
Admin about 2 yearsThis doesn't explain why an fstab definition without
_netdev
fails not only at boot but also later at run time (withmount -a
), but succeeds when this flag is added.