NFS mount using systemd from user home

Hi
I’m on openSUSE Tumbleweed on both my workstation and laptop.
I currently installed a brand new tumbleweed on the laptop and using it as a test to recover my own stuff from my NAS and forgejo selfhosted instance in case of failure.
My main goal and motivation is to write down a quick README to quickly walk me through a brand new installation process and be operative as quickly as possible.
For this reason I start dealing with my dotfiles using chezmoi to sync them across the 2 machines and my selfhosted forgejo.

I’d like to share the configuration off all my network drives the is currently written in /etc/fstab. This file cannot be managed via chezmoi.

I set out to find a solution to this over-engineered problem and discovered that it is possible to use systemd to automatically mount network folders.

I added these two configuration files in /etc/systemd/system/:

➜  ~ cat /etc/systemd/system/home-fabio-mnt-magnum-shared.mount
       
[Unit]  
 Description=shared folder on Magnum  
  
[Mount]  
 What=192.168.20.2:/volume1/shared  
 Where=/home/fabio/mnt/magnum/shared  
 Options=defaults  
 Type=nfs  
  
[Install]  
 WantedBy=multi-user.target  
➜  ~ cat /etc/systemd/system/home-fabio-mnt-magnum-shared.automount     

[Unit]  
 Description=Automount of shared on Magnum  
  
[Automount]  
 Where=/home/fabio/mnt/magnum/shared  
 TimeoutIdleSec=0  
  
[Install]  
 WantedBy=multi-user.target  

Subsequently:

systemctl daemon-reload

To start the automount service:

systemctl start home-fabio-mnt-magnum-shared.automount

and this follwing command to make it persistent after reboot:

systemctl enable home-fabio-mnt-magnum-shared.automount

My goal is to keep the configuration entirely within my home directory (~/.config/systemd/user/) so I can manage it with my dotfiles via chezmoi, avoiding any modifications to system files like /etc/fstab.

I set

➜  ~ echo $SYSTEMD_UNIT_PATH  
/home/fabio/.config/systemd/user

and put the above configuration files inside that folder, but when I try run the same command, it doesn’t work:

░░ The unit UNIT has entered the 'failed' state with result 'resources'.
Oct 19 18:01:50 workstation systemd[1697]: Failed to set up automount Automount of shared on Magnum.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░  
░░ A start job for unit UNIT has finished with a failure.
░░  
░░ The job identifier is 1028 and the job result is failed.
lines 976-1041/1041 (END)

I wonder if I have really embarked on a non-existent problem and am trying to solve it the wrong way.
I also understand the objection could be “eh but just copy the mount points in /etc/fstab by hand and that’s it”.
And you are also right :slight_smile: but now that I’m one step closer to solving it I’m sorry I wasted my time trying to solve it.

Thanks for any suggestions and help!

Mounting is system-wide operation and cannot be restricted to an individual user.

thanks @arvidjaar,
which is best or modern way than? editing fstab or systemd?

If I continue with the systemd approach I can create them locally in my folder and create a quick script to install them in the /etc folder so still no need to edit the etc/fstab file manually.

Or …is there a way to tell /etc/fstab to load the folder info from a separate file? I’m trying to dig the documentation, but haven’t found anything in this direction.
Thanks!

This is what man systemd.mount says:

Mount units may either be configured via unit files, or via /etc/fstab (see fstab(5) for details). Mounts listed in /etc/fstab will be converted into native units dynamically at boot and when the configuration of the system manager is reloaded. In general, configuring mount points through /etc/fstab is the preferred approach to manage mounts for humans. For tooling, writing mount units should be preferred over editing /etc/fstab. See systemd-fstab-generator(8) for details about the conversion from /etc/fstab to mount units.

So for most system managers /etc/fstab will still be the preferred way to go.

1 Like