slepy8
15 February 2023 08:36
1
Hi everyone.
I have a NAS with SMB share and want to automount it via systemd automount when I turn on this NAS.
Mount (disabled) filename: home-adrian-media-DANE.mount
[Unit]
Description=serwer
[Mount]
What=//192.168.0.100/Dane
Where=/home/adrian/media/DANE
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/smb.cred,uid=1000
TimeoutSec=30
[Install]
WantedBy=multi-user.target
Automount (enabled) filename: home-adrian-media-DANE.automount
[Unit]
Description=DANE automount
[Automount]
Where=/home/adrian/media/DANE
[Install]
WantedBy=multi-user.target
After daemon-reload and reboot,
status for automount unit is:
"Failed with result âmount-start-limit-hitâ.
status for mount unit is:
âhome-adrian-media-DANE.mount: Failed with result âexit-codeâ.
Failed to mount serwer.
Start request repeated too quickly.
Failed with result âexit-codeâ.
Failed to mount serwer.â
What can I do about it?
Thanks in advance!
Hi @slepy8 ,
I have, myself, quite a few systemd mounts, and a few automounts as well. Granted, theyâre SSH and not SMB, but theyâre networked and works really well. I followed these tutorials, they ought to help you:
Difficulty: â
ââââ
Disk device recognition
Manjaro uses udev (see Arch Wiki ) to load devices at boot time. The loading of devices is arbitrary and therefore you cannot predict which device will be available at a given path.
But static device names do exist and you can assign specific locations to your device and thus ensure e.g. scripts will work as expected.
What to learn
Overview of system mount units
Structure and Content of a mount unit
Mount at boot (immediate mount)
Mount on demand (mâŚ
and
Difficulty: â
â
âââ
Example mount units for systemd
The examples here are a supplement to the guide on systemd mount units
Remember to remove the comments placed in the units - they are not writing for copy-paste but as examples. (comments is text beginning with a #)
[root tip] [How To] Use systemd to mount ANY device
Only use an automount unit if the device is not readily available at boot like removable devices and network locations.
Important rule
âŚ
Hope these helps!
slepy8
15 February 2023 08:53
3
I know these threads.
And they donât solve my issues.
At least I donât find the answear thereâŚ
Does the mount work if you manually start it?
sudo sysstemctl start home-adrian-media-DANE.mount
I think the problem is that systemd-automout works on your machine: itâs mounted on access (or on boot, depending on your setup). But it assumes that the NAS is always available. If itâs not available, it will retry a few times and fail.
How should your system know that the remote endpoint is available?
slepy8
15 February 2023 09:19
6
Yes, it mounts without a problem
slepy8
15 February 2023 09:23
7
This might be the point.
What I aimed for is a behaviour seen when mounting a USB drive.
Whenever it becomes accesible it should be mounted.
I just have no idea what Options should I use to make it happen. (if itâs Options case)
Dependance on availability of the NAS is not options basedâŚ
You should create a script that checks the NAS and if available start the mount unit, and when it dissapears stop the mount unit.
Automounts work in the way that it gets mounted when itâs accessed , not when itâs available, IIRC. For that a normal systemd mount would suffice. And if, as you said,
âŚyou should just enable it:
sudo systemd enable --now home-adrian-media-DANE.mount
This will result in the error message from the first post when the NAS is not running: failed too quickly too often.
(You have an error in your command, it should be sudo systemctl enable --now ...
)
slepy8
15 February 2023 09:56
11
This soundslike a reasonable solution.
But is there no other way?
If it can work with USB dongle why canât it work with SMB share?
You can always edit the unit to make a network connection the deependency:
[Unit]
Description=serwer
Requires=network-online.target
[Mount]
What=//192.168.0.100/Dane
Where=/home/adrian/media/DANE
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/smb.cred,uid=1000
TimeoutSec=30
[Install]
WantedBy=multi-user.target
And after youâve edited the file, remember to reload the daemon:
sudo systemctl daemon-reload
slepy8
15 February 2023 10:28
13
I read somewhere that â_netdevâ should satisfy this and they should not be used simultaneusly.
Or maybe âRequires=network-online.targetâ should be added to automount unit?
Donât add this - it will create weird messages in log.
_netdev option makes systemd infer that network-online.target is needed
When you specify a mountpoint inside your home - I will have to verify - but as I recall it - it will fail.
Test by duplicating your units using e.g. /a/DANE as mountpoint - start and stop the mount unit once to create the mountpoint - then set permissions -
remove the uid=1000 from options in your mount unit
add TimeoutIdleSec=30 to automount - just below the Where=
chmod o+rwx /a/DANE
then enable the automount
I have three that works perfectly, so maybe itâs not that.
Exactly as @slepy8 mentioned.
can you cat them for me?
just one mount and the corresponding automount
But I think there may be a difference with cifs - yours is using sshfs - as I recall?
linux-aarhus:
yours is using sshfs
Correct. Because I didnât see the use or need to setup SMB for the server since Iâm the only one that uses it.
$ systemctl cat home-mirdarthos-Gatekeeper_Downloads.mount
# /etc/systemd/system/home-mirdarthos-Gatekeeper_Downloads.mount
[Unit]
Description=Mount Gatekeeper's Downloads
[Mount]
What=mirdarthos@10.0.0.254:/home/mirdarthos/Downloads
Where=/home/mirdarthos/Gatekeeper_Downloads
Type=fuse.sshfs
Options=_netdev,allow_other,IdentityFile=/home/mirdarthos/.ssh/id_rsa,reconnect,ServerAliveInterval=30,ServerAliveCountMax=5
TimeoutSec=3600
$ systemctl cat home-mirdarthos-Gatekeeper_Downloads.automount
# /etc/systemd/system/home-mirdarthos-Gatekeeper_Downloads.automount
[Unit]
Description=Automount gatekeeper Downloads
ConditionPathExists=/home/mirdarthos/Gatekeeper_Downloads
[Automount]
Where=/home/mirdarthos/Gatekeeper_Downloads
TimeoutIdleSec=30m
[Install]
WantedBy=multi-user.target
Learning something new every day
A working set of unit files for cifs mount
disabled
$ cat /etc/systemd/system/home-fh-media-data.mount
[Unit]
Description=nas
[Mount]
What=//nas.net.nix.dk/data
Where=/home/fh/media/data
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/samba/.smbcredentials
TimeoutSec=30
[Install]
WantedBy=multi-user.target
enabled
$ cat /etc/systemd/system/home-fh-media-data.automount
[Unit]
Description=data on nas
[Automount]
Where=/home/fh/media/data
TimeoutIdleSec=30
[Install]
WantedBy=multi-user.target
$ ls ~/media/data
1.mp4
2.mp4
3.mp4
4.mp4
codeformatting
conky
diskstation-rsync-scripts
download
...
slepy8
15 February 2023 11:06
19
So what is the solution?
Cause itâs not very clear from your post
The diffs from my set of units
mount unit
remove uid=1000 from options
automount unit
my credentials file is accessible only by root and stored in /etc/samba under another name (the name doesnât matter)
chmod 600 /etc/smb.cred