Startup and shutdown scripts - run script at earliest and last opportunity?

The hard way: write your own systemd unit file.

The easy way:

Startup: /etc/rc.local
Shutdown: put your script or symlink in /lib/systemd/system-shutdown/ (fyi that is really right before halting the system. Filesystems e.g. are already read-only when scripts in that directory are called.

2 Likes