You are not logged in.

#1 2019-07-01 01:13:20

Kirill Bugaev
Member
Registered: 2018-08-03
Posts: 173

[solved] Switch off external hdd during system shutdown

I have external hdd. It stops with terrible noise after system shutdown (heads parking?), so I want to switch it off before. I use

udisksctl power-off -b /dev/sdb

Then I want to switch it off automatically during system shutdown. I have tried to make systemd unit

# ehddoff.service 
[Unit]
Description=ehdd power-off
DefaultDependencies=no
Before=shutdown.target

[Service]
ExecStart=/usr/bin/udisksctl power-off -b /dev/sdb
Type=oneshot

[Install]
WantedBy=shutdown.target

It doesn't work.

# journalctl
Jun 27 04:16:59 toshibanb ehddoff[2449]: Error connecting to the udisks daemon: Error calling StartServiceByName for org.freedesktop.UDisks2: GDBus.Error:org.freedesktop.systemd1.ShuttingDown: Refusing activation, D-Bus is shutting down.

What can you advice? Is it possible to start service before D-Bus shutdown?

Last edited by Kirill Bugaev (2019-07-01 06:54:04)

Offline

#2 2019-07-01 01:19:17

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [solved] Switch off external hdd during system shutdown


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2019-07-01 01:28:49

Kirill Bugaev
Member
Registered: 2018-08-03
Posts: 173

Re: [solved] Switch off external hdd during system shutdown

Thanks for replay, Jason.
Can you describe more precisely what do you mean?

Offline

#4 2019-07-01 01:41:21

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [solved] Switch off external hdd during system shutdown

Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2019-07-01 02:39:52

Kirill Bugaev
Member
Registered: 2018-08-03
Posts: 173

Re: [solved] Switch off external hdd during system shutdown

Jason, I thought it means executables in folder /usr/lib/systemd/system-shutdown/ start before actual shutdown, i.e. in last turn, just before electricity off, so D-Bus should be already shutdown. Am I wrong?
I have mdadm.shutdown only in this folder. I have tried to add bash script, smth like

#!/bin/bash
/usr/bin/logger TEST1

But TEST1 doesn't appear in system journal after reboot.

Offline

#6 2019-07-01 05:58:18

seth
Member
Registered: 2012-09-03
Posts: 49,966

Re: [solved] Switch off external hdd during system shutdown

Put an executable script in there that uses hdparm -Y to power off the disk.

Online

#7 2019-07-01 06:53:39

Kirill Bugaev
Member
Registered: 2018-08-03
Posts: 173

Re: [solved] Switch off external hdd during system shutdown

seth, it works. thanks.
But I get a problem with shutdown when I have added script in /usr/lib/systemd/system-shutdown/. It freezes (I waited about minute).
So I prefer use systemd unit. Shutdown is a few seconds longer.

Last edited by Kirill Bugaev (2019-07-01 07:16:08)

Offline

#8 2019-07-01 12:49:04

seth
Member
Registered: 2012-09-03
Posts: 49,966

Re: [solved] Switch off external hdd during system shutdown

So is this (still) solved (by using hdparm in the systemd unit)?

Online

#9 2019-07-01 20:13:13

Kirill Bugaev
Member
Registered: 2018-08-03
Posts: 173

Re: [solved] Switch off external hdd during system shutdown

seth, yes of course.

Offline

Board footer

Powered by FluxBB