Rebooting a Linux with I/O Errors

Rebooting a Linux with I/O Errors
Photo by Michael Dziedzic / Unsplash

When a Linux system encounters I/O errors and becomes unresponsive, rebooting it gracefully might not be possible. In such scenarios, you can use the SysRq mechanism to reboot the system forcibly. This tutorial explains how to reboot a Linux system with I/O errors using SysRq commands.


Steps to Reboot the System

1. Enable SysRq Commands

The SysRq mechanism must be enabled to allow low-level system commands. To enable it, run the following command as root or using sudo:

echo 1 > /proc/sys/kernel/sysrq

This writes the value 1 to the /proc/sys/kernel/sysrq file, enabling SysRq commands.

2. Trigger a Forced Reboot

Once SysRq is enabled, you can force the system to reboot by executing the following command:

echo b > /proc/sysrq-trigger

This writes the value b to /proc/sysrq-trigger, which instructs the kernel to perform an immediate reboot without syncing filesystems or unmounting disks.


Detailed Explanation

  • /proc/sys/kernel/sysrq: This file controls the SysRq functionality. Writing 1 to it enables all SysRq commands.
  • /proc/sysrq-trigger: This file is used to issue specific SysRq commands to the kernel. The b command instructs the kernel to reboot immediately.

Notes

  1. Unclean Reboot: Using the b option skips filesystem synchronization and unmounting, which can lead to data loss or filesystem corruption.
  2. Alternatives: If possible, attempt a graceful reboot using reboot or shutdown commands before resorting to SysRq.

Persistent SysRq Setting: To make SysRq permanently enabled across reboots, add the following line to /etc/sysctl.conf:

kernel.sysrq = 1

Then apply the change using:

sysctl -p

Common Scenarios for Using SysRq

  • The system is completely unresponsive due to hardware or software issues.
  • I/O errors prevent the system from syncing or shutting down properly.
  • Regular reboot commands (reboot, shutdown) fail to execute.

Final Reminder

Use the SysRq mechanism as a last resort when all other options to reboot the system are unavailable. It is a powerful tool but comes with risks due to its forceful nature.