Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
Created October 12, 2022 10:06
Show Gist options
  • Save PSJoshi/803a0419e568cc95c6bec24ebb0d44dc to your computer and use it in GitHub Desktop.
Save PSJoshi/803a0419e568cc95c6bec24ebb0d44dc to your computer and use it in GitHub Desktop.
Setting watchdog on Raspberry Pi

Setting watchdog timer in Raspberry Pi

  • Check WDT module is enabled in kernel In recent raspberry pi boards, the module for watchdog is bcm2835_wdt and it comes precompiled into kernel directly. So it doesn’t have to be enabled manually anymore and also it will not show when running lsmod.

To check if you have this module precompiled in kernel, you can run:

pi@raspberrypi:~ $ sudo cat /lib/modules/$(uname -r)/modules.builtin | grep wdt
kernel/drivers/watchdog/bcm2835_wdt.ko
pi@raspberrypi:~ $ sudo cat /var/log/kern.log* | grep watchdog
Oct 31 12:17:02 raspberrypi kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer

First command checks if the module is compiled into the kernel while the second command checks if it is loaded at boot.

  • Installing and enabling Watchdog (WDT) service To enable watchdog you have to change the boot parameters by adding dtparam=watchdog=on in /boot/config.txt. Also, install watchdog package and enable it to start at startup. Don’t forget to restart your RaspberryPi for these settings to come into effect.
pi@raspberrypi:~ $ sudo apt install watchdog
[... command output ...]
pi@raspberrypi:~ $ sudo systemctl enable watchdog
[... command output ...]
  • Configure WDT service The configuration file of watchdog can be tweaked in /etc/watchdog.conf. You can read the documentation for each setting in the file and adjust it as you like.
max-load-1 = 24
watchdog-device = /dev/watchdog
realtime = yes
priority = 1
  • Test WDT service You can test the WDT working as expecting by simulating heavy load on your device. The following command runs a fork bomb and should create enough load for WDT to overflow. DANGER: THIS WILL REBOOT YOUR DEVICE.
# :(){ :|: & };:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment