You are not logged in.

#1 2022-10-14 21:54:37

someReallyRandomName
Member
Registered: 2022-09-25
Posts: 22

[SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

I have remote disk connected to network and I have created systemd mount file (/etc/systemd/system/run-media-yesnt-diskz.mount) with the following content:

[Unit]
Description=Disk Z
Requires=systemd-networkd.service
After=network-online.target
Wants=network-online.target

[Mount]
What=\\192.168.8.2\wspolne
Where=/run/media/yesnt/diskz
Options=vers=2.1,credentials=/etc/samba/disk_z.cred,iocharset=utf8,rw,x-systemd.automount
Type=cifs
TimeoutSec=30

[Install]
WantedBy=multi-user.target

The problem is if I am not connected on the same network, or disk is currently unavailable systemd will wait from 5 to 30 seconds when starting up (it's kinda random) and 1.5 minute when shuting down.
My questing is, would it be possible to run mount for this unit asynchronously, so it wouldn't block rest of the system, and if it is possible to ignore unmounting without blocking shutdown?

Last edited by someReallyRandomName (2022-10-17 11:42:54)

Offline

#2 2022-10-16 19:41:18

yodermk
Member
Registered: 2012-07-17
Posts: 86

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

Maybe create a new systemd target for when you're on that network and add it to that target.  At minimum it would let you more easily start and stop related services.

Whether it's possible to have it automatically load that target when you're on that network, I'm not sure, but it should be!  Sorry I don't have all the details but just a thought.  A google search isn't immediately showing a way to do that, but it seems like something that obviously should be doable.  With systemd adding features for every situation but the kitchen sink, this seems like an obvious addition.

Offline

#3 2022-10-17 08:15:28

someReallyRandomName
Member
Registered: 2022-09-25
Posts: 22

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

So, I found something called "remote-fs.target" while running "systemctl list-units --type=target" but I couldn't find too much documentation.
I myself couldn't find a way to trigger it  only when I am connected to that specific network.
Also I couldn't find a way to just kinda 'ignore' it when it isn't connected/mounted.

Offline

#4 2022-10-17 08:28:31

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

x-systemd.automount can indeed be helpful here, but it is an option for fstab. If you want to write the unit files yourself, you have to create an automount unit in addition to the mount unit and only enable the former (like with timer+service units).

Offline

#5 2022-10-17 08:58:44

someReallyRandomName
Member
Registered: 2022-09-25
Posts: 22

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

Sorry, but I am not an expert at systemd and I have no idea what you have just explained to me.
I would appreciate if you could like show me some example?

Offline

#6 2022-10-17 09:41:15

jonno2002
Member
Registered: 2016-11-21
Posts: 735

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

try adding "nofail" to the options

Offline

#7 2022-10-17 09:49:13

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

nofail is also an option for fstab... One can read about its effects in the man page and implement that in the unit files, but that seems to be too much:

someReallyRandomName wrote:

Sorry, but I am not an expert at systemd and I have no idea what you have just explained to me.
I would appreciate if you could like show me some example?

Then why create mount units yourself? Use fstab as recommended and let systemd generate the units.

Last edited by Raynman (2022-10-17 09:50:39)

Offline

#8 2022-10-17 11:42:32

someReallyRandomName
Member
Registered: 2022-09-25
Posts: 22

Re: [SOLVED] SystemD mount unit for remote disk blocks startup/shutdown.

Thanks jonno2002.
It worked.

Raynman wrote:

Then why create mount units yourself? Use fstab as recommended and let systemd generate the units.

Well, it was the first method that I found working so this is what I am using.
But, I will look into fstab as you proposed.

Offline

Board footer

Powered by FluxBB