0

I'm trying to gracefully shutdown my HDD's connected to my Rock64 SoC PC (similar to a Raspberry Pi) as the system full shuts down and I've managed to do it with the udiskstcl command. I can manually run the file perfectly fine and it does spin down all of the disks, however, upon shutdown it doesn't work.

I have created my shutdown file at

/lib/systemd/system-shutdown/graceful_disk_shutdown.shutdown

,made it executable and the contents of this file are as follows:

#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

Wait for media to be in idle state.

sync [ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

Function used to power off all SATA disks.

function power_off_disks() {     for disk in /sys/block/sd* ;     do         [ -e $disk ] && /usr/bin/udisksctl power-off -b /dev/${disk##*/}         sleep 2     done }

case "$1" in     *)         power_off_disks         ;; esac

Someone else reported it here and was told to use hdparm instead, which does indeed work for me but it doesn't answer the question to why udiskctl doesn't work.

Any ideas?

1 Answers1

0

By the time systemd reads the scripts in /lib/systemd/system-shutdown, the filesystems have already been umounted and are read only.

See this link "https://unix.stackexchange.com/questions/347275/how-to-run-a-script-at-shutdown-on-debian-9-or-raspbian-8-jessie/347686#347686" as a service using the script placed in say /usr/local/sbin.