问题问题来源
node
因为磁盘fsck检查异常,致使系统挂载以只读模式挂载根分区。linux
若是fsck检查后以只读模式挂载/分区,极可能fsck已经没法修复分区了shell
#开机启动会出现fsck对/分区fsck检测ubuntu
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):
-----------------------------------------------引用他文起-----------------------------------------------------------------------------------------安全
一、系统没法进行磁盘的读写操做(touch,cp,chmod)等等bash
二、服务器没法启动(也是由于没法建立文件)服务器
三、只有涉及到系统磁盘的写操做,都会报错"Read-only file system"ide
问题缘由:spa
一、系统没有正常关机,致使虚拟磁盘出现文件系统错误;code
二、机器硬盘故障致使硬盘只读
通常状况是因为系统发现磁盘硬件(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
在readonly的状况下,/分区能够进行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
#此时系统就能够正常读写,为了确保数据安全,没有作备份的,能够先对重要数据进行备份
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
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
If you want to fix filesystem errors, first unmountyour partition: umount /dev/xvda3
# 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 #能够在read only下修复 #挂载状况下没法修复 #/分区修复,要使用系统安装引导,进入修复模式,不要挂载文件系统
#此时发现,应该是思路问题,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挂载下执行
#umount / umount: /: device is busy. (In somecases useful info about processes that use the deviceis found by lsof(8) or fuser(1))
注意进入时不要选择挂载原系统!
此时执行fsck即可成功