Linux下出现Read-only file system的解决办法
<article><div class="case-content-item" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><h2 class="case-item-title" style="box-sizing: inherit; margin: 1rem 0px 0px; padding: 0px 3px 1px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 1.6rem; line-height: 1.6rem; font-family: inherit; vertical-align: baseline; position: relative; display: inline-block;">问题描述</h2><div class="contents" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">涉及到修改/保存条目等需要写磁盘操作的命令都无法使用(如tar、cp、mv、rm、chmod、chown、wget下载等指令),总是提示Read-only file system,也就是说系统是只读的,什么也写不了。</p></div></div><div class="case-content-item" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><h2 class="case-item-title" style="box-sizing: inherit; margin: 1rem 0px 0px; padding: 0px 3px 1px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 1.6rem; line-height: 1.6rem; font-family: inherit; vertical-align: baseline; position: relative; display: inline-block;">处理过程</h2><div class="contents" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">1、查看/etc/fstab文件,在其中发现这样的一样记录(注意errors=remount-ro段),如下:</p><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">/dev/sda1 /ext3 errors=remount-ro 0 1</p><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">这种情况通常都是由于系统发现磁盘硬件故障或文件系统中文件被损坏之后而采取的保护机制导致的。为了保护数据不破坏分区中已有内容,Linux在挂载文件系统时就只用read-only只读方式加载了。至于挂载的文件系统为什么会莫名地变成以只读方式挂载的具体原因,这就不知道了。可能的原因有</p><table width="736"><tbody style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><tr style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;" class="firstRow"><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">a、系统文件损坏;<p style="box-sizing: inherit; margin-top: 21.6696px; margin-bottom: 21.6696px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;"><br/></p><p style="box-sizing: inherit; margin-top: 21.6696px; margin-bottom: 21.6696px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">b、 磁盘有坏道;</p><p style="box-sizing: inherit; margin-top: 21.6696px; margin-bottom: 21.6696px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">c、fstab文件配置错误,如分区格式错误错误(将ntfs写成了fat)、配置指令拼写错误等。</p></td></tr></tbody></table><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">如果能够确认数据和系统的文件没有被损坏,修复fstab文件配置后只要重新R/W加载或reboot就能够恢复正常。</p><table width="736"><tbody style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><tr style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;" class="firstRow"><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;"><br/></td><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">以读写方式重新挂载文件系统<p style="box-sizing: inherit; margin-top: 20.2946px; margin-bottom: 20.2946px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;"><br/></p><p style="box-sizing: inherit; margin-top: 20.2946px; margin-bottom: 20.2946px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">mount -o remount rw /</p></td></tr></tbody></table><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">如果机器上有重要文件,在重新加载文件系统前可以用scp命令将其备份到远程主机上:</p><table width="736"><tbody style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><tr style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;" class="firstRow"><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">1</td><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">scp -r import_dir/import_file user@host:backup_dir</td></tr></tbody></table><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">之所以使用scp -r命令备份重要目录/文件到远程主机上,而不用tar命令打包压缩后再传输,因为在用tar命令打包压缩文件/目录时会涉及到写磁盘操作,这会引起Read-only file system的错误。</p><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">如果是文件系统有问题,那就需要在umount状态下执行fsck命令来检查文件系统并修复文件系统中的错误。</p><table width="736"><tbody style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><tr style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;" class="firstRow"><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;"><br/></td><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">nohup fsck -y /dev/VolGroup00/LogVol00 > /dev/shm/fscklog &<p style="box-sizing: inherit; margin-top: 21.0625px; margin-bottom: 21.0625px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;"><br/></p><p style="box-sizing: inherit; margin-top: 21.0625px; margin-bottom: 21.0625px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;"># 检查好后重启 reboot</p></td></tr></tbody></table><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">如果是磁盘硬件损坏,最好的方法就是直接换一个新硬盘。如果你觉得旧硬盘扔了可惜,还可以将它低格之后,再重新安装系统,系统重新安装后,磁盘会重新分区。</p><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">如果仅仅是想将数据备份出来而且机器又在身边的话,你可以用live-cd从光盘启动系统,然后直接备份。当然此时你也可以修改硬盘中的配置文件,如/etc/fstab。</p></div></div><div class="case-content-item" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><h2 class="case-item-title" style="box-sizing: inherit; margin: 1rem 0px 0px; padding: 0px 3px 1px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 1.6rem; line-height: 1.6rem; font-family: inherit; vertical-align: baseline; position: relative; display: inline-block;">建议与总结</h2><div class="contents" style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">附:</p><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">另一种处理方法,方便简洁:</p><table width="736"><tbody style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><tr style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;" class="firstRow"><td style="box-sizing: inherit; margin: 0px; padding: 12px 6px; border-color: rgb(230, 233, 237); font: inherit; vertical-align: baseline;">1、以读写方式重新挂载文件系统 mount -o remount rw /</td></tr></tbody></table><p style="box-sizing: inherit; margin-top: 22.0893px; margin-bottom: 22.0893px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: 2rem; font-family: inherit; vertical-align: baseline;">2、在‘~’root用户的家目录下执行命令11?-a,到找.viminfo,在执行tar、cp、mv、rm、chmod、chown、wget命令,测试正常。</p></div></div></article><ul class="tags" style="list-style-type: none;"><li style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">centos read-only-file-system</li><li style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">linux read-only-file-system</li></ul><p><nav> </nav></p><p><br/></p>