首页 > 编程知识 正文

linux删除的东西怎么恢复,linux删除重新安装

时间:2023-05-05 11:58:41 阅读:257378 作者:1966

文件恢复的原

简单介绍

Linux 文件系统的最基本单元:inode。inode 译成中文就是索引节点,每个存储设备(例如硬盘)或存储设备的分区被格式化为文件系统后,应该有两部份,一部份是 inode,另一部份是 block,block 是用来存储数据用的。而 inode 呢,就是用来存储这些数据的信息,这些信息包括文件大小、属主、归属的用户组、读写权限等。

inode 为每个文件进行信息索引,所以就有了 inode 的数值。在 ext3 和 ext4 文件系统中,每个文件都是通过 inode 来描述其数据存放的具体位置,当文件被删除以后,inode 的数据指针部分被清零,文件目录区没有太多变化。文件的读写都是通过 inode 来实现,当 inode 数据指针被清零以后,即便文件内容还在,也没有办法把文件内容组合出来。

当 ext3 和 ext4 文件系统中的元数据 metadata 发生变化时,相应的元数据 metadata 在日志文件会有一份拷贝。比如一个文件被删除了,它的 inode 信息会在日志文件中先保存一份,然后把要删除文件 inode 相关信息清零。这个日志文件是循环使用的,当操作过多时,删除的文件的 inode 日志记录会被新的数据替换,这就彻底丧失了根据 inode 找回数据的机会了。

如果是大量文件的删除,这个日志文件会被反复循环利用多次,只留给最后删除的那些文件的恢复机会。

linux 操作系统下可以使用 ls –id 或者 stat 命令来查看文件或者目录的 inode 值

[root@crushlinux ~]# stat install.log

File: “install.log”

Size: 34226 Blocks: 80 IO Block: 4096 一般文件

Device: 303h/771d Inode: 4672098 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2014-05-06 14:49:22.000000000 +0800

Modify: 2013-05-04 22:24:21.000000000 +0800

Change: 2013-05-04 22:24:38.000000000 +0800

[root@crushlinux ~]# ls -i install.log

4672098 install.log

上面信息给出install.log文件的inode号码为:4672098

formost 是一个基于文件头和尾部信息以及文件的内建数据结构恢复文件的命令行工具。这个过程通常叫做数据挖掘(data carvubg)。formost 可以分析由 dd、Safeback、Encase 等生成的镜像文件,也可以直接分析驱动器。文件头和尾可以通过配置文件设置,也可以通过命令行开关使用 formost 内建的文件类型。formost 最初是由美国空军特别调查室(Air Force Office of Special Investigations)和信息系统安全研究中心(The Center for Information Systems Security Studies and Research)开发的,现在使用 GPL 许可。Foremost 支持恢复如下格式:avi, bmp, dll, doc, exe, gif, htm, jar, jpg, mbd, mov, mpg, pdf, png, ppt, rar, rif, sdw, sx, sxc, sxi, sxw, vis, wav, wmv, xls, zip。

针对 Linux 下的 ext 文件系统来说,常用的 Linux 文件删除恢复工具有 debugfs、ext3grep、extundelete 等。extundelete 是一个开源的数据恢复工具,支持 ext3、ext4 文件系统,其官方站点位于 http://extundelete.sourceforce.net/,目前最新稳定版本为 0.2.0。

上面介绍的两种命令行工具 foremost 和 extundelete 二者相比,foremost 支持的文件系统比较多(包括 ext2、 ext3 、vfat、NTFS、ufs、jfs 等)和 extundelete 支持的文件系统较少(ext3、ext4)文件系统。不过 foremost 只能支持恢复特定格式的文件。

模拟实验环境:

[root@crushlinux ~]# cd ~/Desktop

[root@crushlinux Desktop]# ls

desktop.png

[root@crushlinux Desktop]# rm -f desktop.png

[root@crushlinux Desktop]# cd /root/

下载并编译安装 foremost:

[root@crushlinux ~]# wget http://foremost.sourceforge.net/pkg/foremost-1.5.7.tar.gz

[root@crushlinux ~]# tar xf foremost-1.5.7.tar.gz -C /usr/src/

[root@crushlinux ~]# cd /usr/src/foremost-1.5.7/

[root@crushlinux foremost-1.5.7]# ls

api.c cli.c dir.c extract.c foremost.8.gz helpers.c main.h ole.h state.c

CHANGES config.c engine.c extract.h foremost.conf main.c Makefile README

[root@crushlinux foremost-1.5.7]# make && make install

先确定被删除文件的所在分区,我的文件在/root/Desktop/下属于/,而/上挂载了设备 /dev/hda3

[root@crushlinux foremost-1.5.7]# mount

/dev/hda3 on / type ext3 (rw)

[root@crushlinux foremost-1.5.7]# foremost -t png -i /dev/hda3

恢复完成后会在你的当前所在目录中建立一个 output 目录,并在在 output 目录下会建立 png 子目录下会包括所有已经恢复回来的 png 格式的文件。

注意:恢复回来的文件,文件名已经改变,另外 output 目录下有一个 audit.txt 文件是恢复成功文件的列表。

[root@crushlinux output]# pwd

/usr/src/foremost-1.5.7/output

[root@crushlinux output]# ls

audit.txt png

[root@crushlinux output]# cd png

[root@crushlinux png]# ls -l 38019080.png

-rw-r--r-- 1 root root 13024 05-06 14:39 38019080.png

原本叫 desktop.png 的文件恢复回来之后文件名改成 38019080.png,需要自己找哦!!

恢复多种类型文件

[root@crushlinux abc]# ls

file.doc file.pdf

[root@crushlinux abc]# rm -f *

[root@crushlinux abc]# ls

[root@crushlinux abc]# foremost -v -t pdf,doc -i /dev/hda1 -o /tmp/recover

[root@crushlinux abc]# ls

file.doc file.pdf

[root@crushlinux abc]# rm -f *

[root@crushlinux abc]# ls

[root@crushlinux abc]# foremost -v -t pdf,doc -i /dev/hda1 -o /tmp/recover

foremost version 1.5.7 by Jesse Kornblum, Kris Kendall, and Nick Mikus.

foremost [-xsdsg] [-t ] [-s ] [-k ]

[-b ] [-c ] [-o

-V - display copyright information and exit

显示版权信息并退出

-t - specify file type. (-t jpeg,pdf ...)

指定的文件类型

-d - turn on indirect block detection (for UNIX file-systems)

打开间接块检测

-i - specify input file (default is stdin)

指定输入文件

-a - Write all headers, perform no error detection (corrupted files)

写出所有头文件,检测是否有错误

-w - Only write the audit file, do not write any detected files to the disk

只写审计文件,不写所有检测到的文件到磁盘

-o - set output directory (defaults to output)

指定输出目录

-c - set configuration file to use (defaults to foremost.conf)

设置配置文件并使用

-q - enables quick mode. Search are performed on 512 byte boundaries.

可使用快速模式,搜索是在512字节边界进行。

-Q - enables quiet mode. Suppress output messages.

可使用快速模式,抑制输出消息。

-v - verbose mode. Logs all messages to screen

详细模式,记录所有消息到屏幕

切记:硬盘有价,数据无价!!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。