Difference between revisions of "Remount root partition"

From Noah.org
Jump to navigationJump to search
m
m
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
 
[[Category:Drives_and_Filesystems]]
 
[[Category:Drives_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 -- assuming you have one handy.. Or you could just remount the read-only partition without rebooting. The trick is to remember the '-n' option.  
+
Sometimes, due to hubris or stupidity, you may end up with a bad fstab entry for your root partition. Linux will detect errors and conveniently mount it as read-only, but then 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 remount the read-only partition without rebooting. The trick is to remember the '''-n''' option.
 
 
 
<pre>
 
<pre>
 
-n    Mount without writing in /etc/mtab.   
 
-n    Mount without writing in /etc/mtab.   
Line 8: Line 7:
 
</pre>
 
</pre>
  
For example, this will remount / with the options defined in '''defaults''', which usually contains "rw":
+
For example, the following will remount / with the options defined in '''defaults''', which usually contains '''rw''':
 
<pre>
 
<pre>
 
mount -n -o remount,defaults /dev/sda1 /
 
mount -n -o remount,defaults /dev/sda1 /
Line 16: Line 15:
 
I found that the most common reason for me screwing up my root partition is because I forgot [[Disk_Performance_Tuning#Before_you_reboot|run tune2fs before rebooting]] when I [[Disk_Performance_Tuning|tune an ext3 filesystem for performance]]. This is harmless and easy to fix, but can be alarming.
 
I found that the most common reason for me screwing up my root partition is because I forgot [[Disk_Performance_Tuning#Before_you_reboot|run tune2fs before rebooting]] when I [[Disk_Performance_Tuning|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:
+
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:
  
 
<pre>
 
<pre>
 
cut /proc/mounts -f 2,3,4 -d " " | grep -q ^/\\W.*\\Wro
 
cut /proc/mounts -f 2,3,4 -d " " | grep -q ^/\\W.*\\Wro
 
</pre>
 
</pre>

Revision as of 18:12, 8 February 2011

Sometimes, due to hubris or stupidity, you may end up with a bad fstab entry for your root partition. Linux will detect errors and conveniently mount it as read-only, but then 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 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, the following 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