Custom Linux Shutdown Scripts

Everyone knows one of the beauties of Linux (and FOSS in general) is the ability to delve in and change functionality for your own requirements. I was having an issue where a standard “poweroff” or “halt” was not shutting the computer down properly, so I needed to write my own scripts to replace them.

On Ubuntu /sbin/poweroff and /sbin/halt are symlinks to /sbin/reboot which is a binary (on debian reboot and poweroff symlink to halt), but the binary is aware of which command is being called, and acts accordingly. This means if you replace one of the symlinks with a script which in turn calls the binary, it will not necessarily perform the action you want (i.e. it will reboot rather than halt or poweroff).

On Ubuntu I solved this problem by creating a /sbin/local directory, copying the binary into there and creating local symlinks.

mkdir /sbin/local
cp /sbin/reboot /sbin/local/reboot
ln -s reboot /sbin/local/poweroff
ln -s reboot /sbin/local/halt

I was then free to replace the /sbin/poweroff, /sbin/halt and /sbin/reboot scripts with my own custom scripts, which were able to call the scripts in /sbin/local and would execute those correctly.

Leave a Reply