0

I'm trying to mount my local NAS on startup with a script that is called by a systemd-service. Yesterday I did the same on a Debian 11-Install and it worked. Today on Arch I run into the problem that the network is unreachable when the script is executed. This is the service:

[Unit]
Description=mount FRITZ.NAS network share
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/etc/systemd/system/connect_fritz_nas

[Install]
WantedBy=multi-user.target

And this is the executing script:

#!/bin/bash

### connecting to fritz nas
### cannot copy without "noserverino"-option

sudo mount -t cifs -o credentials=/home/user/.smbcredentials,vers=2.1,_netdev,noserverino,uid=1000,gid=1000 //192.168.178.1/FRITZ.NAS /home/user/networkshare

As I read in different posts and articles (arch wiki, freedesktop wiki), systemd-networkd.service needs to be enabled because of systemd-networkd-wait-online.service in order to reach network-online.target.

Nevertheless I receive this ouput when running systemctl status connect-fritz-nas.service after rebooting my system:

× connect-fritz-nas.service - mount FRITZ.NAS network share
     Loaded: loaded (/etc/systemd/system/connect-fritz-nas.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Tue 2022-01-04 09:24:08 CET; 17min ago
    Process: 513 ExecStart=/etc/systemd/system/connect_fritz_nas (code=exited, status=32)
   Main PID: 513 (code=exited, status=32)
        CPU: 19ms

Jan 04 09:24:08 wooden-arch-box systemd[1]: Starting mount FRITZ.NAS network share...
Jan 04 09:24:08 wooden-arch-box sudo[517]:     root : PWD=/ ; USER=root ; COMMAND=/usr/bin/mount -t cifs -o credentials=/home/hendrik/.smbcredentials,vers=2.1,_netdev,noserverino,uid=1000,gi>
Jan 04 09:24:08 wooden-arch-box sudo[517]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jan 04 09:24:08 wooden-arch-box connect_fritz_nas[532]: mount error(101): Network is unreachable
Jan 04 09:24:08 wooden-arch-box connect_fritz_nas[532]: Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
Jan 04 09:24:08 wooden-arch-box sudo[517]: pam_unix(sudo:session): session closed for user root
Jan 04 09:24:08 wooden-arch-box systemd[1]: connect-fritz-nas.service: Main process exited, code=exited, status=32/n/a
Jan 04 09:24:08 wooden-arch-box systemd[1]: connect-fritz-nas.service: Failed with result 'exit-code'.
Jan 04 09:24:08 wooden-arch-box systemd[1]: Failed to start mount FRITZ.NAS network share.

Telling me that the network is unreachable. I know I could use fstab as an alternative, but on fstab I run into the same issue. Did I oversee something or did I do something wrong?

0

1 Answer 1

3

Instead of using a mount script which is executed by a systemd-unit, I used systemd.automount for which you need to create two files (mount units). Systemd.automount uses an automount-unit which refers to a mount-unit. Both files need to have the same name (except the extension). One is called home-user-networkshare.automount

[Unit]
Description=Automount networkshare

[Automount]
Where=/home/user/networkshare

[Install]
WantedBy=multi-user.target

and the other is called home-user-networkshare.mount

[Unit]
Description=mounting the fritz nas
Wants=network-online.target
After=network-online.target

[Mount]
What=//192.168.178.1/FRITZ.NAS
Where=/home/user/networshare
Type=cifs
Options=credentials=/home/user/.smbcredentials,vers=2.1,noserverino,uid=1000,gid=1000

[Install]
WantedBy=multi-user.target

Then I enabled both with systemctl enable home-user-networkshare.mount and systemctl enable home-user-networkshare.mount. After the next reboot, the networkshare is mounted. For more in-depth info dig through the manual.

1
  • 1
    I think Where=/home/share/networkshare in the mount file should be Where=/home/user/networkshare, right?
    – TechnoSam
    Commented Aug 9, 2023 at 2:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .