You are not logged in.

#1 2016-03-02 15:46:32

killkrt
Member
From: Italy
Registered: 2016-02-24
Posts: 35

[?] How to mount USB at boot waiting for disk availability

Hi,

I would like to know which is the best solution to solve the following problem:

I have an headless server where a lot of services are running, two of those need to access to an external disk connect via USB. The disk is mounted via /etc/fstab using auto option.
Sometimes the disk is not ready as the system start so the mount fails stopping the boot process waiting for an user option (but since it is an headless server... Nobody could push any button).

If I understood correctly fstab entries are automatically converted to systemctl unit, so I was wondering how I can put a timeout/retry to this autogenerated unit, and then put a drop-in snippet to other two units depending on it in order to wait that the USB disk is mounted in order to be started.

Thank you.

Ciao.

Offline

#2 2016-03-02 21:31:49

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [?] How to mount USB at boot waiting for disk availability

killkrt wrote:

The disk is mounted via /etc/fstab using auto option

Try using these options instead:

x-systemd.automount,nofail

See systemd.mount(5) & systemd.automount(5)


Jin, Jîyan, Azadî

Offline

#3 2016-03-02 21:42:25

killkrt
Member
From: Italy
Registered: 2016-02-24
Posts: 35

Re: [?] How to mount USB at boot waiting for disk availability

I think I've solved with this solution.
I've create a unit /etc/systemd/system/media-xyz.mount with this content:

[Unit]
Description = Big USB disk

[Mount]
What = /dev/sdb1
Where = /media/xyz
Type = ext4
Options = rw,user
TimeoutSec = 10

[Install]
RequiredBy = transmission.service
RequiredBy = plexmediaserver.service

And then enable the service.

It seems to work, but I am not pretty sure that it's the best way to do it.

Offline

#4 2016-03-02 22:21:47

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: [?] How to mount USB at boot waiting for disk availability

With this solution you only have the 'Requires=' part, not the 'After=' part; so it could work, but it is not sure that the two units will be started after the mount point.
You could try instead to keep the /etc/systemd/system/media-xyz.mount unit without the 'RequiredBy' lines:

[Unit]
Description = Big USB disk

[Mount]
What = /dev/sdb1
Where = /media/xyz
Type = ext4
Options = rw,user
TimeoutSec = 10

(You don't need to enable the mount unit)

And adding in the [Unit] section of the two services transmission.service and plexmediaserver.service this line:

RequiresMountsFor=/media/xyz

which should take care of the 'Requires=' and 'After=' for the mount unit required to access the specified path (see man systemd.unit).

But if your solution works, this is good, but with the 'After=' part it should be better.

Offline

Board footer

Powered by FluxBB