· 准备阶段
由于条件原因,我只能在VMware虚拟机上进行模拟实验,开机的时候,发现sdb磁盘正常加载
然后通过lsblk命令查看挂载情况
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part /data sr0 11:0 1 1024M 0 rom
进入/data目录,查看内容,并新建文件test,写入一句话:“this is test file.”,查看test内容
[root@localhost ~]# cd /data/ [root@localhost data]# ls lost+found [root@localhost data]# echo "this is test file." > test [root@localhost data]# ls lost+found test [root@localhost data]# cat test this is test file.
发现可以查看并正常写入文件,现在进入破坏阶段
· 破坏阶段
硬盘进行分区格式化(ext4)会创建硬盘内的文件存取系统表(superblock、block、inode信息),文件新建、文 件写入到分区内,正常存取block块。
使用dd命令给硬盘写入文件,破坏硬盘内的文件存取系统表,给硬盘直接写入空文件。直接将文件写入给磁盘随机的扇 区里面。
[root@localhost /]# dd if=/dev/zero of=/dev/sdb bs=1 count=2048
2048+0 records in 2048+0 records out 2048 bytes (2.0 kB) copied, 0.00410516 s, 499 kB/s
破坏磁盘后,进入/data目录,写入文件test2
[root@localhost data]# touch test2 touch: cannot touch ‘test2’: Input/output error
发现写入文件报错,reboot重启机器报错,输入密码直接进入单用户系统
· 修复阶段
使用fsck修改文件系统
[root@localhiost ~]# fsck -t ext4 -y /dev/sdb fsck from util-linux 2.23.2 e2fsck 1.42.9(28-DEC-2013) ext2fs_open2:Bad magic number in super-block fsck.ext4:Superblock invalid,trying backup blocks... /dev/sdb was not cleanly unmounted, check forced. Pass 1 : Checking inodes,blocks,and sizes Pass 2 : Checking directory structure Pass 3 : Checking directory connectivity Pass 4 : Checking reference counts Pass 5 : Checking group summary information Free blocks count wrong for group #1 (31740, counted=31739). Fix? yes Free blocks count wrong (5116558, counted=5116557). Fix? yes Free inodes count wrong for group #0 (8181, counted=8180). Fix? yes Free inodes count wrong (1310709, counted=1310708). Fix? yes /dev/sdb : ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb : 12/1310720 files (0.0% non-contiguous), 126323/5242880 blocks
修复完成后reboot,重启系统。
重新进入系统,然后重新进行写入文件测试。
[root@localhost ~]# cd /data [root@localhost data]# ls lost+found test [root@localhost data]# cat test this is test file. [root@localhost deta]# echo "this is test2 file." > test2 [root@localhost data]# ls lost+found test test2 [root@localhost data]# cat test2 this is test2 file.