Recover a Read-Only Root Filesystem with fsck
Goal
Bring a Linux node whose root filesystem was remounted read-only (after journal or block errors) back to read-write, without reinstalling it.
Prerequisites
- Console or SSH access to the node, with
sudo. - The root filesystem currently mounted read-only: check with
findmnt -n -o OPTIONS /(it must showro).
Steps
- Rule out the look-alike first. If
/is read-only right after every boot, check that/etc/fstabstill has an active entry for/; if it doesn't, there is nothing to repair withfsck(see With No Active Root Entry in fstab, systemd Leaves the Root Filesystem Read-Only on Every Boot):
Then check the disk before repairing it:grep -v '^#' /etc/fstab # a line for "/" must be there sudo journalctl -k -b -1 | grep -iE 'EXT4-fs error|I/O error' # errors here = a real faultlsblk -no PKNAME "$(findmnt -n -o SOURCE /)"names the disk under the root partition (e.g.sda), andsudo smartctl -H -A /dev/sdareports its health (reallocated, pending or uncorrectable sectors mean replace the drive). - (Optional) If you must run automation against the locked node first (to stop it cleanly, for example), send Ansible's temporary files to RAM-backed
/tmp, which stays writable when it's atmpfs:ansible all -b -e ansible_async_dir=/tmp/.ansible_async \ -m shell -a "shutdown -h now" -B 1 -P 0 - Find the root device instead of guessing
/dev/sda1:ROOT_DEV=$(findmnt -n -o SOURCE /) - Check and repair, answering yes to every fix (there can be thousands):
sudo fsck -y "$ROOT_DEV" - Once it reports the filesystem clean, reboot (
sudo reboot; if it hangs on the read-only root, hold the power button). The kernel still holds its own view of the filesystem it had mounted, so remounting read-write without a reboot risks writing over whatfsckjust repaired. Remount (sudo mount -o remount,rw /) only if you must reach the node before it can be rebooted, then reboot as soon as possible.
Verify
-
findmnt -n -o OPTIONS /showsrw. -
touch /var/tmp/write-test && rm /var/tmp/write-testsucceeds (on the disk itself, not on/tmp, which may be in RAM). -
dmesg | grep -i -E "ext4|I/O error"shows no new errors.
Troubleshooting
fscksaysclean, yet/is read-only again after every reboot: without-f, e2fsck only reads the clean flag; the filesystem is probably fine and the fstab root entry is missing (step 0).- Remount fails with "write-protected" after a clean fsck: the drive itself has switched to read-only, typical of a dying SSD. Replace it.
- Errors come back after a few days: check the drive's health with
smartctl -a "$ROOT_DEV"before trusting the node again.
References
- The Read-Only Lockdown: Recovering a Bare-Metal Node from a Kernel Panic - the incident this runbook comes from.
- With No Active Root Entry in fstab, systemd Leaves the Root Filesystem Read-Only on Every Boot - the cause when everything checks out clean.
- e2fsck(8) man page - options and the warning about mounted filesystems.
- Ansible documentation: Asynchronous actions -
-B,-Pandansible_async_dir. - Linux Administration MOC - hub for Linux notes.