Artix Linux Forum

Artix Linux => System => Topic started by: freetix on 15 June 2025, 12:31:55

Title: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 15 June 2025, 12:31:55
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.

Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 15 June 2025, 15:13:18
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).
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 15 June 2025, 19:06:53
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.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 16 June 2025, 00:51:32
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.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 16 June 2025, 01:13:07
Thanks. I misread that passage.

That way they just mount and I don't get an error message.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 16 June 2025, 02:40:16
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?
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 16 June 2025, 08:12:27
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

Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 16 June 2025, 14:53:37
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 (https://gitea.artixlinux.org/artix/dinit-rc/commit/3111aca01d89975f9a2922175312f56739da3d8d) 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.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 16 June 2025, 16:48:28
Could you explain how to load these targets/files/services and where to place them?
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 17 June 2025, 02:25:40
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.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 17 June 2025, 09:14:03
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
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: konimex on 17 June 2025, 11:07:32
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.
Title: Re: NFS, _netdev, /etc/fstab, dinit
Post by: freetix on 17 June 2025, 12:17:55
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