当前位置: 移动技术网 > 科技>操作系统>Linux > 如何修复被破坏的分区文件系统

如何修复被破坏的分区文件系统

2019年07月12日  | 移动技术网科技  | 我要评论

· 准备阶段

由于条件原因,我只能在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.

至此,分区文件系统修复完成。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网