Remount root partition

From Noah.org
Revision as of 18:07, 8 February 2011 by Root (talk | contribs)
Jump to navigationJump to search

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 -- assuming you have one handy.. Or you could just remount the read-only partition without rebooting. The trick is to remember 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 the options defined in defaults, which usually 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