Difference between revisions of "Remount root partition"

From Noah.org
Jump to navigationJump to search
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
 
+
[[Category:Disks_and_Filesystems]]
 
Sometimes, due to hubris or stupidity, you end up with a bad fstab entry for your root or /etc partition. Linux will detect errors and conveniently mount it as read-only, but now you can't edit /etc/fstab to fix the problem. You could break out a live-CD to fix the problem, but you can also just remount the read-only partition without rebooting. The trick is don't forget the "-n" option.  
 
Sometimes, due to hubris or stupidity, you end up with a bad fstab entry for your root or /etc partition. Linux will detect errors and conveniently mount it as read-only, but now you can't edit /etc/fstab to fix the problem. You could break out a live-CD to fix the problem, but you can also just remount the read-only partition without rebooting. The trick is don't forget the "-n" option.  
  

Revision as of 13:52, 25 August 2008

Sometimes, due to hubris or stupidity, you end up with a bad fstab entry for your root or /etc partition. Linux will detect errors and conveniently mount it as read-only, but now you can't edit /etc/fstab to fix the problem. You could break out a live-CD to fix the problem, but you can also just remount the read-only partition without rebooting. The trick is don't forget the "-n" option.

-n     Mount without writing in /etc/mtab.  
       This is necessary for example when /etc is on a read-only file system.

For example, this will remount / with defaults (defaults contains "rw"):

mount -n -o remount,defaults /dev/sda1 /
mount -n -o remount,defaults /dev/VolGroup00/LogVol00 /

I found that the most common reason for me screwing up my root partition is because I forgot run tune2fs before rebooting when I tune an ext3 filesystem for performance. This is harmless and easy to fix, but can be alarming.

Interestingly, I found the only way I could check the current mount option status was by looking at /proc/mounts. Using the `mount` command will show you if the partition is mounted and it will show the mount options requested, but it won't show the mount options actually in effect. The following example tests for "ro" options status on the / mount. This will return 0 if / is mounted read-only or 1 if not:

cut /proc/mounts -f 2,3,4 -d " " | grep -q ^/\\W.*\\Wro