Hello, I multi-boot, I have a 3 diskz1 pool with basically my local data that I have been sharing between some Void installations using
/etc/rc.local
#!/bin/sh
# Default rc.local for void; add your custom commands here.
#
# This is run by runit in stage 2 before the services are executed
# (see /etc/runit/2).
zpool import lagoon
&
/etc/rc.shutdown
#!/bin/sh
# Default rc.shutdown for void; add your custom commands here.
#
# This is run by runit in stage 3 after the services are stopped
# (see /etc/runit/3).
zpool export lagoon
How would I do this in systemd distributions? Debian, Ubuntu, Mint, CachyOS etc?
I have found you can start a script with roots crontab, but what about the shutdown-export side?
From Ben Cotton’s article at How to run commands at shutdown on Linux | Opensource.com :
Turns out, it’s much simpler with systemd. All you have to do is put your script in /usr/lib/systemd/system-shutdown/, which is handled by systemd-halt.service. Of course, if you need to manage dependencies in a particular order (e.g., you can’t post a tweet if the network stack is down), then you can write a systemd service unit file. For example:
[Unit]
Description=Run mycommand at shutdown
Requires=network.target
DefaultDependencies=no
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=mycommand
[Install]
WantedBy=multi-user.target
1 Like
sudo crontab -e
@reboot zpool import lagoon
sudo vim /usr/lib/systemd/system-shutdown/lagoon_Export
#!/bin/sh
zpool export lagoon
sudo chmod +x lagoon_Export
Super easy, barely an inconvenience!
Thank you this is working perfectly, reboot to another distribution and my data is automagically right there as well. No manual export required.
1 Like