Ext4文件系统修复

目录

一、 super block.................................................................................................................................................

二、查看分区设备信息.....................................................................................................................................

三、查看备份块................................................................................................................................................

四、尝试修复超级块.........................................................................................................................................

1. 已知文件系统格式...................................................................................................................................

2. 不确定文件系统.......................................................................................................................................

一、super block

硬盘分区开头、开头的第一个byte是byte0,从byte1024开始往后的一部分数据。由于block size最小时1024bytes,所以superblock在block1中(此时block的大小正好是1024bytes),也可能是在block 0中。

超级块保存了文件系统设定的文件块大小、操作函数、inode链表等重要信息。

二、查看分区设备信息

一般情况下我们是能够通过一些命令查看到分区的一些信息,如果super block有损坏,则该分区设备则不能够正常使用,还有可能不能通过命令查看设备分区的信息。

命令:

dumpe2fs          /dev/sdb1

tune2fs     -h      /dev/sdb1

linux-iu82:/ # dumpe2fs -h /dev/sdb1
dumpe2fs 1.43. (-Jan-)
Filesystem volume name: <none> #文件系统的名称
Last mounted on: /a #是否挂载及挂载点
Filesystem UUID: cd22c2f7-d461-4cbe-973b-16d0b584a7b2
Filesystem magic number: 0xEF53
Filesystem revision #: (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean #正常,异常:clean with errors或not clean whith errors
Errors behavior: Continue
Filesystem OS type: Linux #文件系统类型
Inode count: #inode总的个数
Block count: #block总的个数
Reserved block count:
Free blocks: #空闲的block个数
Free inodes: #空闲的iNode个数
First block: #第一个超级块编号=
Block size: #块大小,这里是4k
Fragment size: #分块大小
Group descriptor size:
Reserved GDT blocks: #保留的GDT块大小
Blocks per group: #每个块组的block的个数
Fragments per group:
Inodes per group: #每个块组的inode个数
Inode blocks per group:
…………

三、查看备份块

mkfs.ext4 -n /dev/sdb1(查看备份块时需要将分区卸载)

linux-iu82:/ # mkfs.ext4 -n /dev/sdb1
mke2fs 1.43. (-Jan-)
/dev/sdb1 contains a ext4 file system
last mounted on /a on Wed Jun ::
Proceed anyway? (y,N) y
Creating filesystem with 4k blocks and inodes #块大小4k
Filesystem UUID: 9e8e093e-183d-42ed-9e1f-b414673add53
Superblock backups stored on blocks: #查看备份超级块
, , , , , , ,

四、尝试修复超级块

  1. 1.   已知文件系统格式

    1.1.    在已知文件系统的情况下可以直接使用:

      mkfs.type -n /dev/sdb1

      进行查看分区的备份块。(注意查看备份块的时候需要将分区卸载)

    1.2.    尝试挂载备份块

    当文件系统出现损坏时,分区是挂载不上去的,这个时候尝试对分区备份块进行挂载,如果该备份超级块块可以被挂载上,并且上面数据没有问题,那么就可以使用该备份超级块进行修复

mount -t ext4 -o sb= /dev/sdb1 /a        #以32768为例,block的大小是4k,而mount的sb参数的块大小是1k,所以挂载时需要进行单位转换,转换成1k则是32768*=。
若挂载成功则可以使用该备份块进行修复

    1.3.    尝试使用备份块修复文件系统

      尝试修复前一定要先卸载该设备,否则会导致部分数据丢失

      且修复过程中需要确认的信息要自己观察分析,避免丢失数据

wyc:/ # fsck.ext4 -b  /dev/sdb1
e2fsck 1.43. (-Jan-)
/dev/sdb1 was not cleanly unmounted, check forced.
Pass : Checking inodes, blocks, and sizes
Pass : Checking directory structure
Pass : Checking directory connectivity
Pass : Checking reference counts
Pass : Checking group summary information
Free blocks count wrong for group # (, counted=).
Fix<y>? yes
Free blocks count wrong for group # (, counted=).
Fix<y>? yes
Free blocks count wrong for group # (, counted=).
Fix<y>? yes
Free blocks count wrong for group # (, counted=).
Fix<y>? yes
Free blocks count wrong (, counted=).
Fix<y>? yes
Free inodes count wrong for group # (, counted=).
Fix<y>? yes
Free inodes count wrong for group # (, counted=).
Fix<y>? yes
Directories count wrong for group # (, counted=).
Fix<y>? yes
Free inodes count wrong for group # (, counted=).
Fix<y>? yes
Directories count wrong for group # (, counted=).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group # (, counted=).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group # (, counted=).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group # (, counted=).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group # (, counted=).
Fix<y>? yes
Free inodes count wrong (, counted=).
Fix<y>? yes /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb1: / files (0.0% non-contiguous), / blocks

    1.4.    全部super block损坏修复(数据丢失风险大)

      在所有superblock损坏后,只能通过重建进行修复

      命令:  mkfs.ext4 -S /dev/sdb1

wyc:~ # mkfs.ext4 -S /dev/sdb1
mke2fs 1.43. (-Jan-)
Creating filesystem with 4k blocks and inodes
Filesystem UUID: 5c9e2db1-5cf6--b051-7eefef7c6018
Superblock backups stored on blocks:
, , , , , , , Allocating group tables: done
/dev/sdb1 may be further corrupted by superblock rewrite
Proceed anyway? (y,N) y
Skipping journal creation in super-only mode
Writing superblocks and filesystem accounting information: done

      重建完成后进行修复:fsck.ext4 -y /dev/sdb1

wyc:~ # fsck.ext4 -y /dev/sdb1
e2fsck 1.43. (-Jan-)
One or more block group descriptor checksums are invalid. Fix<y>? yes
Group descriptor checksum is 0x20a2, should be 0x8d20. FIXED.
Group descriptor checksum is 0x1342, should be 0xdec3. FIXED.
Group descriptor checksum is 0x1038, should be 0xddb9. FIXED.
Group descriptor checksum is 0xa34e, should be 0x6ecf. FIXED.
Group descriptor checksum is 0x1db9, should be 0xd038. FIXED.
Group descriptor checksum is 0xa2de, should be 0x6f5f. FIXED.
Group descriptor checksum is 0xf83c, should be 0x35bd. FIXED.
Group descriptor checksum is 0x4b4a, should be 0x86cb. FIXED.
Group descriptor checksum is 0x973c, should be 0x5abd. FIXED.
Group descriptor checksum is 0xe044, should be 0x2dc5. FIXED.
Group descriptor checksum is 0xe33e, should be 0x2ebf. FIXED.
Group descriptor checksum is 0xcf59, should be 0x02d8. FIXED.
Group descriptor checksum is 0xeebf, should be 0x233e. FIXED.
Group descriptor checksum is 0x9e92, should be 0x5313. FIXED.
Group descriptor checksum is 0xe851, should be 0x25d0. FIXED.
Group descriptor checksum is 0xc436, should be 0x09b7. FIXED.
Group descriptor checksum is 0x516a, should be 0x9ceb. FIXED.
Group descriptor checksum is 0xe962, should be 0x24e3. FIXED.
Group descriptor checksum is 0x3bc2, should be 0xf643. FIXED.
Group descriptor checksum is 0x75a2, should be 0xb823. FIXED.
Group descriptor checksum is 0xde81, should be 0x1300. FIXED.

    修复完成直接进行挂载即可。

  1. 2.   不确定文件系统

    在不知道文件系统的情况下,可以使用fsck -r /dev/sdb1 命令进行修复(注意提示内容),这种修复可能会导致文件正常恢复,但是文件系统发生改变,比如原本是ext4,修复后变成了ext3或ext2,需要手动升级一下。(一般不建议此方法)

    命令:Fsck -r /dev/sdb1

wyc:~ # fsck -r /dev/sdb1
fsck from util-linux 2.29.
e2fsck 1.43. (-Jan-)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
/dev/sdb1 was not cleanly unmounted, check forced.
Pass : Checking inodes, blocks, and sizes
Pass : Checking directory structure
Pass : Checking directory connectivity
Pass : Checking reference counts
Pass : Checking group summary information
Block bitmap differences: -(--)
Fix? yes Free blocks count wrong for group # (, counted=).
Fix? yes Free blocks count wrong for group # (, counted=).
Fix? yes Free blocks count wrong for group # (, counted=).
Fix? yes Free blocks count wrong (, counted=).
Fix? yes Free inodes count wrong for group # (, counted=).
Fix? yes Free inodes count wrong for group # (, counted=).
Fix? yes Directories count wrong for group # (, counted=).
Fix? yes Free inodes count wrong for group # (, counted=).
Fix? yes

    修复后正常挂载即可。

Ext4文件系统修复的更多相关文章

  1. linux操作系统故障处理-ext4文件系统超级块损坏修复

    linux操作系统故障处理-ext4文件系统超级块损坏修复   背景 前天外面出差大数据测试环境平台有7台服务器挂了,同事重启好了五台服务器,但是还有两台服务器启动不起来,第二天回来后我和同事再次去机 ...

  2. 如何进行服务器Linux系统下的ext文件系统修复

    一.故障描述 服务器是dell 730系列服务器,存储阵列是MD3200系列存储5T的Lun,操作系统是Linux centos 7,文件系统类型是EXT4,因意外断电,导致系统不能正常启动,修复之后 ...

  3. 恢复ext4文件系统superblock

    恢复ext4文件系统superblock 1. Create ext4 文件系统. [root@localhost ~]# mkfs.ext4 /dev/vdb1 [root@localhost ~] ...

  4. 使用hexdump工具追踪EXT4文件系统中的一个文件

    昨天追踪EXT4文件系统的过程中出了点问题,就是找不到文件,于是试了一下追踪FAT32文件系统的,成功之后有了点信心,今天继续嗑EXT4文件系统,终于找到啦,记录一下. 操作系统:linux(cent ...

  5. CentOS中对ext4文件系统做磁盘配额

    1.修改/etc/fstab文件,使ext4文件系统支持磁盘配额. UUID="9e6dc1e8-4fc1-4984-be38-524573572d41" /mnt/ext ext ...

  6. Centos 7 LVM xfs文件系统修复

    Centos 7 LVM xfs文件系统修复 今天一大早,zabbix开始报警了,一台linux主机出现问题. 登陆控制台查看,报如下错误. 解决方法如下: ls -l /dev/mapper xfs ...

  7. ext4文件系统的delalloc选项造成单次写延迟增加的分析

    最近我们的服务进程遇到kill -15后处于Z的状态,变为了僵尸进程,经过/proc/{thread_id}/stack查看其上线程的栈,发现是卡在了fwrite的过程中,而我们的系统中所有文件系统挂 ...

  8. Ext4文件系统架构分析(二)

    接着上一篇博文,继续分析Ext4磁盘布局中的元数据. 1.7 超级块 超级块记录整个文件系统的大量信息,如数据块个数.inode个数.支持的特性.管理信息,等待. 如果设置sparse_super特性 ...

  9. Ext4文件系统架构分析(一)

    本文描述Ext4文件系统磁盘布局和元数据的一些分析,同样适用于Ext3和Ext2文件系统,除了它们不支持的Ext4的特性外.整个分析分两篇博文,分别概述布局和详细介绍各个布局的数据结构及组织寻址方式等 ...

随机推荐

  1. 5、kubernetes资源清单定义入门

    使用配置清单创建资源 定义pod时使用yaml格式 master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE client / Error 1 ...

  2. 自在因梦 | 威爾伯的Fourth Turning所引發的聯想

    2015-05-06                                                 胡因梦                                       ...

  3. Python——GUI编程 利息计算器 作业9(python programming)

    import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class ...

  4. mysql的基本操作命令

    1,数据库操作: create database 数据库名 例:create database test; 亦或 create database test charset=utf8; 相关操作: 显示 ...

  5. 参考:菜菜的sklearn教学之降维算法.pdf!!

    PCA(主成分分析法) 1. PCA(最大化方差定义或者最小化投影误差定义)是一种无监督算法,也就是我们不需要标签也能对数据做降维,这就使得其应用范围更加广泛了.那么PCA的核心思想是什么呢? 例如D ...

  6. 亚马逊s3存储: aws cli上传工具速度和各文件大小关系探究

    1,背景介绍 公司最近最近统一了存储环境,由ftp文件存储全量转换为ceph存储.有业务组表示以前往ftp文件批量上传30万个文件1.3GB只需要16分钟左右.切换为ceph存储需要1个多小时,也就是 ...

  7. 02-初识CSS

    一. CSS介绍 CSS:Cascading Style Sheet,层叠样式表.CSS的作用就是给HTML页面标签添加各种样式,定义网页的显示效果.简单一句话:CSS将网页内容和显示样式进行分离,提 ...

  8. cisco路由的ip路由(一)

    路由Corp配置Corp#sh run Building configuration... Current configuration : 1652 bytes ! version 12.4 no s ...

  9. 【神经网络与深度学习】gflags介绍

    gflags是什么: gflags是google的一个开源的处理命令行参数的库,使用c++开发,具备python接口,可以替代getopt. gflags使用起来比getopt方便,但是不支持参数的简 ...

  10. 【C/C++语言】指针常量与常量指针的区别

    三个名词虽然非常绕嘴,不过说的非常准确.用中国话的语义分析就可以很方便地把三个概念区分开. 一) 常量指针. 常量是形容词,指针是名词,以指针为中心的一个偏正结构短语.这样看,常量指针本质是指针,常量 ...