Host and Client Ubuntu 19.04. OpenSSH
I have a SSH server in my home LAN that I mount to my laptop using the LAN network address. When I'm at my weekend hideaway, I have to change my fstab to mount through my router's external IP address.
My router does not support loopback so I can't use the external IP when I'm in the LAN.
My approach has been to keep two sections in my fstab. One for the LAN and one for the external IP. Then I comment out the fstab lines to suit my location.
I wonder if there is a better way.
I can leave both sections open. I use the
nofail option so the boot process is not aborted but the startup is extremely slow. I tried putting
ConnectionTimeout=5in the sshfs options but this doesn't improve the boot time.
It's not a critical issue obviously, just a nice-to-have. Some conditional mounting? Or perhaps setting the timeout is not as simple as I've assumed.
Later: After some looking about:
following on suggestions by Archemar and muru, I'm looking into systemd initialization to make a fork to direct the mount process.
My theory (purely speculative based on reading documentation -- no experimentation) is to direct the
mount command through the
--fstab option to a fstab for the location.
One way to establish location is to read the network device IP. My LAN DHCP will assign 10.0.0.120. Any other IP address strongly suggests I am connecting to some network other than my LAN. Not completely reliable but good enough for non-critical application. If there is a more reliable way I'm happy to hear it.
I'm stuck now on locating the systemd mount service and where in the systemd init that service is called.
I look first in
/lib/systemd/. This directory contains mostly systemd executables, and some directories. One of these directories
system-generators contains a promising file
systemd-fstab-generator. This is an executable so I'm looking for, I guess the
conf file for this.
This is as far as I've got so far. I'll come back and post more later, but in the meantime I'd appreciate any tips, warnings, alarms...