The "REISUB" sequence is a well-known keyboard shortcut used to safely reboot a Linux system when it becomes unresponsive. It stands for the following actions, performed by holding down Alt + SysRq (or Print Screen) and pressing the corresponding keys one by one:
- R: UnRaw mode - Takes the keyboard out of raw mode.
- E: tErminate - Sends the SIGTERM signal to all processes, asking them to terminate gracefully.
- I: kIll - Sends the SIGKILL signal to forcefully terminate any remaining processes.
- S: Sync - Flushes data from the kernel's file buffers to disk to ensure filesystem consistency.
- U: Unmount - Remounts all filesystems in read-only mode to prevent further writes.
- B: reBoot - Reboots the system.
Why Sync Before Remount?
The key reason for syncing (S) before remounting (U) lies in ensuring data integrity and preventing filesystem corruption. Let’s break this down:
-
Sync (S):
- The
sync operation ensures that all pending changes in memory (cached writes) are flushed to disk. Filesystems often delay writing data to disk to improve performance, keeping modifications in memory buffers temporarily. If the system were to crash or reboot without syncing, these changes could be lost, leading to data loss or inconsistencies.
- By syncing first, you guarantee that all buffered data is written to disk, reducing the risk of losing important information.
-
Remount Read-Only (U):
- After syncing, the next step is to remount all filesystems as read-only. This prevents any further writes to the disk, which is crucial for maintaining the integrity of the filesystem during an emergency reboot.
- If you were to remount the filesystems as read-only before syncing, any unwritten changes in memory buffers would be discarded, potentially causing data loss or leaving the filesystem in an inconsistent state.
Order Matters
Performing the sync operation before remounting ensures that:
- All pending writes are safely committed to disk.
- The filesystem is then placed in a read-only state, protecting it from further modifications during the reboot process.
If the order were reversed (remounting read-only first), the system would lock itself into a state where no further writes are possible, including those required to flush the buffers to disk. This would leave the filesystem in an incomplete or corrupted state, defeating the purpose of the safe reboot sequence.
Summary
The sync operation is performed before remounting to ensure that all data in memory buffers is safely written to disk. This guarantees filesystem consistency and minimizes the risk of data loss or corruption when the system is rebooted. The sequence is carefully designed to prioritize data integrity and safe system recovery.
Final Answer:
Syncing before remounting ensures all pending writes are flushed to disk, preserving data integrity and preventing filesystem corruption.