ThunderHosting
EN

Fix "Read-only file system" on a Linux VPS

ThunderHosting ·

DeutschFrançaisItaliano

Why Linux suddenly switches the disk to read-only, how to check and repair the file system with fsck, and when to revert a snapshot instead.

If commands fail with Read-only file system, Linux has switched the system disk to read-only. The kernel does this on purpose when it finds file system errors, to stop the damage from spreading. You can still read your data, but nothing can be written until the file system has been checked.

1. Check what happened

bash
findmnt -no SOURCE,FSTYPE,OPTIONS /
sudo dmesg | grep -iE 'ext4|xfs|i/o error|read-only'

The first command shows the device of the system disk (for example /dev/vda1 or /dev/sda1), its file system and ro in the options. The kernel log usually shows the error that caused it. If your data matters, copy it off the server now (for example with scp or rsync from your computer) while it can still be read.

2. Restart the VPS

Restart the VPS on the Power tab of the server page in the control panel, or run reboot in the server. During boot, Ubuntu checks the system disk and repairs simple errors automatically. In many cases the server comes back up normally and writable.

3. Repair by hand from the console

If the server stops in emergency mode during boot, or the disk becomes read-only again, run the check yourself:

  1. Open the Console tab of the server page and click Open console.
  2. Log in as root.
  3. Make sure the disk is mounted read-only, run fsck on the device from step 1 and answer y to the repairs, then restart:
bash
mount -o remount,ro /
fsck -f /dev/vda1   # use the device from step 1
reboot

Never run fsck on a disk that is mounted read-write: this can destroy data. On xfs use xfs_repair instead of fsck.

4. If the repair does not help

  • Revert a snapshot on the Snapshots tab, if you created one before the problem started. This replaces the current disk with the snapshot.
  • Reinstall the operating system on the Reinstall tab and restore your data from your backup. Reinstalling erases the disk and all snapshots.
  • Errors that come back right after a repair can point to a problem outside your server: open a support ticket and include the output of the commands from step 1.

Also check the free space with df -h. A full disk does not make the file system read-only, but it causes similar write errors (No space left on device).

The Power, Console, Snapshots and Reinstall tabs are explained in Managing your VPS.