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.8 (1-Jan-2018)
Filesystem volume name:   <none>    #文件系统的名称
Last mounted on:          /a    #是否挂载及挂载点
Filesystem UUID:          cd22c2f7-d461-4cbe-973b-16d0b584a7b2
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (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:              655360    #inode总的个数
Block count:              2621440    #block总的个数
Reserved block count:     131072
Free blocks:              2554687    #空闲的block个数
Free inodes:              655344    #空闲的iNode个数
First block:              0    #第一个超级块编号=0
Block size:               4096    #块大小,这里是4k
Fragment size:            4096    #分块大小
Group descriptor size:    64
Reserved GDT blocks:      1024    #保留的GDT块大小
Blocks per group:         32768   #每个块组的block的个数
Fragments per group:      32768
Inodes per group:         8192    #每个块组的inode个数
Inode blocks per group:   512
…………

三、查看备份块

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

linux-iu82:/ # mkfs.ext4 -n /dev/sdb1
mke2fs 1.43.8 (1-Jan-2018)
/dev/sdb1 contains a ext4 file systemlast mounted on /a on Wed Jun 12 11:03:20 2019
Proceed anyway? (y,N) y
Creating filesystem with 2621440 4k blocks and 655360 inodes    #块大小4k
Filesystem UUID: 9e8e093e-183d-42ed-9e1f-b414673add53
Superblock backups stored on blocks:        #查看备份超级块32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

四、尝试修复超级块

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

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

      mkfs.type -n /dev/sdb1

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

    1.2.    尝试挂载备份块

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

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

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

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

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

wyc:/ # fsck.ext4 -b 32768 /dev/sdb1
e2fsck 1.43.8 (1-Jan-2018)
/dev/sdb1 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 #6 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong for group #42 (32254, counted=32252).
Fix<y>? yes
Free blocks count wrong for group #50 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong for group #58 (32254, counted=32253).
Fix<y>? yes
Free blocks count wrong (2558144, counted=2558139).
Fix<y>? yes
Free inodes count wrong for group #0 (8181, counted=8180).
Fix<y>? yes
Free inodes count wrong for group #6 (8192, counted=8191).
Fix<y>? yes
Directories count wrong for group #6 (0, counted=1).
Fix<y>? yes
Free inodes count wrong for group #42 (8192, counted=8189).
Fix<y>? yes
Directories count wrong for group #42 (0, counted=1).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group #50 (8192, counted=8191).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group #50 (0, counted=1).
Fix ('a' enables 'yes' to all) <y>? yes
Free inodes count wrong for group #58 (8192, counted=8191).
Fix ('a' enables 'yes' to all) <y>? yes
Directories count wrong for group #58 (0, counted=1).
Fix<y>? yes
Free inodes count wrong (655349, counted=655342).
Fix<y>? yes/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb1: 18/655360 files (0.0% non-contiguous), 63301/2621440 blocks

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

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

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

wyc:~ # mkfs.ext4 -S /dev/sdb1
mke2fs 1.43.8 (1-Jan-2018)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: 5c9e2db1-5cf6-4353-b051-7eefef7c6018
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating 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.8 (1-Jan-2018)
One or more block group descriptor checksums are invalid.  Fix<y>? yes
Group descriptor 0 checksum is 0x20a2, should be 0x8d20.  FIXED.
Group descriptor 1 checksum is 0x1342, should be 0xdec3.  FIXED.
Group descriptor 2 checksum is 0x1038, should be 0xddb9.  FIXED.
Group descriptor 3 checksum is 0xa34e, should be 0x6ecf.  FIXED.
Group descriptor 4 checksum is 0x1db9, should be 0xd038.  FIXED.
Group descriptor 5 checksum is 0xa2de, should be 0x6f5f.  FIXED.
Group descriptor 6 checksum is 0xf83c, should be 0x35bd.  FIXED.
Group descriptor 7 checksum is 0x4b4a, should be 0x86cb.  FIXED.
Group descriptor 8 checksum is 0x973c, should be 0x5abd.  FIXED.
Group descriptor 9 checksum is 0xe044, should be 0x2dc5.  FIXED.
Group descriptor 10 checksum is 0xe33e, should be 0x2ebf.  FIXED.
Group descriptor 11 checksum is 0xcf59, should be 0x02d8.  FIXED.
Group descriptor 12 checksum is 0xeebf, should be 0x233e.  FIXED.
Group descriptor 13 checksum is 0x9e92, should be 0x5313.  FIXED.
Group descriptor 14 checksum is 0xe851, should be 0x25d0.  FIXED.
Group descriptor 15 checksum is 0xc436, should be 0x09b7.  FIXED.
Group descriptor 16 checksum is 0x516a, should be 0x9ceb.  FIXED.
Group descriptor 17 checksum is 0xe962, should be 0x24e3.  FIXED.
Group descriptor 18 checksum is 0x3bc2, should be 0xf643.  FIXED.
Group descriptor 19 checksum is 0x75a2, should be 0xb823.  FIXED.
Group descriptor 20 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.2
e2fsck 1.43.8 (1-Jan-2018)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
/dev/sdb1 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
Block bitmap differences:  -(2138112--2162687)
Fix? yesFree blocks count wrong for group #16 (24544, counted=24543).
Fix? yesFree blocks count wrong for group #48 (24544, counted=24542).
Fix? yesFree blocks count wrong for group #64 (24544, counted=24543).
Fix? yesFree blocks count wrong (2554687, counted=2554683).
Fix? yesFree inodes count wrong for group #0 (8181, counted=8177).
Fix? yesFree inodes count wrong for group #16 (8192, counted=8191).
Fix? yesDirectories count wrong for group #16 (0, counted=1).
Fix? yesFree inodes count wrong for group #48 (8192, counted=8190).
Fix? yes

    修复后正常挂载即可。

转载于:https://www.cnblogs.com/xcbki/p/11288149.html

Ext4文件系统修复相关推荐

  1. android ext4 损坏,EXT4文件系统损坏导致的实例无法启动的排查与修复

    现象 某现网局点进行POC时,发现某DN core掉,且一直无法启动. core文件堆栈和dn的pg_log日志中的堆栈信息一致. 堆栈中显示 checkpoint 时进行 buffer 落盘时导致c ...

  2. Linux下的文件系统修复

    Linux下的文件系统修复 一.进行磁盘分区 二.格式成xfs文件系统 1.查看分区 2.格式化分区 三.挂载分区 1.查看分区的uuid 2.将挂载信息写入/etc/fstab 3.挂载分区 四.破 ...

  3. 由 OOM 引发的 ext4 文件系统卡死

    注:本问题影响 3.10.0-862.el7.centos 及之后的 CentOS 7 版本内核,目前问题还未被修复. 背景 近日,我司的测试同学发现内部集群中一个存储节点无法通过 ssh 访问了.i ...

  4. [ Linux驱动炼成记 ] 15 - 存储器EMMC中Ext4文件系统 中 磁盘空间占用率100%

    产品现象 : 设备(Linux 系统) 运行一段时间后,其中某一个分区 /et/config 突然占用率为100%,而实际空间可能1%都不到. 这种问题百思不得其解.谷歌/百度 所遇到的解决方案都是嵌 ...

  5. oracle+磁盘挂载格式化,oracle asm disk格式化恢复—格式化为ext4文件系统

    昨天中午接到一位朋友紧急求救电话,大概场景如下,asm data磁盘组一共把个asm disk,但是使用4个lun实现的(也就是说每个lun使用fdisk进行分区),该主机上还有一个lun是用来存放备 ...

  6. Linux ext4文件系统inode信息修改

    引文(引用博客:https://blog.csdn.net/stringnewname/article/details/73740155):Linux访问文件过程 1.当我们输入cat testfil ...

  7. linux ext4增加大小,如何修改 ext4 文件系统的大小

    如何修改 ext4 文件系统的大小 a. 扩大文件系统 i 启动到 Linux,umount 掉/dev/sdb1 和/dev/sdb2,若提示磁盘忙的话使用 fuser 将正在使用磁盘的程序 kil ...

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

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

  9. ext4 文件系统的优化

    ext4作为ext3的下一代,是Linux上的经典文件系统,功能上虽不及zfs.btrfs那么花哨,但是可靠实用,被广泛部署在企业级的生产环境中. ext4 作为一个通用文件系统,默认情况下已经工作良 ...

最新文章

  1. 前端进阶(三) webpack处理vue以及vue-cli脚手架环境
  2. github创建项目,并提交本地文件
  3. kettle将文件路径定义为_kettle_步骤解释
  4. tensorboard使用_tensorboard查看训练曲线
  5. plsql(轻量版)_基本语法
  6. 新UI云开发壁纸小程序源码(新修复版带编译教程)
  7. 【Kotlin】我的第一个 Kotlin 程序
  8. Mr.J-- jQuery学习笔记(七)--CSS类操作文本值操作
  9. C#指南,重温基础,展望远方!(11)C#委托
  10. php jquery ajax实现用户名,php+jquery+ajax实现用户名验证
  11. tensorflow CNN常用函数汇总
  12. 【2020CCPC秦皇岛:C】Cameraman(计算几何+思维+枚举)
  13. android的opengl教程,android opengl 教程
  14. 通用权限管理概要设计说明书
  15. python torch.optim模块
  16. ccf 节日 java 思路
  17. 瞎琢磨先生教你优雅的进行参数合法性校验
  18. 人工智能 漆桂林_认识一下计算机的新成员——人工智能
  19. linux下进程管理的原理,Linux进程管理:supervisor和nohup原理及使用
  20. 如何自学Python爬虫,python爬虫快速入门教程

热门文章

  1. sublime php快捷键,分享Sublime Text 3快捷键精华版!
  2. 计算机应用基础重点分析,计算机应用基础整体设计重点分析.doc
  3. Spring Cloud —— Gateway 服务网关
  4. php 设置agent,限制某个目录禁止解析php及user_agent、php相关配置
  5. 自定义键盘组件_一文读懂!iOS系统组件的设计规范全解
  6. python access 源码_连接的微软Access数据库,这是一个轻量级的Python模块(MDB格式)...
  7. 使用python构建三层神经网络、softmax函数
  8. arduino串口输入改变模式模块
  9. linux讲日志暂停,linux – Rsyslog在日志轮换后停止向远程服务器发送数据
  10. 通信与计算机技术的联系,通信技术与计算机技术融合发展论文