You are not logged in.
I use an external USB Drive (174c:5106 ASMedia Technology Inc. ASM1051 SATA 3Gb/s bridge - with normal sata harddisk), and I want to poweroff the drive automatically, when shutting down the whole system.
I tried
hdparm -S 10 xxx
systemctl poweroff
but this works only sometimes, it's not reliable.
Reliable is
hdparm -f -F -Y xxx
systemctl poweroff
But where do I put the hdparm command, so that the drive poweroff is done automatically at the right time?
Is there a right place in arch shutdown sequence to put such hdparm command?
I don't want to loose data, because I put the drive sleeping too early of course, e.g. before sync, un-mounting and drive cache flush.
Thanks very much.
Last edited by ua4000 (2016-12-25 08:44:07)
Offline
You should be able to accomplish this with a systemd unit file using the poweroff target. https://wiki.archlinux.org/index.php/Sy … unit_files
Offline
Thanks very much! systemd ... of course :-)
But I didn't get it working. What I did:
# /etc/systemd/system/hdparm.service
[Unit]
Description=Shutdown external USB drive
Before=poweroff.target
[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -f -F -Y /dev/disk/by-id/ata-WDC_WD40EFRX-...
[Install]
WantedBy=poweroff.target
and then enabled it:
sudo systemctl daemon-reload
sudo systemctl enable hdparm.service
A manual start of the unit works fine, the external usb drive is powerd off, but it don't work automatically at system shutdown.
Is ExecStart right, or have I use ExecStop ? Also when googling for this problem (systemd + hdparm + poweroff.target) I found another location for a hdparm script: /usr/lib/systemd/system-shutdown - is this also I good idea to test?
Offline
Just place a file (+x) in /usr/lib/systemd/system-shutdown/, scripts/programs here are executed just before "deinitramfs".
For example I place the, to signal UPS in case of emergency shutdown.
$ cat /usr/lib/systemd/system-shutdown/apc_killpower
#!/bin/sh
if [ -f /etc/apcupsd/powerfail -a "$1" = "poweroff" ]; then
/etc/apcupsd/apccontrol killpower
fi
in your case you only need to check $1.
Offline
thank you very much, this works!
#!/bin/sh
# sudo nano /usr/lib/systemd/system-shutdown/hdparm.shutdown
# sudo chmod a+x /usr/lib/systemd/system-shutdown/hdparm.shutdown
if [ "$1" = "poweroff" ]; then
/usr/bin/hdparm -f -F -Y /dev/disk/by-id/ata-WDC_WD40EFRX-...
fi
Offline