Emergency poweroff of Pi/Ubuntu

237 words, 1 mins

So, why won’t it shutdown

Some notes on force restarting a Raspberry Pi 4 running Ubuntu 20.04. I have
had times when I’ve changed something on the Pi, and then I can’t reboot. I
don’t want to simply pull the plug (rarely good happens from that) so I need
something to force shutdown…

This is after I’ve tried all the following:

reboot now
shutdown now
sudo shutdown now
sudo systemctl poweroff
sudo su -
# shutdown now

all of the above just silently return without any action. Occasionally $ sudo shutdown -f now will work, but often results in disk corruption.

Some prodding around in the system seems to indicate that there is something
borked in the systemd subsystem, but I’m not sure what.

Forcing a shutdown

There is something known as the ‘magic SysRq
. On a computer with a
physical keyboard, this maps to a physical key combination, however on the
Raspberry Pi we don’t have a physical keys, so we need to emulate the effect
from the terminal.

echo 1 > /proc/sys/kernel/sysrq
echo s > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger

The first command activates the kernel sysrq register. The second and third
commands are sending a character to trigger a kernel action. There are many
different keys that can be sent to the trigger, but the ones that we are
interested in are:

  • s - synchronize the file system
  • b - reboot the system
  • o - power off the system

HT to matoski

// EOF