千家信息网

如何恢复ext4文件系统被误删的文件

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,今天就跟大家聊聊有关如何恢复ext4文件系统被误删的文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。导读本文档给出了恢复ext4文件系统被误
千家信息网最后更新 2026年11月02日如何恢复ext4文件系统被误删的文件

今天就跟大家聊聊有关如何恢复ext4文件系统被误删的文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

导读本文档给出了恢复ext4文件系统被误删的文件的方法,需要使用的软件是extundelete,这款软件对ext4文件系统的恢复成功率比较高,值得拥有!
[root@localhost ~]# rm -Rf /   #执行不成功的!rm: 在"/" 进行递归操作十分危险rm: 使用 --no-preserve-root 选项跳过安全模式[root@localhost ~]# rm -rf /*    #这个可以执行成功! 呵呵。。。
ext4文件系统上删除文件,可以恢复: extundelete ,ext3恢复使用:ext3grepwindows恢复误删除的文件:  final data v2.0 汉化版  和  easyrecovery

扩展:

Linux文件系统由三部分组成:文件名,inode,blockwindows也由这三部分组成。a.txt          -->inode              --> block文件名       存放文件元数据信息       真正存放数据查看文件文件名:[root@localhost ~]# cp /etc/passwd a.txt[root@localhost ~]# ls a.txta.txt查看inode号:常识: 每个文件,有一个inode号。[root@localhost ~]# ls -i a.txt440266 a.txt查看inode中的文件属性;  通过stat命令查看inode中包含的内容[root@localhost ~]# stat a.txt   #查看inode信息:[root@localhost ~]# ls -l a.txt-rw-r--r-- 1 root root 1720 Oct 25 10:21 a.txtblock块:真正存储数据的地方逻辑删除:假删除为什么删除比复制快?

误删除文件后,第一件事要做什么? 你不心删除把存了几十年的大片删除了!
要避免误删除的文件内容被覆盖,如何避免?

卸载需要恢复文件的分区或者以只读的方式挂载
例如:

mount -o remount,ro /mnt

实战:恢复ext4文件系统被误删的文件

下载extundelete
http://sourceforge.net/ 开源软件发布中心

extundelete-0.2.4.tar.bz2
链接: https://pan.baidu.com/s/1n0dtGnhffcH7XrLv0TqUsw
提取码:a5m7

准备测试分区:

[root@localhost ~]# ls /dev/sd*/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb[root@localhost ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x539f33b8.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): p #查看分区表信息Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x539f33b8   Device Boot      Start         End      Blocks   Id  SystemCommand (m for help): n #创建一个新分区Command action   e   extended   p   primary partition (1-4)p #创建一个主分区Partition number (1-4): 1First cylinder (1-2610, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +1G #指定分区大小Command (m for help): p #查看分区表信息Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x539f33b8   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         132     1060258+  83  LinuxCommand (m for help): w #保存The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@localhost ~]# partx -a /dev/sdb1  #获得新分区表或者[root@localhost ~]# reboot

扩展:
如果在根下删除文件了,想恢复,怎么办?
方法1: 立即断电,然后把磁盘以只读方式,挂载到另一个电脑中进行恢复。
方法2:把extundelete在虚拟机上(虚拟机系统要和服务器版本一样),提前安装好后再复制到U盘中,把U盘插入服务器,恢复时,恢复的文件要保存到U盘中,(不要让恢复的数据写到/下,那样会覆盖之前删除的文件)。

使用新的分区:

[root@localhost ~]# mkdir /tmp/sdb1 #创建挂载点[root@localhost ~]# mkfs.ext4 /dev/sdb1 #把/dev/sdb1分区文件系统格式化成ext4[root@localhost ~]# mount /dev/sdb1 /tmp/sdb1 #把/dev/sdb1分区挂到/tmp/sdb1[root@localhost ~]# df -h Filesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root   18G  1.3G   16G   8% /tmpfs                         499M     0  499M   0% /dev/shm/dev/sda1                     485M   33M  427M   8% /boot/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom/dev/sdb1                    1020M   34M  935M   4% /tmp/sdb1

复制一些测试文件,然后把这些文件再删除,然后演示恢复:

[root@localhost ~]# cp /etc/passwd /tmp/sdb1[root@localhost ~]# cp /etc/hosts /tmp/sdb1 [root@localhost ~]# echo aaa > a.txt[root@localhost ~]# mkdir -p /tmp/sdb1/a/b/c[root@localhost ~]# cp a.txt /tmp/sdb1/a[root@localhost ~]# cp a.txt /tmp/sdb1/a/b[root@localhost ~]# touch /tmp/sdb1/a/b/kong.txt[root@localhost ~]# yum install -y tree[root@localhost ~]# tree /tmp/sdb1/tmp/sdb1├── a│   ├── a.txt│   └── b│       ├── a.txt│       ├── c #空目录│       └── kong.txt #空文件├── hosts├── lost+found└── passwd4 directories, 5 files

删除文件:

[root@localhost ~]# cd /tmp/sdb1[root@localhost sdb1]# lsa  hosts  lost+found  passwd[root@localhost sdb1]# rm -rf a hosts passwd [root@localhost sdb1]# lslost+found

误删除文件后,第一件事要做什么???
如何避免误删除的文件内容被覆盖???
卸载需要恢复文件的分区或者以只读的方式挂载

[root@localhost sdb1]# cd /root[root@localhost ~]# df -hFilesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root   18G  1.3G   16G   8% /tmpfs                         499M     0  499M   0% /dev/shm/dev/sda1                     485M   33M  427M   8% /boot/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom/dev/sdb1                    1020M   34M  935M   4% /tmp/sdb1[root@localhost ~]# echo "/dev/sdb1 /tmp/sdb1 ext4 defaults 0 0" >> /etc/fstab [root@localhost ~]# mount -o remount,ro /tmp/sdb1 #以读写的形式重新挂载/tmp/sdb1所在分区[root@localhost ~]# df -hFilesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root   18G  1.3G   16G   8% /tmpfs                         499M     0  499M   0% /dev/shm/dev/sda1                     485M   33M  427M   8% /boot/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom/dev/sdb1                    1020M   34M  935M   4% /tmp/sdb1[root@localhost ~]# touch /tmp//sdb1/testfiletouch: cannot touch `/tmp//sdb1/testfile': Read-only file system

或者

[root@localhost ~]# umount /tmp/sdb1 #卸载/tmp/sdb1所在分区[root@localhost ~]# df -hFilesystem                    Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root   18G  1.3G   16G   8% /tmpfs                         499M     0  499M   0% /dev/shm/dev/sda1                     485M   33M  427M   8% /boot/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom

安装extundelete工具

上传extundelete到Linux中:从Windows上传extundelete文件到Linux,安装SecureCRT或者XShell[root@localhost ~]# yum install -y lrzsz  # 安装后就有了rz命令和sz命令rz: 将Windows中的文件上传到Linuxsz: 将Linux中的文件下载到Windows

源码安装extundelete

[root@localhost ~]# cd /usr/local/src[root@localhost src]# ls[root@localhost src]# rzrz waiting to receive. zmodem trl+C ȡ  100%     105 KB  105 KB/s 00:00:01       0 Errorsbz2...[root@localhost src]# lsextundelete-0.2.4.tar.bz2[root@localhost src]# tar xjvf extundelete-0.2.4.tar.bz2 [root@localhost src]# cd extundelete-0.2.4[root@localhost extundelete-0.2.4]# yum install -y e2fsprogs-devel gcc*[root@localhost extundelete-0.2.4]# ./configure   #检查系统安装环境[root@localhost extundelete-0.2.4]# make  -j 4  #编译,把源代码编译成可执行的二进制文件。 -j 4   使用4进程同时编译,提升编译速度或者使用4核CPU同时编译。[root@localhost extundelete-0.2.4]# make install  #编译安装

扩展:

install 和cp 有什么区别? install 复制时可以指定权限  cp不可以例:[root@localhost ~]# install -m 777 /bin/find /opt/a.sh[root@localhost ~]# ll /opt/

开始恢复:

方法一:通过inode结点恢复
方法二:通过文件名恢复
方法三:恢复某个目录,如目录a下的所有文件:
方法四:恢复所有的文件

[root@localhost extundelete-0.2.4]# mkdir /test #创建一个目录使用于存放恢复的数据[root@localhost extundelete-0.2.4]# cd /test[root@localhost test]# 通过inode结点查看被删除的文件名字:[root@localhost test]# extundelete /dev/sdb1 --inode 2  File name                                       | Inode number | Deleted status.                                                 2..                                                2lost+found                                        11passwd                                            12             Deletedhosts                                             13             Deleteda                                                 7377           Deleted扩展:ext4文件系统的分区根目录的inode值为2,xfs分区根目录的inode值为64[root@localhost test]# ls -id /boot/   #xfs文件系统64 /boot/[root@localhost test]# ls -id /tmp/sdb12 /tmp/sdb1

方法一:通过inode结点恢复

[root@localhost test]# ls[root@localhost test]# extundelete /dev/sdb1 --restore-inode 12NOTICE: Extended attributes are not restored.Loading filesystem metadata ... 9 groups loaded.Loading journal descriptors ... 61 descriptors loaded.[root@localhost test]# lsRECOVERED_FILES[root@localhost test]# ls RECOVERED_FILES/file.12[root@localhost test]# diff /etc/passwd  RECOVERED_FILES/file.12 #对比文件内容,没有任何输出,说明恢复后的文件内容没有变化

方法二:通过文件名恢复

[root@localhost test]# extundelete /dev/sdb1 --restore-file passwd[root@localhost test]# diff /etc/passwd RECOVERED_FILES/passwd #对比文件内容,没有任何输出,说明恢复后的文件内容没有变化

方法三:恢复某个目录,如目录a下的所有文件:

[root@localhost test]# extundelete /dev/sdb1 --restore-directory a[root@localhost test]#  tree RECOVERED_FILES/a/RECOVERED_FILES/a/├── a.txt└── b    └── a.txt1 directory, 2 files

方法四:恢复所有的文件

[root@localhost test]# rm -rf RECOVERED_FILES/*[root@localhost test]# extundelete /dev/sdb1 --restore-all[root@localhost test]# ls RECOVERED_FILES/a  hosts  passwd[root@localhost test]# tree  RECOVERED_FILES/RECOVERED_FILES/├── a│   ├── a.txt│   └── b│       └── a.txt├── hosts└── passwd2 directories, 4 files

数据对比

删除前:

[root@localhost ~]# tree /tmp/sdb1/tmp/sdb1├── a│   ├── a.txt│   └── b│       ├── a.txt│       ├── c #空目录│       └── kong.txt #空文件├── hosts├── lost+found└── passwd4 directories, 5 files

恢复后:

[root@localhost test]# tree  RECOVERED_FILES/RECOVERED_FILES/├── a│   ├── a.txt│   └── b│       └── a.txt├── hosts└── passwd2 directories, 4 files

extundelete在恢复文件的时候能不能自动创建空文件和目录?
答:不能

看完上述内容,你们对如何恢复ext4文件系统被误删的文件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

文件 系统 方法 内容 数据 目录 编译 文件名 信息 成功 命令 方式 结点 软件 分区表 同时 所在 文件下载 服务器 根目录 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 喔噻互联网科技有限公司 山东特亿宝互联网科技有限公司 互联网金融 金融科技 互联网科技公司电话 互联网未来科技 互联网科技革命 上海卓越科技 互联网 人人互联网科技是培训 科技大学互联网专业好不好 博兴的互联网电子科技公司 贵州叶脉互联网科技有限公司所属行业 岳阳华臻互联网科技有限公司 速维有品互联网信息科技(苏州)有限公司 呼和浩特新华互联网科技学院 民营互联网公司国防科技 南博望互联网科技有限公司 银行科技岗属于互联网吗 有人说阿里系是互联网科技企业 互联网科技包装股份有限公司上市 互联网公司属于科技吗 互联网的科技 互联网科技财经 互联网扶贫科技 华宇互联网科技 深圳互联网络科技有限公司 米客互联网科技 互联网科技汛 科技大学互联网专业好不好 滨湖区互联网智能科技产品有哪些 科技互联网企业在行动
0