How to activate auto-reboot on kernel hung on Linux in 20 seconds

Use this script (run as root) to automatically configure Linux to reboot after a Kernel hung event:

# Comment out previous kernel hung configuration
sed -i -e 's/kernel.hung_/#kernel.hung_/g' /etc/sysctl.conf
sed -i -e 's/kernel.panic/#kernel.panic/g' /etc/sysctl.conf
# Add configuration (which becomes effective after reboot)
cat <<EOF >>/etc/sysctl.conf

# Reboot after kernel hang
kernel.hung_task_timeout_secs=600
kernel.hung_task_panic=1
kernel.panic=300
EOF
# Activate config NOW
sysctl -w kernel.hung_task_timeout_secs=600
sysctl -w kernel.hung_task_panic=1
sysctl -w kernel.panic=300

The configuration works by converting the kernel hung event to a kernel panic event after kernel.hung_task_timeout_secs (10 minutes by default).

The configuration will be activated without reboot but it will also stay active after reboot.