Ubuntu 14.10 shutdown script with rc0.d (rc6.d, rc.d)

An important change happened between Ubuntu 14.04 and 14.10. The automatic halt script was changed from /etc/rc0.d/S90halt to /etc/rc0.d/K11halt. Therefor custom scripts with the prefix K99 won’t be executed anymore. Changing your custom script to e.g. K04 ensures, that the script is executed in time.

Warning for encrypted home directories (not the same as full disk encryption): It seems that an encrypted home directory is umounted before the scripts in rc0 are executed (even if the script starts with K010). So a script won’t be able to access files of the home directory anymore.

Example:

Generate a custom shutdown file. The result will be an empty goodbye.txt on your Desktop after the next reboot.
echo -e '#!/bin/sh\ntouch /home/'$USER'/Desktop/goodbye.txt' | sudo tee /etc/init.d/custom-shutdown.sh

Set the file as executable.
sudo chmod +x /etc/init.d/custom-shutdown.sh

Insert a symlink from in the rc0.d directory with the process order K04.
sudo ln -s /etc/init.d/custom-shutdown.sh /etc/rc0.d/K04custom-shutdown.sh

Optional: This will execute the script at a reboot as well
sudo ln -s /etc/init.d/custom-shutdown.sh /etc/rc6.d/K04custom-shutdown.sh

Your custom script will be executed at the shutdown of the system.
Note: Currently Ubuntu is in the process of migrating from upstart to systemd.

References