Score:0

How to run a task at shutdown after filesystems are unmounted and cryptdisks are stopped?

cn flag

After my computer shuts down, my USB HDD keeps spinning. I would like to prevent this, so I created the following systemd service unit to spin it down upon shutdown:

[Unit]
Description=Spin down HDD on shutdown
DefaultDependencies=no
Before=shutdown.target
After=cryptdisks.service systemd-cryptsetup@luks_diskname.service
Conflicts=reboot.target cryptsetup.target

[Service]
ExecStart=/usr/sbin/hdparm -Y /dev/sda
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=shutdown.target

This gets executed upon shutdown and the HDD is spun down, but it happens too early despite the various after and conflicts statements I added to the service file. After the disk is spun down, the system still attempts to unmount filesystems and stop crypto disks, which either get stuck until they reach a timeout or they wake up the disk.

How could I fix the order of the shutdown tasks? The system itself is not running from the USB disk in case it matters.

user535733 avatar
cn flag
Edit your task to unmount that USB HDD first, and then spin it down. Once unmounted, none of the other tasks should matter.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.