You are not logged in.

#1 Yesterday 19:12:45

Therk
Member
Registered: 2023-02-02
Posts: 9

Creating/deleting a mounting directory based on FS mount status

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

#2 Today 13:27:26

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,120

Re: Creating/deleting a mounting directory based on FS mount status

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

#3 Today 14:12:12

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,160

Re: Creating/deleting a mounting directory based on FS mount status

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.

Online

Board footer

Powered by FluxBB