Occasionally, as a result of a storage-related event, some partitions on a Linux machine may become read-only. In this article, we will explain how to correct this status and reduce the risks of a switch.
Topics
- Avoiding the Read-Only Switch of Your VM Disk on Linux
Avoiding the Read-Only Switch of Your VM Disk on Linux
When partitions are read-only, writing to the file system is no longer possible.
$ touch test
touch: cannot touch 'test': Read-only file system
The file system status can be confirmed using the mount
command:
$ mount
**/dev/sda1 on / type ext3 (ro,errors=remount-ro)**
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
To restore /
to read-write, the VM must be restarted.
Workaround Solution
By default, the timeout of SCSI devices is 30 seconds on Linux. VMware Tools can increase this time to 180 seconds. It is recommended to set the timeout to 3600 seconds. The following command will execute this for the current session:
$ echo 3600 > /sys/block/`basename /dev/sda`/device/timeout
To set this value at the VM's startup, you can put this command in the following file:
$ sudo vi /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # # Make sure that the script will "exit 0" on success or any other value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. echo 3600 > /sys/block/`basename /dev/sda`/device/timeout exit 0
Conclusion
Having read this article, you should be able to prevent and fix your partitions from switching to read-only.