Linux File Recovery Study
Background
Today I did stupid things that I went into the ~/Downloads/ and pressed [Alt] + [A] then [Shift] + [Delete]. Wtf... I didn't want to delete this folder but another sub-folder...... So no zuo no die : )
Theory
Generally, Linux filesystem mainly contains inode and blocks. inode is the index of file or directory; blocks stores the actual data.
Usually, our rm or [Shift] + [Delete] in GUI just modify the inode but do not rewrite the blocks in which your data has ever be (If you use some special professional softwares to delete file, good luck : ) ).
So if our file is just there as it was before if we take measures in time. We can't use filename or inode to fetch it, but there are other probably ways to make it.
EMPTY. I want to add more filesystem knowledge here later. Remind me of it, OK ?
P.S. The filesystem is very interesting. You can regard it as local Domain Name System to some extent. And the filename is something like the domain name, while inode is something like IP address.
Recovery
Environment: Linux (I tried on Ubuntu 14.04 & CentOS 6.0)
Filesystem: Ext4 [1]
Of course, you'd better be root and everything will be easier.
0x0 Forbid other users and processes to Modify the filesystem
~If no speical prompts, you'd better follow this part to protect your data.
~Now we test on /dev/sda8 mounting at /tmp. sth in /tmp may be erased after mounting or unmounting, but sth in /tmp/lost+found may not.
~I usecat /proc/meminfo > /tmp/lost+found/tetto create a test file and delete it.
~fs means filesystem.
~sth means something.
For the test, I md5sum /tmp/lost+found/tet before deleting it

Before unmounting, use ls -id /tmp and take down the inode number
- use
dforfdisk -lto determine the fs to be unmounted unmount it:
umount /dev/sda8

mount the fs with read-only state:
mount -r -n /dev/sda8And you can have a try to write sth and find failed.
P.S.
~When I man umount I foundumount /dev/sda8is not recommended and it's better to useumount /tmp(directory name). And after Imount -r -n /dev/sda8, I failed to useumount /dev/sda8to unmount it.
~If the fs is busy and you can't unmount it. You can usefuser -v -m /dev/sda8to find the processes using it and kill them. What's more, you can usefuser -k -v -m /dev/sda8to kill them automatically.
Here I will give some methods I have tried(the title is the main tool to be used).
0x1 extundelete
yum install e2fsprogs e2fsprogs-libs e2fsprogs-develwget http://tenet.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
If you didn't install g++ like me,yum install gcc-c++./configuremake && make installextundelete /dev/sda8 --inode 2to check

extundelete /dev/sda8 --restore-directory lost+found
here I use --restore-directory, you can also use --restore-file RELATIVE-PATH-OF-FILEmd5sum ./RECOVERD_FILES/lost+found/tet

Bingo~
P.S.
You can also use extundelete /dev/sda8 --restore-all simply.
0x02 debugfs & dd
...
0x03 testdisk
...
Finally
Some advice:
- Backup is very very important
- Disk should be parted into filesystems (/,/home,/boot,/var,/usr,swap,...)
alias rm="rm -i"
Quotations
I learnt knowledge from articles below. Thanks for the authors' sharing.
Appendix
[1] How to determine your filesystem?
fdisk -l # to get the name of disk. E.g. /dev/sda5
You can also usedfand this tool can show the relationship between fs and your directories. However, this tool can only deal with fs being mounted.file -s /dev/sda5

Linux File Recovery Study的更多相关文章
- chattr lsattr linux file system attributes - linux 文件系统扩展属性
我们使用 linux 文件系统扩展属性,能够对linux文件系统进行进一步保护:从而给文件 赋予一些额外的限制:在有些情况下,能够对我们的系统提供保护: chattr命令用来改变文件属性.这项指令可改 ...
- Windows File Recovery - 微软官方文件恢复工具
假如你不小心误删除了文件或因各种意外情况丢失数据后,你可以通过 微软这款工具 这个工具来尝试恢复它们.WinFR 工具支持读取本机硬盘.移动硬盘.U 盘,或者连接相机.手机.使用读卡器来恢复 SD.T ...
- Linux— file命令 用于辨识文件类型
Linux file命令用于辨识文件类型. 通过file指令,我们得以辨识该文件的类型. 语法 file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...] ...
- 磁盘、分区及Linux文件系统 [Disk, Partition, Linux File System]
1.磁盘基础知识 1.1 物理结构 硬盘的物理结构一般由磁头与碟片.电动机.主控芯片与排线等部件组成:当主电动机带动碟片旋转时,副电动机带动一组(磁头)到相对应的碟片上并确定读取正面还是反面的碟面,磁 ...
- Linux File System Change Monitoring Technology、Notifier Technology
catalog . 为什么要监控文件系统 : hotplug . udev . fanotify(fscking all notification system) . inotify . code e ...
- Linux File System
目录 . Linux文件系统简介 . 通用文件模型 . VFS相关数据结构 . 处理VFS对象 . 标准函数 1. Linux文件系统简介 Linux系统由数以万计的文件组成,其数据存储在硬盘或者其他 ...
- Linux File、File Directory IO Operation Summary(undone)
目录 . 引言 . Linux下文件操作API . Linux下文件目录操作API . Linux下的其他设备操作API 1. 引言 Linux支持多种文件系统,如ext.ext2.minix.iso ...
- linux file命令小记
在linux中,所有东西都是文件:而且他并没有后缀名这一概念.Linux的扩展名没有太大的意义, file.tar.gz file.tgz file.tar.bz2 file.rar file.gz ...
- linux File Handling commands 'ls'.
ref:Linux / Unix Command: ls NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DES ...
随机推荐
- redis+cookies实现session机制(解决 手机浏览器不自动回传cookies导致session不可用问题)
昨天在手机端测试自己的项目遇到如下情况. 1.在手机上(苹果qq浏览器),登陆时存在session中的图片验证码结果,一直获取不到,考虑是cookies的问题.但是其他网站有貌似可以正常使用cooki ...
- 针对Asp.net MVC SEO的几点建议
1. 引言 SEO 即搜索引擎优化,很多web开发人员本应该熟悉,至少需要了解的一个知识点.像百度.必应等搜索引擎其实一直都在进化.但是有些优化的技巧可能在短时间内不变. 今天就给大家介绍几个专门针对 ...
- C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。
C#中对象,字符串,dataTable.DataReader.DataSet,对象集合转换成Json字符串方法. public class ConvertJson { #region 私有方法 /// ...
- C#文件或文件夹压缩和解压方法(通过ICSharpCode.SharpZipLib.dll)
我在网上收集一下文件的压缩和解压的方法,是通过ICSharpCode.SharpZipLib.dll 来实现的 一.介绍的目录 第一步:下载压缩和解压的 ICSharpCode.SharpZipLib ...
- python计算器
思路:优先级处理思路一:正则表达式+递归(计算时间慢)思路二:堆栈的方式队列:先进先出电梯-->队列上电梯(入队123):第三个人3,第二个人2,第一个人1>>> li = [ ...
- Hibernate总结(一)
Hibernate为了提高性能,提供了缓存与快照机制. 它的缓存分为一级缓存与二级缓存. Hibernate一级缓存:当一个事务中执行一次Sql语句时,就将返回的结果存储在Session中的Map集合 ...
- RequireJS入门之一——实现第一个例子
为什么学习RequireJS? 像我这种菜鸟,会提到海量文章里提到的AMD.JS模块化编程.异步... ... 等等 RequireJS是一个Javascript 文件和模块框架,它可以帮我们去管理j ...
- Maven学习随笔一——Maven安装报错处理(mvn -v, 提示不是内部命令的问题)
今天心血来潮学习maven,可是光安装就花了个把小时,好坑有木有! 安装过程可百度,各种经贴,不详. 控制台输入 mvn -v ,如果报错,很可能是你的java/maven的环境变量配置出了点问题: ...
- Netty(四)分隔符与定长解码器的使用
TCP以流的形式进行数据传输,上层的应用协议为了对消息进行划分,往往采用如下的4种方式. (1)消息长度固定,累计读到长度总和为定长len的报文后,就认为读取到了一个完整的消息:然后重新开始读取下一个 ...
- crm on premise IFD 部署下提供oauth 2.0 集成自定义应用
很多情况下我们的CRM系统会和弟三方应用集成,一般情况我们会开发一个中间站点来提供web api 给弟三方应用. 参考:http://alexanderdevelopment.net/post/201 ...