Hi,
This tutorial is for everyone who is using an external hard drive with the Raspberry Pi and wants to use a safe method to power the drive down when rebooting/shutting down the Pi.
The problem: When powering down/rebooting the Pi, the connected hard drive won't spin down before Pi's power off. Instead power to the drive is abruptly cut off, resulting in an unpleasant clicking noise from the drive as it tries to jam the head to its parking position before the platter stops spinning.
Tutorial
To solve this issue we can use a small script which gets called right before shutdown (more specifically system halt).
Simply create a new script inside /lib/systemd/system-shutdown:
I'm using the drive /dev/sda with a partition called /dev/sda1. Replace it with your setup.
Insert this into the script:
#!/bin/bash
# Sync any cached data to the drive
sync
# In case the drive is still mounted, unmount it
umount /dev/sda1
sleep 1
# Spin down the drive
hdparm -y /dev/sda
sleep 3
Alles anzeigen
Save it (CTRL+O) and exit nano (CTRL+X).
Don't forget to make the new script executable:
That's it! Now the drive will spin down before the Pi cuts off power to it. It should definitely be better for the drive compared to just cutting power to it while it's still running.
For more info on systemd-shutdown/halt see:
https://www.freedesktop.org/so…systemd-halt.service.html
https://www.freedesktop.org/software/systemd/man/bootup.html
Or using man in shell: