An external USB 3.0 HDD Seagate Expantion Drive 1TB is connected to my Raspberry Pi 4B on the Raspbian Buster. The hard drive rarely works, so the first thing I would like it to shut down during idle time (rotation stopped). I must say right away that I tried the "hdparm" utility, but it absolutely does not work for me. On my old Raspberry Pi 3B +, it did its job perfectly, but it doesn’t work at all on the new one. I tried doing
sudo hdparm -S 10 / dev / sda1
and
sudo hdparm -Y / dev / sda1
But all he gives out is
/dev/sda:
issuing sleep command
SG_IO: bad / missing sense data, sb []: 70 00 05 00 00 00 00 0a 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
At the same time, the disk continues to rotate and the LED on the case is on, no matter how much I wait I also tried to register the following settings in hdparm.conf:
/dev/sda1 {
spindown_time = 20
}
But this also did not give any effect, the disk continues to rotate. Also, knowing that udisks2 is installed in the raspbian buster, I tried to create a configuration file Seagate_Expansion_NA4B2GTR-0: 0.conf (this is exactly what the command "udevadm info / dev / sda" gave me) in the directory /etc/udisks2/ with the contents
[ATA]
StandbyTimeout = 20
But it didn't work either.
The fact that the disk does not stop spinning is my first problem. The second problem is that when you turn off or restart Raspberry, the disk does not park its heads and its power is interrupted abruptly, which causes a very unpleasant rattle. I found similar queries on the Internet, this is a very common problem. I would like that during the procedure of shutting down the OS, the disk should be correctly unmounted and its power turned off before power is lost on the USB 3.0 port. Fortunately, I was able to write a similar script and it works great:
hddshutdown.sh
sudo umount -f /dev/sda1
sudo udisksclt power-off -b /dev/sda1
sleep 5
If I run this script just while the OS is running, it does exactly what I need: The disk is unmounted, the disk rotation stops and the LED on the case goes out. However, I cannot get this script to work the same way during the OS shutdown procedure.
I wrote this unit for systemd: hddshutdown.service in /usr/lib/systemd/system/
[Unit]
Description=[=======USB-HDD-spindown============]
DefaultDependencies=no
After=umount.target
Before=shutdown.target poweroff.target reboot.target halt.target
[Service]
ExecStart=/bin/sh /home/pi/hddshutdown.sh
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=reboot.target
I did "sudo systemctl enable hddshutdown", tried several different configuration options, played with different Before, After, and WantedBy values, but none of the options worked, just one, the drive is successfully unmounted, but the power does not turn off, the drive continues to spin and LED is on until the moment the Pi is turned off. Moreover, I know for sure that the sh-script starts exactly, the "sleep" delay, which I set at the end of the script, really works.
I do not know Linux very well and this was my first experience writing units for systemd. I found information that udisksctl needs DBus to work, but it doesn’t exist during shutdown, and that’s why the drive’s power cannot turn off. I could not find a way to execute this unit as early as possible during the shutdown procedure when DBus is still available. (I don’t even know what it is, maybe I said stupidity) Please help me solve 2 of these problems, thanks in advance.
I myself found the answer to my question. Because I use the Seagate Expansion drive, I used the Seagate Dashboard program from the official site to "reprogram" my hard drive. I was able to turn off the external LED-indicator and set the rotation shutdown time to 10 minutes and now on any system the hard disk is turned off after 10 minutes. Using programs like hdparm or udisks is no longer required!