[systemd-devel] Guidance on automount/unmount for external powered devices - SOLVED

Patrick O'Callaghan pocallaghan at gmail.com
Fri Mar 26 12:37:11 UTC 2021


On Thu, 11 Mar 2021 at 11:00, Patrick O'Callaghan <pocallaghan at gmail.com>
wrote:

> Apologies in advance if this is a FAQ, or if there is a more
> appropriate list for this question. I'm looking for a step-by-step
> guide for the following situation:
>
> I have an external 2-bay USB3 drive enclosure, configured as an MD
> Raid-1 device. This works without issue.
>
> I normally only use the device for nightly backups, so would prefer to
> leave it powered off until needed.
>
> I have scripts to power it up (creating the appropriate /dev/md entry
> and mounting the drive) and down (unmounting, removing the /dev/md
> entry and sending a magic signal to the USB device so it powers itself
> down after 30 minutes).
>
> Unfortunately a system reboot always leaves it in the 'powered up and
> present in /dev/md' state, so I have to manually run the power-down
> script every time I reboot. This is inelegant.
>
> I would much prefer to have this all handled automagically by systemd,
> but I need guidance on how to configure it. If it weren't for the power
> question, I know I can just use automount (and have managed to get this
> far on my own), but I don't know where or how to insert the power
> scripts. My reading of the systemd docs leads me to think that
> ExecStart/Stop might be the way, but where do I put this? Do I need a
> specific foo.mount unit (I'm currently using /etc/fstab)?
>

After a good deal of thrashing around, I settled on using "inotify -e
unmount" to detect when automount unmounted the drive, and used that to
trigger the power-down script.

poc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210326/4e0abd20/attachment.htm>


More information about the systemd-devel mailing list