linux恢复 rm -rf * 误删数据


linux误删除文件后应尽快将磁盘挂载为只读,否则后续操作可能会覆盖这些数据,越早发现,并挂载为只读,恢复的成功机率就越大。因此,本文只是提供一种方式,不能保证一定能恢复误删的数据。

一、磁盘分区挂载为只读

1、查看被删除文件位于哪个分区

[root@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sdb1 on /opt type ext4 (rw)

2、将对应目录重新挂载为只读

[root@localhost  ~]#  mount -r -n -o remount /opt
mount: /home is busy
如果显示 xxx is busy
[root@localhost  ~ ]# fuser -v -m /opt

找出相关进程,kill掉

[root@localhost  ~ ] #  mount -r -n -o remount /opt

成功后,此时在/opt目录 touch文件时,会报错:

[root@localhost  opt ] # touch txt
touch: cannot touch `txt’: Read-only file system

二、安装数据恢复工具 extundelete

1、下载extundelete-0.2.4

下载源:
http://superb-dca2.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2

2、安装

需要安装编译环境及extundelete依赖的包
yum -y install gcc+ gcc-c++
yum install e2fsprogs e2fsprogs-libs e2fsprogs-devel -y

[root@localhost extundelete-0.2.4]# ./configure 
Configuring extundelete 0.2.4
Writing generated files to disk
[root@localhost extundelete-0.2.4]# make
make -s all-recursive
Making all in src
[root@localhost extundelete-0.2.4]# make install
Making install in src
  /usr/bin/install -c extundelete '/usr/local/bin'
[root@localhost extundelete-0.2.4]# cd src/     --验证
[root@localhost src]# ./extundelete -v
extundelete version 0.2