Edge Computing

Embedded Linux won't reboot, how to force it and repair the file system

By
When a Raspberry Pi or Yocto based device will not reboot and prints "Failed to open /dev/initctl", systemctl cannot reach systemd anymore. You can still force the reboot with systemctl reboot --force, or --force twice as a last resort, but the second one skips unmounting and often leaves a damaged file system. This post shows how to force the reboot, how to make sure the file system gets checked on the next boot with fsck.mode=force, and how to cut SD card writes so it does not happen again.

I have a lot of embedded systems running in my product testing lab or at home, all of them either as Raspberries or self-made PCB with Yocto. Sometimes I can't reboot some systems, I think its the journald which causes some issues with SD cards, the error message usually is:

Failed to open /dev/initctl

Anyhow, if you have this issue - a reboot can be force-forced:

systemctl --force --force reboot

Since a forced reboot does not sync the journal, the system typically comes up with a damaged FS. The remote fsck can be initiated by extending the command above with

sudo tune2fs -i 1m /dev/DISK && touch /forcefsck && systemctl --force --force reboot

(assumed you have access to a shell, via SSH or local access). When all goes fine, the system comes up with a clean FS. All this fuss comes from the SD card writes. A well designed embedded IoT device should have dedicated flash memory for the running OS.

Why the reboot hangs

A normal reboot asks systemd to shut down. When systemd or its bus is stuck, the command falls back to the old SysV way of talking to init, and on a systemd system that fails with Failed to open /dev/initctl. Nothing happens and the box stays up.

  • I hit this myself on Raspberry Pi gateways out in the field, not only in the lab.
  • The steps below are how I got them back.

How to force the reboot

Try the soft force first. Per the systemctl docs, a single --force skips the normal service shutdown but still kills all processes and unmounts or remounts the file systems read-only:

sync
systemctl reboot --force

Only if that also hangs, use --force twice. systemctl then reboots by itself without asking systemd, which is why it works when systemd is stuck. It does not stop processes or unmount anything, so data can be lost. That is why the file system often comes up damaged.

Make sure the file system gets checked

Two parts of the command above need an update. tune2fs -i 1m only sets a check interval of one month, so it does not force a check on the next boot by itself. And systemd treats the /forcefsck file as deprecated, and writing to a file system you think is broken is not a good idea anyway. The current way is the fsck.mode=force kernel parameter from systemd-fsck, usually together with fsck.repair=yes. On Raspberry Pi OS add both to the single line in cmdline.txt on the boot partition, reboot once, then remove them again, or every boot will run a full check.

Stop it from happening again on SD cards

  • Keep the journal in RAM with Storage=volatile in /etc/systemd/journald.conf (see journald.conf). You lose logs on reboot, so ship the ones you need off the device.
  • Run the root file system read-only. Yocto has the read-only-rootfs image feature for this, and Raspberry Pi OS has an overlay file system option in raspi-config.
  • For devices in the field, use proper flash such as eMMC instead of an SD card for the running OS.

More on running devices at the edge: infinimesh 3.4 with rules, alarms and OTA at the device layer, connecting BACnet to the cloud with a gateway on an edge box and streaming IoT data to S3.

Need help with distributed systems, backend engineering or data platforms? See my consulting services.

Alexander Alten

Alexander Alten

Founder of Scalytics, co-creator and PMC member of Apache Wayang, and author of KafScale. I write about Kafka, streaming, data platforms, IoT and AI agent infrastructure in production.