Problem Description

Commands that require writing to disk such as tar, cp, mv, rm, chmod, chown, wget download, etc. are not available, and always prompt “Read-only file system”, which means the system is read-only and nothing can be written.

Solution Process

Check the /etc/fstab file, and find the same record like this in it (note the errors=remount-ro paragraph), as follows.

1
/dev/sda1 /ext3 errors=remount-ro 0 1

This situation is usually caused by the protection mechanism adopted by the system after discovering a disk hardware failure or file corruption in the file system. In order to protect the data from destroying the existing contents of the partition, Linux mounts the file system in read-only mode. The exact reason why a mounted file system somehow becomes read-only is unknown. Possible reasons are as follows.

  • System file corruption.
  • Bad sectors on the disk.
  • Wrong fstab file configuration, such as wrong partition format error (writing ntfs as fat), wrong spelling of configuration commands, etc.

If you can confirm that the data and system files are not corrupted, simply reload or reboot the fstab file after repairing its configuration and it will be back to normal.

Remount the file system as a read/write.

1
mount -o remount rw /

If there are important files on the machine, you can use the scp command to back them up to a remote host before reloading the file system.

1
scp -r import_dir/import_file user@host:backup_dir

The reason why you use the scp -r command to backup important directories/files to the remote host instead of using the tar command to pack and compress them before transferring them is that packing and compressing files/directories with the tar command involves a write disk operation, which can cause a Read-only file system error.

If there is a problem with the file system, then you need to execute fsck command in umount state to check the file system and fix the errors in the file system.

1
2
nohup fsck -y /dev/VolGroup00/LogVol00 > /dev/shm/fscklog &
# Reboot after checking

If the disk hardware is damaged, the best way is to just get a new hard drive. If you think it’s a pity to throw away the old hard drive, you can also re-install the system after it is Low-Level Formatted, and the disk will be repartitioned after the system is reinstalled.

If you just want to back up your data and have the machine with you, you can use live-cd to boot the system from the CD and then back it up directly. Of course at this point you can also modify the configuration file on the hard disk, such as /etc/fstab.