Systemd spindown disks before shutdown
mouse 56 · person cloud · link
Last update
2020-05-23
2020
05-23
« — »
  • /lib/systemd/system/spindown-disks.service
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=HDD spindown service
DefaultDependencies=no
After=umount.target
Before=shutdown.target reboot.target halt.target

[Service]
ExecStart=/opt/bin/spindown-disks.sh
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=shutdown.target
1
2
3
systemctl daemon-reload
systemctl enable  spindown-disks.service
systemctl restart spindown-disks.service
  • /opt/bin/spindown-disks.sh
1
2
3
#!/bin/sh
for i in /dev/sd?; do /sbin/hdparm -Y $i; done
/bin/sleep 5

See also: my systemd-units repo

Source: raspberrypi.org forum USB HDD poweroff (HDD abruptly stop spinning when running the shutdown command)