I have a usb sata2 drive connected to usb that is mounted as /home. When I turn off the computer/laptop the disk makes some high pitch sound as if the disks were still spinning and heads were not parked when the power goes off.
This sound is not produced when I unmount the partitions and send a sleep signal to the disk manually:
hdparm -Y /dev/sdb
But to do that I need to unmount /home as a partition of the disk is mounted as /home by the fstab:
UUID=[long number] /home ext4 defaults 1 2
So unmounting it isn't possible as the disk is always busy. Currently I can go to runlevel 1 and then unmount it and then send the sleep signal:
systemctl isolate runlevel1.target
umount /home
umount /dev/sdb*
hdparm -Y /dev/sdb
(unplug the drive without the drive giving any sounds)
systemctl poweroff
Because this is a bit much to do every time I want to turn off the computer/laptop I tried adding a script to rc0:
Have the following file in /etc/init.d
-rwxr-xr-x 1 root root 547 Mar 3 07:57 sleep.usb
containing:
#! /bin/bash
#
# network Bring up/down networking
#
# chkconfig: - 10 1
# description: Unmount /home/harm/ssd, /home and send sleep signal
#
# See how we were called.
case "$1" in
start)
;;
stop)
somevar="$(mount|grep /home)";
if [ "$somevar" != "" ]; then
umount /home
fi
umount /dev/sdb*
hdparm -Y /dev/sdb
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
exit 2
esac
exit 0
Installed it with:
chkconfig --add sleep.usb
and it is showing up in the right directory:
lrwxrwxrwx 1 root root 19 Mar 3 08:00 K01sleep.usb -> ../init.d/sleep.usb
However; when I power down my computer/laptop the harddisk still makes the sound and holding it in my hand I can feel the disks spinning up until the very moment the power goes off.