怎样使用 extundelete 见 https://blog.csdn.net/jiuweiljp/article/details/118024580
extundelete 目前的版本是0.2.4工具不大,本人使用该工具恢复了一些数据。
想着一次编译可以在绝大多数平台上使用,静态编译它,折腾了一圈排错过程如下:
extundelete 需要 e2fsprogs 库支持 目前最新的版本为1.46.2,编译很容易。并安装。
./configure #检测系统并生成 Makefile
make V=1 -j4 #编译
sudo make install-strip #安装工具
sudo make install-libs #安装库文件到系统文件夹
注意如果你的系统已经按安装了e2fsprogs则先卸载它
sudo apt-get purge e2fsprogs
sudo apt-get purge comerr-dev
sudo apt-get purge e2fslibs-dev
回到extundelete 目录配置静态编译参数
./configure CFLAGS="--static " CXXFLAGS="--static " CPPFLAGS="--static " LDFLAGS="--static "
报错
Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library
打开config.log 其中有一段信息如下
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libext2fs.a(alloc_stats.o): In function `ext2fs_inode_alloc_stats2':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/alloc_stats.c:25: undefined reference to `com_err'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libext2fs.a(alloc_stats.o): In function `ext2fs_block_alloc_stats2':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/alloc_stats.c:67: undefined reference to `com_err'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libext2fs.a(alloc_stats.o): In function `ext2fs_block_alloc_stats_range':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/alloc_stats.c:114: undefined reference to `com_err'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libext2fs.a(bitops.o): In function `ext2fs_warn_bitmap':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/bitops.c:75: undefined reference to `com_err'
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/bitops.c:77: undefined reference to `com_err'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libext2fs.a(gen_bitmap.o):/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/ext2fs/gen_bitmap.c:180: more undefined references to `com_err' follow
collect2: error: ld returned 1 exit status
其中 /usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/ 其实是/usr/lib/ 目录,文件libext2fs.a 是刚刚编译并安装的e2fsprogs库文件,从信息中 undefined reference to `com_err' 可以知道是缺东西, 缺com_err。
一顿折腾,下了好几个版本的e2fsprogs都没有解决这个问题。后来发现e2fsprogs生成了好几个库文件,一共有:
libblkid.a libe2p.a libss.a libcom_err.a libext2fs.a libuuid.a
其中libcom_err.a 有点像报错信息,查看 extundelete 的 configure文件找到如下段落
# Checks for libraries.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ext2fs_bmap in -lext2fs" >&5
$as_echo_n "checking for ext2fs_bmap in -lext2fs... " >&6; }
if ${ac_cv_lib_ext2fs_ext2fs_bmap+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lext2fs $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
注意:LIBS="-lext2fs $LIBS" 这句只链接 libext2fs.a 这个库文件,想着直接修改configure文件,添加 -lcom_err 链接到 libcom_err.a 这个库,发现后缀还有一个 $LIBS,呵呵,这是一个变量。想到 configure 帮助信息 中有一个LIBS选项。
./configure --help
...
...
Some influential environment variables:
CXX C++ compiler command
CXXFLAGS C++ compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CC C compiler command
CFLAGS C compiler flags
CPP C preprocessor
添加LIBS参数 重新调用 configure 看看。
./configure CFLAGS="--static " CXXFLAGS="--static " CPPFLAGS="--static " LDFLAGS="--static " LIBS="-lcom_err "
继续报错 error: Can't find ext2fs library,再次查看config.log
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libcom_err.a(error_message.o): In function `et_list_unlock':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/et/error_message.c:96: undefined reference to `sem_post'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libcom_err.a(error_message.o): In function `et_list_lock':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/et/error_message.c:86: undefined reference to `sem_wait'
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/et/error_message.c:86: undefined reference to `sem_wait'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libcom_err.a(error_message.o): In function `setup_et_lock':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/et/error_message.c:69: undefined reference to `sem_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libcom_err.a(error_message.o): In function `fini_et_lock':
/media/admin1/openwrt/e2fsprogs/e2fsprogs-1.43.1/lib/et/error_message.c:75: undefined reference to `sem_destroy'
collect2: error: ld returned 1 exit status
出错信息已经有了变化,说明LIBS="-lcom_err "有效,但出现新的错误。
百度了一下 在网文 https://www.cnblogs.com/minglee/p/10096457.html 提示,缺少 -lpthread ,继续添加链接库
./configure CFLAGS="--static " CXXFLAGS="--static " CPPFLAGS="--static " LDFLAGS="--static " LIBS="-lcom_err -lpthread"
这下就不报错了。
Configuring extundelete 0.2.4
Writing generated files to disk
后面就简单了 make 静态编译成功。
注:如果不是静态编译extundelete,则没有这些错误。
并且extundelete在gcc7,gcc9下面无法正常编译,gcc5 倒是可以成功。
结论:
编译的文件的时候,还是要耐心,细致。
补充:
在 https://github.com/pld-linux/extundelete 看见有人给打了个补丁,我也一并编译了,不知道有什么作用。
--- extundelete-0.2.4/src/extundelete.cc.orig 2014-12-24 14:00:40.401233636 +0100
+++ extundelete-0.2.4/src/extundelete.cc 2014-12-24 14:41:00.240755859 +0100
@@ -89,6 +89,7 @@ Important future enhancements:
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
+#include <sys/time.h>
/* GNU headers */
#ifndef HAVE_GETOPT_H
@@ -1746,8 +1746,14 @@ errcode_t restore_inode(ext2_filsys fs,
}
tsize = fsize - rsize;
if ((retval = truncate( (outputdir + fname2).c_str(), tsize)) == 0) {
+ struct timeval times[2];
+ chmod((outputdir + fname2).c_str(),inode->i_mode);
+ lchown((outputdir + fname2).c_str(),inode->i_uid,inode->i_gid);
+ times[0].tv_sec=inode->i_atime; times[0].tv_usec=0;
+ times[1].tv_sec=inode->i_mtime; times[1].tv_usec=0;
+ utimes((outputdir + fname2).c_str(),times);
Log::info << "Restored inode " << ino << " to file "
- << (outputdir + fname2) << std::endl;
+ << (outputdir + fname2) << " deleted " << asctime(localtime((time_t*)&inode->i_dtime)) << std::endl;
retval = 0;
} else {
Log::warn << "Failed to restore inode " << ino << " to file "
--- extundelete-0.2.4/src/extundelete.cc.orig 2014-12-24 14:00:40.401233636 +0100
+++ extundelete-0.2.4/src/extundelete.cc 2014-12-25 01:29:09.076514586 +0100
@@ -1777,6 +1777,23 @@ errcode_t restore_inode(ext2_filsys fs,
retval = EU_RESTORE_FAIL;
}
}
+ else if (LINUX_S_ISDIR(inode->i_mode)) {
+ if(mkdir((outputdir2 + fname2).c_str(), 0700)) {
+ struct timeval times[2];
+ chmod((outputdir + fname2).c_str(),inode->i_mode);
+ lchown((outputdir + fname2).c_str(),inode->i_uid,inode->i_gid);
+ times[0].tv_sec=inode->i_atime; times[0].tv_usec=0;
+ times[1].tv_sec=inode->i_mtime; times[1].tv_usec=0;
+ utimes((outputdir + fname2).c_str(),times);
+ std::cout << "Restored inode " << ino << " as directory ";
+ std::cout << (outputdir + fname2) << " deleted " << asctime(localtime((time_t*)&inode->i_dtime));
+ retval = 0;
+ } else {
+ std::cout << "Failed to restore inode " << ino << " as directory ";
+ std::cout << (outputdir + fname2) << " deleted " << asctime(localtime((time_t*)&inode->i_dtime));
+ retval = EU_RESTORE_FAIL;
+ }
+ }
else {
Log::info << "extundelete identified inode " << ino << " as "
<< (outputdir + fname2) << ":"
下载地址:
偷懒的人可以直接下载我编译好的文件
https://pan.baidu.com/s/1rYtUNC0hSRH1ossCyJ-VWA 提取码: 7fe3
里面有x86_64 和 i386 静态编译的版本,还有原文件,自取。