[How to] Use systemd to mount remote shares

I’ve included this and built in staging now; made a couple of other changes surrounding UDisks so it will need a bit of testing. I’ll put some details in Slack shortly.

Sam

Here’s the system journal with Starting and Stopping times of each process.

osmc@osmc:~$ sudo journalctl -b -1 | grep 'Stopping\|Starting'
Sep 05 10:38:05 osmc systemd[1]: Starting Slices.
Sep 05 10:38:05 osmc systemd[1]: Starting Remount Root and Kernel File Systems...
Sep 05 10:38:05 osmc systemd[1]: Starting boot.automount.
Sep 05 10:38:05 osmc nfs-common[198]: Starting NFS common utilities: statd
Sep 05 10:38:05 osmc systemd[1]: Starting Load/Save Random Seed...
Sep 05 10:38:05 osmc systemd[1]: Starting Apply Kernel Variables...
Sep 05 10:38:05 osmc systemd[1]: Starting Create Static Device Nodes in /dev...
Sep 05 10:38:05 osmc systemd[1]: Starting udev Kernel Device Manager...
Sep 05 10:38:05 osmc systemd[1]: Starting Local File Systems (Pre).
Sep 05 10:38:05 osmc systemd[1]: Starting Local File Systems.
Sep 05 10:38:05 osmc systemd[1]: Starting Create Volatile Files and Directories...
Sep 05 10:38:05 osmc systemd[1]: Starting Copy rules generated while the root was ro...
Sep 05 10:38:05 osmc systemd[1]: Starting LSB: Tune IDE hard disks...
Sep 05 10:38:05 osmc systemd[1]: Starting Update UTMP about System Boot/Shutdown...
Sep 05 10:38:05 osmc systemd[1]: Starting System Initialization.
Sep 05 10:38:05 osmc systemd[1]: Starting sdio device path monitor.
Sep 05 10:38:05 osmc systemd[1]: Starting Paths.
Sep 05 10:38:05 osmc systemd[1]: Starting Avahi mDNS/DNS-SD Stack Activation Socket.
Sep 05 10:38:05 osmc systemd[1]: Starting D-Bus System Message Bus Socket.
Sep 05 10:38:05 osmc systemd[1]: Starting Sockets.
Sep 05 10:38:05 osmc systemd[1]: Starting Daily Cleanup of Temporary Directories.
Sep 05 10:38:05 osmc systemd[1]: Starting Timers.
Sep 05 10:38:05 osmc systemd[1]: Starting Basic System.
Sep 05 10:38:05 osmc systemd[1]: Starting mount disks automatically with standby...
Sep 05 10:38:05 osmc systemd[1]: Starting eventlircd remote support...
Sep 05 10:38:05 osmc systemd[1]: Starting irqbalance...
Sep 05 10:38:05 osmc systemd[1]: Starting Atop process accounting daemon...
Sep 05 10:38:05 osmc systemd[1]: Starting Regular background program processing daemon...
Sep 05 10:38:05 osmc systemd[1]: Starting Login Service...
Sep 05 10:38:05 osmc systemd[1]: Starting Login Prompts.
Sep 05 10:38:05 osmc systemd[1]: Starting Avahi mDNS/DNS-SD Stack...
Sep 05 10:38:05 osmc systemd[1]: Starting D-Bus System Message Bus...
Sep 05 10:38:05 osmc systemd[1]: Starting Connman connection service...
Sep 05 10:38:05 osmc systemd[1]: Starting Atop advanced performance monitor...
Sep 05 10:38:06 osmc systemd[1]: Starting Broadcom 43xx bluetooth HCI...
Sep 05 10:38:06 osmc systemd[1]: Starting Sound Card.
Sep 05 10:38:06 osmc systemd[1]: Starting Network.
Sep 05 10:38:06 osmc systemd[1]: Starting OpenBSD Secure Shell server...
Sep 05 10:38:06 osmc systemd[1]: Starting /etc/rc.local Compatibility...
Sep 05 10:38:06 osmc systemd[1]: Starting Network is Online.
Sep 05 10:38:06 osmc systemd[1]: Starting LSB: RPC portmapper replacement...
Sep 05 10:38:06 osmc systemd[1]: Starting Remote File Systems (Pre).
Sep 05 10:38:06 osmc systemd[1]: Starting Remote File Systems.
Sep 05 10:38:06 osmc systemd[1]: Starting Improves system performance tunables...
Sep 05 10:38:06 osmc systemd[1]: Starting media center application...
Sep 05 10:38:06 osmc systemd[1]: Starting Trigger Flushing of Journal to Persistent Storage...
Sep 05 10:38:06 osmc systemd[1]: Starting Set Time using HTTP query...
Sep 05 10:38:11 osmc bluetoothd[411]: Starting SDP server
Sep 05 10:38:06 osmc systemd[1]: Starting Permit User Sessions...
Sep 05 10:38:06 osmc systemd[1]: Starting RPC Port Mapper.
Sep 05 10:38:12 osmc systemd[1]: Starting Authenticate and Authorize Users to Run Privileged Tasks...
Sep 05 10:38:12 osmc rpcbind[317]: Starting rpcbind daemon....
Sep 05 10:38:12 osmc mediacenter[321]: Starting Kodi...
Sep 05 10:38:29 osmc systemd[1]: Starting LSB: Start NTP daemon...
Sep 05 10:38:29 osmc systemd[1]: Starting Multi-User System.
Sep 05 10:38:29 osmc systemd[1]: Starting Graphical Interface.
Sep 05 10:38:29 osmc systemd[1]: Starting Update UTMP about System Runlevel Changes...
Sep 05 10:38:29 osmc ntp[510]: Starting NTP server: ntpd.
Sep 05 10:38:34 osmc systemd[1]: Starting user-1000.slice.
Sep 05 10:38:34 osmc systemd[1]: Starting User Manager for UID 1000...
Sep 05 10:38:34 osmc systemd[1]: Starting Session c1 of user osmc.
Sep 05 10:38:34 osmc systemd[541]: Starting Paths.
Sep 05 10:38:34 osmc systemd[541]: Starting Timers.
Sep 05 10:38:34 osmc systemd[541]: Starting Sockets.
Sep 05 10:38:34 osmc systemd[541]: Starting Basic System.
Sep 05 10:38:34 osmc systemd[541]: Starting Default.
Sep 05 10:38:59 osmc systemd[1]: Starting Hostname Service...
Sep 05 10:39:24 osmc systemd[1]: Starting Session c2 of user osmc.
Sep 05 10:53:13 osmc systemd[1]: Starting Cleanup of Temporary Directories...
Sep 05 19:01:57 osmc systemd[1]: Stopping Session c1 of user osmc.
Sep 05 19:01:57 osmc systemd[1]: Stopping Bluetooth.
Sep 05 19:01:57 osmc systemd[1]: Stopping Sound Card.
Sep 05 19:01:57 osmc systemd[1]: Stopping Update UTMP about System Boot/Shutdown...
Sep 05 19:01:57 osmc systemd[1]: Stopping Bluetooth service...
Sep 05 19:01:57 osmc systemd[1]: Stopping Swap.
Sep 05 19:01:57 osmc systemd[1]: Stopping Restore / save the current clock...
Sep 05 19:01:57 osmc systemd[1]: Stopping Encrypted Volumes.
Sep 05 19:01:57 osmc systemd[1]: Stopping Load/Save Random Seed...
Sep 05 19:01:57 osmc systemd[1]: Stopping Apply Kernel Variables...
Sep 05 19:01:57 osmc systemd[1]: Stopping Load Kernel Modules...
Sep 05 19:01:57 osmc systemd[1]: Stopping LSB: NFS support files common to client and server...
Sep 05 19:01:57 osmc systemd[1]: Stopping User Manager for UID 1000...
Sep 05 19:01:57 osmc systemd[1]: Stopping Authenticate and Authorize Users to Run Privileged Tasks...
Sep 05 19:01:57 osmc systemd[1]: Stopping Disk Manager (legacy version)...
Sep 05 19:01:57 osmc systemd[541]: Stopping Default.
Sep 05 19:01:57 osmc systemd[541]: Stopping Basic System.
Sep 05 19:01:57 osmc systemd[1]: Stopping Graphical Interface.
Sep 05 19:01:57 osmc systemd[541]: Stopping Paths.
Sep 05 19:01:57 osmc systemd[1]: Stopping Multi-User System.
Sep 05 19:01:57 osmc systemd[541]: Stopping Timers.
Sep 05 19:01:57 osmc systemd[541]: Stopping Sockets.
Sep 05 19:01:57 osmc systemd[1]: Stopping irqbalance...
Sep 05 19:01:57 osmc systemd[1]: Stopping Regular background program processing daemon...
Sep 05 19:01:57 osmc systemd[541]: Starting Shutdown.
Sep 05 19:01:57 osmc systemd[1]: Stopping OpenBSD Secure Shell server...
Sep 05 19:01:57 osmc systemd[1]: Stopping media center application...
Sep 05 19:01:57 osmc systemd[541]: Starting Exit the Session...
Sep 05 19:01:57 osmc systemd[1]: Stopping /etc/rc.local Compatibility...
Sep 05 19:01:57 osmc systemd[1]: Stopping Login Prompts.
Sep 05 19:01:57 osmc systemd[1]: Stopping Avahi mDNS/DNS-SD Stack...
Sep 05 19:01:57 osmc systemd[1]: Stopping LSB: Start NTP daemon...
Sep 05 19:01:57 osmc bluetoothd[411]: Stopping SDP server
Sep 05 19:01:57 osmc nfs-common[5591]: Stopping NFS common utilities: idmapd statd.
Sep 05 19:01:57 osmc ntp[5614]: Stopping NTP server: ntpd.
Sep 05 19:01:57 osmc systemd[1]: Stopping eventlircd remote support...
Sep 05 19:01:57 osmc systemd[1]: Stopping RPC Port Mapper.
Sep 05 19:01:57 osmc systemd[1]: Stopping LSB: RPC portmapper replacement...
Sep 05 19:01:57 osmc systemd[1]: Stopping Login Service...
Sep 05 19:01:57 osmc systemd[1]: Stopping Create Volatile Files and Directories...
Sep 05 19:01:57 osmc systemd[1]: Stopping user-1000.slice.
Sep 05 19:01:57 osmc systemd[1]: Stopping Permit User Sessions...
Sep 05 19:01:57 osmc systemd[1]: Stopping Broadcom 43xx bluetooth HCI...
Sep 05 19:01:57 osmc rpcbind[5645]: Stopping rpcbind daemon....
Sep 05 19:01:57 osmc systemd[1]: Stopping Network is Online.
Sep 05 19:01:57 osmc systemd[1]: Stopping Network.
Sep 05 19:01:57 osmc systemd[1]: Stopping Remote File Systems.
Sep 05 19:01:57 osmc systemd[1]: Stopping Local File Systems.
Sep 05 19:01:57 osmc systemd[1]: Stopping boot.automount.
Sep 05 19:01:57 osmc systemd[1]: Stopping Remote File Systems (Pre).
Sep 05 19:01:57 osmc systemd[1]: Stopping Connman connection service...
Sep 05 19:01:57 osmc systemd[1]: Starting Unmount All Filesystems.
Sep 05 19:01:57 osmc systemd[1]: Stopping Local File Systems (Pre).
Sep 05 19:01:57 osmc systemd[1]: Stopping Create Static Device Nodes in /dev...
Sep 05 19:01:57 osmc systemd[1]: Stopping Remount Root and Kernel File Systems...
Sep 05 19:01:59 osmc systemd[1]: Stopping WPA supplicant...
Sep 05 19:01:59 osmc systemd[1]: Stopping D-Bus System Message Bus...
Sep 05 19:01:59 osmc systemd[1]: Stopping Basic System.
Sep 05 19:01:59 osmc systemd[1]: Stopping Slices.
Sep 05 19:01:59 osmc systemd[1]: Stopping User and Session Slice.
Sep 05 19:01:59 osmc systemd[1]: Stopping Paths.
Sep 05 19:01:59 osmc systemd[1]: Stopping sdio device path monitor.
Sep 05 19:01:59 osmc systemd[1]: Stopping Forward Password Requests to Wall Directory Watch.
Sep 05 19:01:59 osmc systemd[1]: Stopping Dispatch Password Requests to Console Directory Watch.
Sep 05 19:01:59 osmc systemd[1]: Stopping Timers.
Sep 05 19:01:59 osmc systemd[1]: Stopping Daily Cleanup of Temporary Directories.
Sep 05 19:01:59 osmc systemd[1]: Stopping Sockets.
Sep 05 19:01:59 osmc systemd[1]: Stopping Avahi mDNS/DNS-SD Stack Activation Socket.
Sep 05 19:01:59 osmc systemd[1]: Stopping D-Bus System Message Bus Socket.
Sep 05 19:01:59 osmc systemd[1]: Starting Shutdown.
Sep 05 19:01:59 osmc systemd[1]: Starting Final Step.
Sep 05 19:01:59 osmc systemd[1]: Starting Reboot...

As you can see there is no mention of wpa_supplicant.service being started by systemd, though a grep for wpa_supplicant gives us this:

osmc@osmc:~$ sudo journalctl -b -1 | grep -i 'wpa_supplicant\|wpa'
Sep 05 10:38:07 osmc dbus[269]: [system] Activating via systemd: service name='fi.w1.wpa_supplicant1' unit='wpa_supplicant.service'
Sep 05 10:38:11 osmc dbus[269]: [system] Successfully activated service 'fi.w1.wpa_supplicant1'
Sep 05 10:38:11 osmc wpa_supplicant[396]: Successfully initialized wpa_supplicant
Sep 05 10:38:11 osmc systemd[1]: Started WPA supplicant.
Sep 05 10:38:12 osmc wpa_supplicant[396]: process 396: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file ../../dbus/dbus-message.c line 2676.
Sep 05 10:38:12 osmc wpa_supplicant[396]: This is normally a bug in some application using the D-Bus library.
Sep 05 10:38:12 osmc wpa_supplicant[396]: process 396: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file ../../dbus/dbus-message.c line 2676.
Sep 05 10:38:12 osmc wpa_supplicant[396]: This is normally a bug in some application using the D-Bus library.
Sep 05 10:38:13 osmc wpa_supplicant[396]: wlan0: Trying to associate with 00:b8:ec:43:cd:f4 (SSID='SS01' freq=2412 MHz)
Sep 05 10:38:13 osmc wpa_supplicant[396]: wlan0: Associated with 00:b8:ec:43:cd:f4
Sep 05 10:38:13 osmc wpa_supplicant[396]: wlan0: WPA: Key negotiation completed with 00:b8:ec:43:cd:f4 [PTK=CCMP GTK=CCMP]
Sep 05 10:38:13 osmc wpa_supplicant[396]: wlan0: CTRL-EVENT-CONNECTED - Connection to 00:b8:ec:43:cd:f4 completed [id=0 id_str=]
Sep 05 10:38:13 osmc wpa_supplicant[396]: bgscan simple: Failed to enable signal strength monitoring
Sep 05 19:01:57 osmc wpa_supplicant[396]: wlan0: CTRL-EVENT-DISCONNECTED bssid=00:b8:ec:43:cd:f4 reason=3 locally_generated=1
Sep 05 19:01:59 osmc systemd[1]: Stopping WPA supplicant...
Sep 05 19:01:59 osmc systemd[1]: Stopped WPA supplicant.

So, although the connman.service is configured to run after wpa_supplicant.service (which starts at 10:38:05), it doesn’t actually start until 10:38:07. However, on the shutdown, it stops after connman, just as we want.

Spot on! Give that man a cigar.

Here’s the plot from systemd_analyze:

1 Like

Would you have a seperat [mount] for each drive?

yes. Separate files for both mount and automount as the filename has to match the mountpoint name.

@grahamh Do you know how I can remove the systemd mounts? I thought I would just need to delete the mnt-***.mount files from /lib/systemd/system but i’m getting some errors on startup

Feb 16 15:06:30 osmc systemd[1]: mnt-Movies.automount: Refusing to start, unit to trigger not loaded.
Feb 16 15:06:30 osmc systemd[1]: Failed to set up automount mnt-Movies.automount.

The file mnt-Movies.automount doesn’t exist

try systemctl disable mnt-Movies.automount and systemctl daemon-reload and reboot.

Thanks, i’d deleted that file already so it errors, no worries, I don’t think it’s causing any problems, I just get some errors on startup.

osmc@osmc:/lib/systemd/system$ sudo systemctl disable mnt-Movies.automount
Failed to disable unit: No such file or directory

I suspected that. You need to search for and delete links to that file in network.target.wants/ in /etc/systemd/system/ or lib/systemd/system/

1 Like

Great thanks, delete the 3 automount files i’d setup under /etc/systemd/system/network.target.wants/ and all seems to be good.

1 Like