问题问题来源
由于磁盘fsck检查异常,导致系统挂载以只读模式挂载根分区。
如果fsck检查后以只读模式挂载/分区,很可能fsck已经无法修复分区了
问题描述
#开机启动会出现fsck对/分区fsck检测
Checking all file systems. [/sbin/fsck.ext4 (1) -- /] fsck.ext4 -a /dev/xvda3 /dev/xvda3 contains a file system with errors, check forced. /dev/xvda3: Inodes that were part of a corrupted orphan linked list found. /dev/xvda3: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. (i.e., without -a or -p options) [FAILED] *** An error occurred during the file system check. *** Dropping you to a shell; the system will reboot *** when you leave the shell. Give root password for maintenance (or type Control-D to continue):
-----------------------------------------------引用他文起-----------------------------------------------------------------------------------------
1、系统无法进行磁盘的读写操作(touch,cp,chmod)等等
2、服务器无法启动(也是因为无法创建文件)
3、只有涉及到系统磁盘的写操作,都会报错"Read-only file system"
问题原因:
1、系统没有正常关机,导致虚拟磁盘出现文件系统错误;
2、机器硬盘故障导致硬盘只读
一般情况是由于系统发现磁盘硬件(Riad卡,硬盘)故障或文件系统中文件被损坏后而采取的保护机制导致的。为了保护数据不破坏分区中已有内容,Linux在挂载文件系统是就只用read-only只读方式加载。
(此段引用自- http://wangjun51.blog.51cto.com/6124567/1559470)
-----------------------------------------------引用他文结束----------------------------------------------------------------------------------------
#此时输入密码进入系统就会以只读模式挂载根分区
cat /proc/mounts rootfs / rootfs rw 0 0 proc /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,relatime 0 0 devtmpfs /dev devtmpfs rw,relatime,size=465516k,nr_inodes=116379,mode=755 0 0 devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,relatime 0 0 /dev/xvda3 / ext4 ro,relatime,barrier=1,data=ordered 0 0 /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0 /dev/xvda3 / ext4 ro,relatime,barrier=1,data=ordered 0 0
处理过程
先进行文件系统卸载
umount /dev/xvda3 or umount /
(实验证实umount对下个mount步骤没有影响)
重新以rw,remount挂载分区
mount -o rw,remount / ]# cat /proc/mounts rootfs / rootfs rw 0 0 proc /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,relatime 0 0 devtmpfs /dev devtmpfs rw,relatime,size=465516k,nr_inodes=116379,mode=755 0 0 devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,relatime 0 0 /dev/xvda3 / ext4 rw,relatime,barrier=1,data=ordered 0 0 /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
#此时系统就可以正常读写,为了确保数据安全,没有做备份的,可以先对重要数据进行备份
如何解决Read-only file system
1. 查看/etc/fstab
UUID=d642f775-751f-44f8-b1b8-416af4440e40 / ext4 defaults 1 1
2. 查看/proc/mounts
rootfs / rootfs ro 0 0
3. 卸载根分区
umount /
4. 重新挂载根分区
mount -o rw,remount /
#如果挂载成功此时就可以先保存下重要资料了
5. 此时重新挂载后,就可以修改/etc/fstab了
UUID=d642f775-751f-44f8-b1b8-416af4440e40 / ext4 defaults 1 0
知识点:
#-o <选项>指定挂载文件系统时的选项 rw 读写 remount 重新挂载 #第一个数字"1"该选项被"dump"命令使用来检查一个文件系统应该以多快频率进行转储,若不需要转储就设置该字段为0 #第二个数字"2"该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序,根文件系统"/"对应该字段的值应该为1,其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0
重点: 正是因为正常情况下第二个数字为1,根分区启动是会被fsck扫描,当根分区出现异常时,就会被以只读模式挂载。
6. 重启系统
尝试修复文件系统
# fsck -y /dev/xvda3 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) /dev/xvda3 is mounted. e2fsck: Cannot continue, aborting. #如果文件系统被挂载,很可能无法执行fsck
解决- e2fsck: Cannot continue, aborting问题
参考谷歌 http://askubuntu.com/questions/536955/e2fsck-cannot-continue-aborting
If you just usefsckto check the volume you can run
fsck -nf /dev/xvda3 n -> dry-run: will not do any change (just checking) f -> force : sometimes it sayscleanbut you can force a new check 结果: # fsck -nf /dev/xvda3 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) Warning! /dev/xvda3 is mounted. Warning: skipping journal recovery because doing a read-only filesystem check. Pass 1: Checking inodes, blocks, and sizes Inodes that were part of a corrupted orphan linked list found. Fix? no Inode 132428 was part of the orphaned inode list. IGNORED. Inode 665432 was part of the orphaned inode list. IGNORED. Inode 665642 was part of the orphaned inode list. IGNORED. Deleted inode 665645 has zero dtime. Fix? no Deleted inode 665685 has zero dtime. Fix? no Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: -557404 -562648 -562702 -562781 -562827-562869 -562920 -562963 -563046 -563090 -563138 -563184 -563747 -563787 -563832-2631031 -(2698588--2698614) -(2714719--2714745) -(2723791--2724297) Fix? no Free blocks count wrong (4222558,counted=4220120). Fix? no Inode bitmap differences: -132428 -665432 -665642 -665645 -665685 Fix? no Directories count wrong for group #81 (262,counted=261). Fix? no Free inodes count wrong (1166629,counted=1166581). Fix? no /dev/xvda3: ********** WARNING: Filesystemstill has errors ********** /dev/xvda3: 67947/1234576 files (0.2%non-contiguous), 706722/4929280 blocks
并没有修复ok,那么是不是挂载了影响的?
If you want to fix filesystem errors, first unmountyour partition: umount /dev/xvda3
如果没有修改fstab进行重启
# umount /dev/svda3 # fsck -nf /dev/xvda3 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Inodes that were part of a corrupted orphanlinked list found. Fix? no Inode 132428 was part of the orphaned inodelist. IGNORED. Inode 665432 was part of the orphaned inodelist. IGNORED. Inode 665642 was part of the orphaned inodelist. IGNORED. Deleted inode 665645 has zero dtime. Fix? no Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: -557404 -562648 -562702 -562781 -562827-562869 -562920 -562963 -563046 -563090 -563138 -563184 -563747 -563787 -563832-2631031 -(2714719--2714745) -(2723791--2724297) Fix? no Inode bitmap differences: -132428 -665432 -665642 -665645 Fix? no Directories count wrong for group #81 (262,counted=261). Fix? no /dev/xvda3: ********** WARNING: Filesystemstill has errors ********** /dev/xvda3: 67971/1234576 files (0.2%non-contiguous), 708714/4929280 blocks
进行修复
#fsck /dev/xvda3 .................................. /dev/xvda3: ***** FILE SYSTEM WAS MODIFIED***** /dev/xvda3: ***** REBOOT LINUX ***** /dev/xvda3: 67990/1234576 files (0.2%non-contiguous), 708579/4929280 blocks
#此时发现,应该是思路问题,umount并未卸载/分区
# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda3 19G 2.3G 16G 14% / # cat /proc/mounts rootfs / rootfs rw 0 0 proc /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,relatime 0 0 devtmpfs /dev devtmpfsrw,relatime,size=465516k,nr_inodes=116379,mode=755 0 0 devpts /dev/pts devptsrw,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,relatime 0 0 /dev/xvda3 / ext4ro,relatime,barrier=1,data=ordered 0 0 /proc/bus/usb /proc/bus/usb usbfsrw,relatime 0 0
#根分区没有被卸载
#umount / #根本没有起到效果
#可以肯定fsck可以只reda only挂载下执行
如果修改fstab并进行重启
#umount / umount: /: device is busy. (In somecases useful info about processes that use the deviceis found by lsof(8) or fuser(1))
进入救援模式对分区进行修复
注意进入时不要选择挂载原系统!
此时执行fsck便可成功