You are not logged in.
Hi everyone, I'm currently converting an old-ish gaming pc into a sort of home server/NAS, it's all a lot of fun. There is a filesystem on there I want to mount to my laptop, but only when I'm at home. At the moment and for the foreseeable future, I won't be able to access this server over the internet.
To be able to quickly see if the file system is mounted, I'd like the mount directory to only exist when the FS is available. So whenever I'm not at home, there's no visible mount directory, when my laptop connects to my home's wifi, the directory gets created and the FS gets mounted, when I leave, the FS gets unmounted and the directory gets removed, if I'm at home, but the FS is inaccessible (like if the server were to be shut down), it gets unmounted and the directory gets removed.
So far, I've found no easy way to do this. The simplest way to mount the network drive seems to be using /etc/fstab, using the x-systemd.automount and either nofail or soft options. From what I understand, this will also prevent the network drive mount timeout from slowing down my boot. Using the x-mount.mkdir option, it seems like I can also have fstab automatically create the directory, which is almost what I want! It just doesn't remove the directory when the FS gets unmounted.
Does this sound possible? Maybe I'm coming at this from a completely wrong point of view. Does it even make sens to think of network file systems as "successfully mounted", or does my machine only check when it needs to access a file?
Offline
Moderator Note
moving to Networking, Server, and Protection
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
x-systemd.automount requires the mountpoint to exist, you then mount the FS by accessing the path.
whenever I'm not at home, there's no visible mount directory, when my laptop connects to my home's wifi, the directory gets created
The various network management services provide hooks/dispatchers to dostuff™ when a connection changes, in case you're using NM see https://wiki.archlinux.org/title/Networ … SMB_shares
Otherwise you'll have to elaborate on the network stack.
Offline
I've spent basically my whole sunday trying to do this. I'm pretty sure what I want to do isn't possible because of how we've built computer networking protocols. That's not really something I have the power to change, so I think I'll have to settle for something that works how I want in something like 98% of real world scenarios (litterally crying rn).
Both the server and my laptop are indeed using NM, I've configured DHCP reservation on my router so their local IP adresses won't change, and both computers are registered in each other's /etc/hosts. The file system is exported on the server using nfs-utils, and /etc/exports allows exporting to my laptop. On the laptop's side, I've been manually mounting the exported file system so far. I'm really far from an expert on networking so I'm not 100% certain what else would be relevant.
I don't think the behavior I want is possible because it would require the process that manages the network mounts on my laptop to know whether the server isn't responding because at the moment it's not supposed to (e.g. if I've manually disconnected the machine from my home wifi, or if I'm not currently home) and whether the server isn't responding because there's some error happening somewhere (e.g. the wifi crashed, or the response is just taking longer because the server is doing something else). The more I think about the actual dialogue that has to happen between computers, using like packets and requests and stuff, the more it seems like this isn't possible. If a server isn't responding, you can't exactly ask it why, it's not responding.
NetworkManager-dispatcher.service was interesting, but I found it to be a bit unreliable. I'm guessing it's some kind of race condition/timeout issue when the nfs client waits for the server's answer? Sometimes it would work perfectly, sometimes the file system didn't mount when connection was established, sometimes it would correctly unmount on network disconnect, but the directory wouldn't be deleted and sometimes the directory would still exist after disconnecting, but trying to access it would just hang for about two minutes, which I'm guessing is what happens when the NFS client is waiting for the server's answer. I also noticed that using the NetworkManager dispatcher service only tries to mount the file system on network connection. Which would mean that if the mount fails, I'd have to manually mount the file system at a later time. So I'm thinking some kind of daemon scanning the network periodically and mounting the file system when it's available would work better.
I've tried using autofs, which did work better, but it had the same behavior whenever a wifi connection isn't available, it hanged for a really long time instead of unmounting. Which once again I think is because it's a bit fundamentally unknowable why a server isn't responding.
Thinking about how I actually use my laptop, it gets shut down whenever I'm not using it. So I probably don't actually need to constantly scan the network. It would probably be fine if I mounted the file system once a bit after boot, without checking constantly in case connection randomly fails.
Offline
I don't think the behavior I want is possible because it would require […] to know whether the server isn't responding because at the moment it's not supposed […] my home wifi
Both the server and my laptop are indeed using NM
Write a dispatcher for the specific profile and/or check the SSID/BSSID?
You can also check whether there's an nfs/rpc service listening on the expected IP?
nmap -p111,2049 SRV.IP.HE.REOffline