Skip to main content
Topic: NFS, _netdev, /etc/fstab, dinit (Read 2080 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

NFS, _netdev, /etc/fstab, dinit

New Artix user here. I come from Arch. SystemD gave me some trouble so I went with Artix and dinit.

I used to have this in my /etc/fstab on Arch
192.168.2.108:/mnt/testdisk /mnt/testdisk nfs rw,sync,_netdev 0 0
192.168.2.108:/mnt/testdisk2 /mnt/testdisk2 nfs rw,sync,_netdev 0 0

I noticed that _netdev no longer works. My shares simply won't mount.

I found somewhat of a two part solution to this by putting this in my fstab first:
192.168.2.108:/mnt/testdisk /mnt/testdisk nfs rw,user,sync 0 0
192.168.2.108:/mnt/testdisk2 /mnt/testdisk2 nfs rw,user,sync 0 0


And second, put this in my .xinitrc.
mount -t nfs -o rw,user,sync 192.168.2.108:/mnt/testdisk /mnt/testdisk &
mount -t nfs -o rw,user,sync 192.168.2.108:/mnt/testdisk2 /mnt/testdisk2 &


OR what I was tinkering with, trying to understand dinit and init systems in general in my /etc/dinit.d/:
nfs-mount:
type = process
command = /usr/bin/mount -t nfs -o rw,user,sync 192.168.2.108:/mnt/testdisk /usr/bin/mnt/testdisk; mount -t nfs -o rw,user,sync 192.168.2.108:/mnt/testdisk2 /mnt/testdisk2
waits-for = NetworkManager

I noticed that if I don't put the user mount option in fstab I can't get the nfs shares to mount at all. Could anyone help me suggest a better solution? The most convenient one would be only relying on 2 entries in /etc/fstab with an alternative to the _netdev mount option.


Re: NFS, _netdev, /etc/fstab, dinit

Reply #1
New Artix user here. I come from Arch. SystemD gave me some trouble so I went with Artix and dinit.

I used to have this in my /etc/fstab on Arch
192.168.2.108:/mnt/testdisk /mnt/testdisk nfs rw,sync,_netdev 0 0
192.168.2.108:/mnt/testdisk2 /mnt/testdisk2 nfs rw,sync,_netdev 0 0

I noticed that _netdev no longer works. My shares simply won't mount.
Our script is yet to provide an automount script for networking filesystems. I'll work on it.

Could anyone help me suggest a better solution? The most convenient one would be only relying on 2 entries in /etc/fstab with an alternative to the _netdev mount option.
Can you try this out? Keep the entries on fstab with the _netdev option.

Code: [Select]
type       = scripted
command    = /usr/bin/mount -a -O _netdev
restart    = false
depends-on = network.target # NetworkManager always runs before this service
# The line below are optional, but good if you want to see the errors while testing
log-type    = buffer
I hope this doesn't interfere with the boot process (i.e. user reaches tty/display manager even while the network filesystems are mounting).
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #2
New Artix user here. I come from Arch. SystemD gave me some trouble so I went with Artix and dinit.

I used to have this in my /etc/fstab on Arch
192.168.2.108:/mnt/testdisk /mnt/testdisk nfs rw,sync,_netdev 0 0
192.168.2.108:/mnt/testdisk2 /mnt/testdisk2 nfs rw,sync,_netdev 0 0

I noticed that _netdev no longer works. My shares simply won't mount.
Our script is yet to provide an automount script for networking filesystems. I'll work on it.

Could anyone help me suggest a better solution? The most convenient one would be only relying on 2 entries in /etc/fstab with an alternative to the _netdev mount option.
Can you try this out? Keep the entries on fstab with the _netdev option.

Code: [Select]
type       = scripted
command    = /usr/bin/mount -a -O _netdev
restart    = false
depends-on = network.target # NetworkManager always runs before this service
# The line below are optional, but good if you want to see the errors while testing
log-type    = buffer
I hope this doesn't interfere with the boot process (i.e. user reaches tty/display manager even while the network filesystems are mounting).
Thanks for your detailed answer and thank you for working on a automount script.

This is working. I do however have to add the 'user' mount option in /etc/fstab for it to work. So I am basically back at the place where I started. Obviously users have to be in the mount group to mount the share, but having the 'user' mount option could technically be a safety concern, right?  I'm curious - because I am still learning - what your reasoning is for choosing the 'scripted' type in this case. When I looked in the man pages it described the type scripted as option for using scripts, but it seems you are only giving one command here.

Re: NFS, _netdev, /etc/fstab, dinit

Reply #3
This is working. I do however have to add the 'user' mount option in /etc/fstab for it to work. So I am basically back at the place where I started. Obviously users have to be in the mount group to mount the share, but having the 'user' mount option could technically be a safety concern, right? 
Say, can you try this command manually as root?
/usr/bin/mount -a -O _netdev
What's the error if user isn't enabled?

I'm curious - because I am still learning - what your reasoning is for choosing the 'scripted' type in this case. When I looked in the man pages it described the type scripted as option for using scripts, but it seems you are only giving one command here.
From dinit-service(5)
Quote
Scripted services are services which are started and stopped by executing commands (which need not actually be scripts, despite the name). Once a command completes successfully the service is considered started (or stopped, as appropriate) by Dinit.
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #4
Thanks. I misread that passage.

That way they just mount and I don't get an error message.

Re: NFS, _netdev, /etc/fstab, dinit

Reply #5
Right, so if you added log-type = buffer to your network mount service you said it failed if the fstab doesn't have user, so any error logs from there?
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #6
So I gathered that the command to do that would be sudo dinitctl catlog nfs-mount.
It says:
mount.nfs: Network is unreachable for 192.168.2.108:/mnt/testdisk on /mnt/testdisk
mount.nfs: Network is unreachable for 192.168.2.108:/mnt/testdisk2 on /mnt/testdisk2


Re: NFS, _netdev, /etc/fstab, dinit

Reply #7
Yeah, even when network.target is enabled, the interface won't be up yet, leading to your error.

I added a new target and script which addresses this (and nfs mount should depend on this), but since it's new (and I'm testing it along with incorporating new dinit features into our getty shell), I hope I can release it to the public this Saturday, but you can test it now.
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #8
Could you explain how to load these targets/files/services and where to place them?

Re: NFS, _netdev, /etc/fstab, dinit

Reply #9
You can put the net-online script wherever you want, but I personally do it in my /usr/local/bin directory, make sure you mark it as executable.

Put the network-online.target file in /etc/dinit.d (but I suggest renaming it since the proper service will be added this weekend), modify the path of the command (e.g. /usr/local/bin/net-online), and make your nfs-mount depend on it.
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #10
So now I have this, with the script marked as executable. My shares are not mounting.

❯ cat /usr/local/bin/net-online
#!/bin/sh
# Copyright (c) 2015 The OpenRC Authors.
# See the Authors file at
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
#
# This file was adapted from OpenRC with the copyright notice attached above.
# The terms are the same between this repo and the OpenRC repo, see ../COPYING
# file for details.

get_interfaces() {
    for ifname in /sys/class/net/*; do
        [ -h "${ifname}" ] || continue
        read iftype < ${ifname}/type
        [ "$iftype" = 1 ] && printf "%s " ${ifname##*/}
    done
}

interfaces=${interfaces:-$(get_interfaces)}
# Timeout should be handled by dinit direcly
# Failure to break from loop = offline
while true; do
    carriers=0
    configured=0
    ifcount=0
    for dev in ${interfaces}; do
        : $((ifcount += 1))
        read carrier < /sys/class/net/$dev/carrier 2>/dev/null ||
            carrier=
        [ "$carrier" = 1 ] && : $((carriers += 1))
        read operstate < /sys/class/net/$dev/operstate 2>/dev/null ||
            operstate=
        [ "$operstate" = up ] && : $((configured += 1))
    done
    [ $configured -eq $ifcount ] && [ $carriers -ge 1 ] && break
    sleep 1
done


~
❯ cat /etc/dinit.d/nfs-online.target
# For services that need network to be online, depend on this.

type       = scripted
command    = /usr/local/bin/net-online
restart    = false
depends-on = network.target

~
❯ cat /etc/dinit.d/nfs-mount
type       = scripted
command    = /usr/bin/mount -a -O _netdev
restart    = false
depends-on = nfs-online.target
log-type   = buffer


As a workaround that I thought of myself I just had my nfs-mount point to a script with a 10 seconds sleep. That way it will wait long enough before it starts mounting and succeed.
/usr/bin/sleep 10 && /usr/bin/mount -a -O _netdev

Re: NFS, _netdev, /etc/fstab, dinit

Reply #11
Huh? What's the catlog for nfs-mount now? Still the same as earlier? I'll need to add a script to test if we can ping something (e.g. Cloudflare), but it will lock out those who want to connect only to local shares.
now only the dinit guy in artix

Re: NFS, _netdev, /etc/fstab, dinit

Reply #12
The same unfortunately
❯ sudo dinitctl catlog nfs-mount
mount.nfs: Network is unreachable for 192.168.2.108:/mnt/testdisk on /mnt/testdisk
mount.nfs: Network is unreachable for 192.168.2.108:/mnt/testdisk2 on /mnt/testdisk2