Can systemd mount a share for a specific user and show it in the filemanager?

This is sort of the flip side of my previous question.

Thanks to @linux-aarhus’s tutorial I have a working systemd unit that mounts a NFS share. Now I want to accomplish the following:

  1. mount the NFS share for only 1 specific user on this PC and not for the other users
  2. show the mounted share in the filemanager as device

Ad 2: When systemd mounts a local disk with Options=x-gvfs-show the disk shows up as a device, but this option does not seem to work for a NFS share. When I mount a SMB share by typing smb://nas/path/to/folder in the filemanager address bar, the mounted SMB share actually is listed as a device in the filemanager.

I’ve been searching the web, but apparently my foo is not strong enough to turn up a good answer.

WRT (1):
Placeing your related mount units inside ~/.config/systemd/user/ instead of /etc/systemd/system/ should do the trick IMHO :wink:

Okay, finally got around to playing with this again.

I didn’t have a systemd folder in ~/.config/ so I created it and gave it a user subfolder.

When I place the mymount.mount file in ~/.config/systemd/user folder and run sudo systemctl start mymount.mount then I get an error saying Failed to start: Unit mymount.mount not found.

When I search for solutions, I do see references to the ~/.config/systemd/user location that systemd should be reading from… but in my case this does not seem to work. What am I missing?

User units are controlled by the user instance of systemd, hence you need to use the --user parameter like this: :wink:
sudo systemctl --user start mymount.mount

That parameter is also needed to query the status etc etc…

Thanks! I had just figured that out by myself. One of my prouder moments :wink:

However, a user instance of systemd then can’t mount the unit in a folder owned by root… Understandable, but… argh, everything I try throws me another curve ball.

Unix system is wonderful when it comes to permissions huh? :face_with_hand_over_mouth:
I guess some mount point that is meant for it would do, IIRC someting like /run/media/your_username
I have no idea, because i don’t user per-user mounts…

Sheesh, going slightly nuts. I’m still trying to set up a mount unit as a user, but failing hard.

I can manually mount the nfs share with sudo mount -t nfs nas:/mnt/volume1/video /data/nfs/nasvideo.

I can mount the nfs share with sudo systemctl start data-nfs-nasvideo.mount when I place the mount unit in /etc/systemd/system/

But for the life of me, I can’t seem to start the mount unit as a user…

I have a mount unit in ~/.config/systemd/user:

$ cat data-nfs-nasvideo.mount 
[Unit]
Description=Mount video nfs share on nas
After=network-online.target
Wants=network-online.target

[Mount]
What=nas:/mnt/volume1/video
Where=/data/nfs/nasvideo
Type=nfs
Options=_netdev,auto
#TimeoutSec=seconds

[Install]
WantedBy=remote-fs.target
WantedBy=multi-user.target

When I run systemctl --user start data-nfs-nasvideo.mount it gives me this error on the command line plus the following journalctl -xe output:

$ systemctl --user start data-nfs-nasvideo.mount 
Job failed. See "journalctl -xe" for details.

$ journalctl -xe
░░ The process' exit code is 'exited' and its exit status is 32.
jan 31 17:35:25 bliep systemd[1088]: data-nfs-nasvideo.mount: Failed with result 'exit->
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'exit-code'.
jan 31 17:35:25 bliep systemd[1088]: Failed to mount Mount video nfs share on nas.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ A start job for unit UNIT has finished with a failure.
░░ 
░░ The job identifier is 2963 and the job result is failed.
jan 31 17:46:07 bliep systemd[1088]: Mounting Mount video nfs share on nas...
░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ A start job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 3061.
jan 31 17:46:07 bliep systemd[1088]: data-nfs-nasvideo.mount: Mount process exited, cod>
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ An n/a= process belonging to unit UNIT has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 32.
jan 31 17:46:07 bliep systemd[1088]: data-nfs-nasvideo.mount: Failed with result 'exit->
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'exit-code'.
jan 31 17:46:07 bliep systemd[1088]: Failed to mount Mount video nfs share on nas.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░ 
░░ A start job for unit UNIT has finished with a failure.
░░ 
░░ The job identifier is 3061 and the job result is failed.
jan 31 17:46:07 bliep mount[5227]: mount.nfs: failed to apply fstab options

If I run sudo systemctl --user start data-nfs-nasvideo.mount I get the following error:

$ sudo systemctl --user start data-nfs-nasvideo.mount 
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined

I have been searching the web for any sort of information or tutorials, but came up short. The best I could find for the latter errors that you can’t start user systemd mount/service with sudo. Looking at the error, that sounds plausible. Haven’t been able to turn up anything useful for the former errors though.

So I can’t figure out what is going wrong, there just isn’t enough information in the output for me.

I have tried chowning the various files and directories to either my user of root. I have tried chmoding the various files and directories to 777 and/or making them executable.

I have tried the previous in combination with setting the location to mount the share to a directory in my home directory, in /mnt and in the aforementioned /data directory. All to no avail and with exactly the same errors.

I’m gonna make pizza now for the kids, but if someone knows what to do, I will send a liberal amount of emoji your way :smiley:

Still trying to make this work, i.e. getting a systemd user mount mounted from a mount unit placed in the ~/.config/systemd/user/ directory.

It doesn’t work, no matter where I locate the destination folder: in my home directory or outside of it. It always fails with the errors listed in the journalctl output above. Starting to feel rather silly.

Hello, have you found a solution to your problem in the meantime?
I want to rebuild my system and want to make an encrypted partition only accessible to a certain user.

Hello @muvvenby,

I have a similar use case, and I have the same problems as you. The difference is that I want to mount an NFS share when the user logs in.

After some research on the Internet, I came to the point that I assume that it is due to the basic setup as described in the archlinux wiki.

Unfortunately, I do not understand the described (yet) basic setup. Is there anyone who can help us?