Hi there,
I'm new to the forum, so forgive me my lack of form.
Here is my Problem:
Whenever I shut down my LibreElec/Kodi (NUC) the external HDDs made a scratchy noise. One HDD died (it was old and maybe it died due to another reason)
On other systems I use the sg_start-command to power-off/park the external HDD, but this is not available in LibreElec.
I found no other simpler solution or plugin to spin-down the hdds, so I made a shutdown-script.
Maybe it helps somebody or you can tell me if there's already a setting or addon for this.
SourceCode of /storage/.config/shutdown.sh
Bash
#!/bin/sh
LOGFILE=/storage/spindown.log
# Flush all data caches to the disks first
function shutdown_usb() {
date
sync
sleep 1
# Loop through all connected USB storage drives
for drive in /sys/block/sd*; do
if [ -d "$drive" ]; then
dev_name=$(basename "$drive")
# Check if the device is a USB drive
if readlink -f "$drive" | grep -q "usb"; then
kodi-send --action="Notification(Stopping USB Drive, Device: $dev_name , 1000, kodi-info-icon)"
echo "Stopping USB drive: $dev_name"
# 1. Allow the device to autosuspend
echo "auto" > /sys/block/$dev_name/device/power/control
# 2. Force it to suspend immediately by setting the idle timeout to 0ms
echo "10" > /sys/block/$dev_name/device/power/autosuspend_delay_ms
LIST_PARTS=$(mount | grep "^/dev/$dev_name" | cut -d " " -f1)
for PART in $LIST_PARTS
do
echo "unmounting $PART"
umount "$PART"
done
# 1. Force the SCSI target to go into standby mode
if [ -e "/sys/block/$dev_name/device/power/manage_start_stop" ]; then
echo 1 > "/sys/block/$dev_name/device/power/manage_start_stop"
fi
# 2. Tell the drive's SCSI link to spin down
echo "offline" > "/sys/block/$dev_name/device/state" 2>/dev/null
sleep 1
echo "current Status"
cat "/sys/block/$dev_name/device/power/runtime_status"
fi
fi
done
sleep 5
}
shutdown_usb > "$LOGFILE" 2>&1
Display More
Thanks for your time,
Josef