linux平台ext4magic数据恢复软件,Linux平台ext4magic数据恢复软件

针对于ext4文件系统数据恢复软件,看了网上好多都在介绍extundelete这个工具,下载最新版本实验时(在Centos5.8、Centos6.7上实验效果不是很好)。最终发现ext4magic对于ext4数据恢复支持还是非常强大的。也可以做到基于时间点、inode、指定文件恢复等等。恢复时需要卸载分区,以只读方式挂载恢复。具体软件下载地址为:

http://sourceforge.net/projects/ext4magic/

1、安装

可以参考官方INSTALL文件进行安装,如有依赖需处理好包依赖方可进行安装。系统必须安装make、file

、gcc工具。以下libmagic、libext2fs、libz、libbz2库必须安装,

# tar -xzf ext4magic-0.3.2.tar.gz

# cd ext4magic-0.3.2

# ./configure

# make

# make install

2、测试

(1)、基于时间恢复(以1970-01-01 00:00:00 UTC的秒数开始计算)

[root@jason1 ~]# mount /dev/sdb1 /media/

[root@jason1 ~]# cp -rp /boot/* /media/

[root@jason1 ~]# cd /media/

[root@jason1 media]# ll

total 34884

-rw-r--r--. 1 root root   107134 Jul 24 00:13 config-2.6.32-573.el6.x86_64

drwxr-xr-x. 3 root root     4096 Dec 10 19:20 efi

-rw-r--r--. 1 root root   166756 Jul 20  2011 elf-memtest86+-4.10

drwxr-xr-x. 2 root root     4096 Dec 10 19:33 grub

-rw-------. 1 root root 27925110 Dec 10 19:31 initramfs-2.6.32-573.el6.x86_64.img

drwx------. 2 root root    16384 Dec 10 18:17 lost+found

-rw-r--r--. 1 root root   165080 Jul 20  2011 memtest86+-4.10

-rw-r--r--. 1 root root   205998 Jul 24 00:14 symvers-2.6.32-573.el6.x86_64.gz

-rw-r--r--. 1 root root  2585052 Jul 24 00:13 System.map-2.6.32-573.el6.x86_64

-rw-r--r--. 1 root root   289193 Oct 15  2014 tboot.gz

-rw-r--r--. 1 root root    12277 Oct 15  2014 tboot-syms

-rwxr-xr-x. 1 root root  4220560 Jul 24 00:13 vmlinuz-2.6.32-573.el6.x86_64

[root@jason1 media]# date

Mon Dec 14 19:36:06 CST 2015

[root@jason1 media]# rm -rf *

[root@jason1 media]# cd

[root@jason1 ~]# umount /dev/sdb1

[root@jason1 ~]# mount -o ro /dev/sdb1 /media

[root@jason1 ~]# ext4magic /dev/sdb1 -d /home -a 1450086000 -m  3##改时间通过date命令获取当前时间秒数减去3600秒得来。

Warning: Activate magic-scan or disaster-recovery function, may be some command line options ignored

"/home"  accept for recoverdir

Filesystem in use: /dev/sdb1

Using  internal Journal at Inode 8

Activ Time after  : Mon Dec 14 17:40:00 2015

Activ Time before : Mon Dec 14 19:44:26 2015

Inode 2 is allocated

--------        /home/config-2.6.32-573.el6.x86_64

--------        /home/efi/EFI/redhat/grub.efi

--------        /home/elf-memtest86+-4.10

--------        /home/grub/menu.lst

--------        /home/grub/reiserfs_stage1_5

--------        /home/grub/e2fs_stage1_5

--------        /home/grub/xfs_stage1_5

--------        /home/grub/fat_stage1_5

--------        /home/grub/stage1

--------        /home/grub/iso9660_stage1_5

--------        /home/grub/splash.xpm.gz

--------        /home/grub/vstafs_stage1_5

--------        /home/grub/ufs2_stage1_5

--------        /home/grub/device.map

--------        /home/grub/stage2

--------        /home/grub/ffs_stage1_5

--------        /home/grub/minix_stage1_5

--------        /home/grub/jfs_stage1_5

--------        /home/grub/grub.conf

--------        /home/initramfs-2.6.32-573.el6.x86_64.img

--------        /home/memtest86+-4.10

--------        /home/symvers-2.6.32-573.el6.x86_64.gz

--------        /home/System.map-2.6.32-573.el6.x86_64

--------        /home/tboot.gz

--------        /home/tboot-syms

--------        /home/vmlinuz-2.6.32-573.el6.x86_64

MAGIC-1 : start lost directory search

MAGIC-2 : start lost file search

MAGIC-2 : start lost in journal search

MAGIC-3 : start ext4-magic-scan search

--------        /home/MAGIC-3/text/plain/0000028685.txt

--------        /home/MAGIC-3/text/plain/0000045944.txt

ext4magic : EXIT_SUCCESS

验证是否恢复成功

[root@jason1 ~]# cd /home/

[root@jason1 home]# ll

total 34872

-rw-r--r--. 1 root root   107134 Jul 24 00:13 config-2.6.32-573.el6.x86_64

drwx------. 3 root root     4096 Dec 14 19:44 efi

-rw-r--r--. 1 root root   166756 Jul 20  2011 elf-memtest86+-4.10

drwx------. 2 root root     4096 Dec 14 19:44 grub

-rw-------. 1 root root 27925110 Dec 10 19:31 initramfs-2.6.32-573.el6.x86_64.img

drwx------. 3 root root     4096 Dec 14 19:44 MAGIC-3

-rw-r--r--. 1 root root   165080 Jul 20  2011 memtest86+-4.10

-rw-r--r--. 1 root root   205998 Jul 24 00:14 symvers-2.6.32-573.el6.x86_64.gz

-rw-r--r--. 1 root root  2585052 Jul 24 00:13 System.map-2.6.32-573.el6.x86_64

-rw-r--r--. 1 root root   289193 Oct 15  2014 tboot.gz

-rw-r--r--. 1 root root    12277 Oct 15  2014 tboot-syms

-rwxr-xr-x. 1 root root  4220560 Jul 24 00:13 vmlinuz-2.6.32-573.el6.x86_64

[root@jason1 home]#

(2)、整个文件系统恢复

[root@jason1 ~]# ext4magic /dev/sdb1 -d /home -m

Warning: Activate magic-scan or disaster-recovery function, may be some command line options ignored

"/home"  accept for recoverdir

Filesystem in use: /dev/sdb1

Using  internal Journal at Inode 8

Activ Time after  : Mon Dec 14 19:36:37 2015

Activ Time before : Mon Dec 14 19:56:58 2015

Inode 2 is allocated

--------        /home/config-2.6.32-573.el6.x86_64

--------        /home/efi/EFI/redhat/grub.efi

--------        /home/elf-memtest86+-4.10

--------        /home/grub/menu.lst

--------        /home/grub/reiserfs_stage1_5

--------        /home/grub/e2fs_stage1_5

--------        /home/grub/xfs_stage1_5

--------        /home/grub/fat_stage1_5

--------        /home/grub/stage1

--------        /home/grub/iso9660_stage1_5

--------        /home/grub/splash.xpm.gz

--------        /home/grub/vstafs_stage1_5

--------        /home/grub/ufs2_stage1_5

--------        /home/grub/device.map

--------        /home/grub/stage2

--------        /home/grub/ffs_stage1_5

--------        /home/grub/minix_stage1_5

--------        /home/grub/jfs_stage1_5

--------        /home/grub/grub.conf

--------        /home/initramfs-2.6.32-573.el6.x86_64.img

--------        /home/memtest86+-4.10

--------        /home/symvers-2.6.32-573.el6.x86_64.gz

--------        /home/System.map-2.6.32-573.el6.x86_64

--------        /home/tboot.gz

--------        /home/tboot-syms

--------        /home/vmlinuz-2.6.32-573.el6.x86_64

MAGIC-1 : start lost directory search

MAGIC-2 : start lost file search

MAGIC-2 : start lost in journal search

MAGIC-3 : start ext4-magic-scan search

--------        /home/MAGIC-3/text/plain/0000028685.txt

ext4magic : EXIT_SUCCESS

[root@jason1 ~]#

(3)、指定文件恢复

[root@jason1 ~]# ext4magic /dev/sdb1 -r -f grub/grub.conf -d /home

"/home"  accept for recoverdir

Filesystem in use: /dev/sdb1

Using  internal Journal at Inode 8

Inode found "grub/grub.conf"   655377

--------        /home/grub/grub.conf

ext4magic : EXIT_SUCCESS

[root@jason1 ~]# cd /home/

[root@jason1 home]# ll

total 4

drwx------. 2 root root 4096 Dec 14 20:08 grub

[root@jason1 home]# ll grub/grub.conf

-rw-------. 1 root root 843 Dec 10 19:33 grub/grub.conf

[root@jason1 home]#

指定文件恢复时,需要注意指定恢复文件的路径书写问题。以下给出官方的示例:

An example: the mount point for this filesystem is " /home " an the filename for Linux is " /home/usr1/Document " you can use now

# ext4magic /dev/sda3 -f usr1/Document

(去掉挂在点目录指定文件目录)。

备注:更详细的恢复参数,参考系统man ext4magic帮助文档。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux内核的ext4文件系统是一种高性能、可靠性高的文件系统,其代码在内核源码树的/fs/ext4目录下。 代码文件主要包括以下几个部分: 1. ext4.h:定义了ext4文件系统的数据结构和相关常量。 2. super.c:实现了ext4文件系统超级块的读取和写入。 3. inode.c:实现了ext4文件系统inode节点的读取和写入。 4. namei.c:实现了ext4文件系统文件名的查找和创建。 5. dir.c:实现了ext4文件系统目录的读写操作。 6. file.c:实现了ext4文件系统文件的读写操作。 7. extents.c:实现了ext4文件系统的extents分配和管理。 8. inode_table.c:实现了ext4文件系统inode表的管理。 9. resize.c:实现了ext4文件系统的动态扩容和缩容。 10. journal.c:实现了ext4文件系统的日志功能。 下面以super.c文件为例,对其代码进行逐行注释介绍。 ```c /* * linux/fs/ext4/super.c * * Copyright (C) 1995-2006 Theodore Ts'o. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ ``` 代码开头是版权和许可证声明。 ```c #include <linux/module.h> #include <linux/fs.h> #include <linux/seq_file.h> #include <linux/parser.h> #include <linux/random.h> #include <linux/string.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/uaccess.h> #include <linux/crc32c.h> #include <linux/buffer_head.h> #include <linux/init.h> #include <linux/magic.h> #include <linux/blkdev.h> #include <linux/backing-dev.h> #include <linux/kdev_t.h> #include <linux/sched.h> #include <linux/quotaops.h> #include <linux/pagemap.h> #include <linux/compat.h> #include <linux/falloc.h> #include <linux/atomic.h> #include <linux/fiemap.h> #include <linux/fscrypt.h> #include "ext4.h" #include "xattr.h" #include "acl.h" #include "ext4_jbd2.h" #include "mballoc.h" #include "extents.h" #include "ext4_extents.h" #include "ext4_inode.h" #include "ext4_raw.h" #include "htree.h" ``` 接下来是一些头文件的引用,包括了一些常用的内核函数和结构体定义。 ```c static void ext4_put_super(struct super_block *sb); static int ext4_sync_fs(struct super_block *sb, int wait); static int ext4_freeze(struct super_block *sb); static int ext4_unfreeze(struct super_block *sb); static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); static int ext4_remount(struct super_block *sb, int *flags, char *data); static int ext4_show_options(struct seq_file *seq, struct dentry *root); static int ext4_commit_super(struct super_block *sb, int sync); static int ext4_write_super(struct super_block *sb); ``` 这部分是函数的声明。 ```c static int ext4_fill_super(struct super_block *sb, void *data, int silent); ``` 这是ext4文件系统的核心函数,用于读取超级块和初始化文件系统。 ```c static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data); ``` 这是文件系统挂载函数,用于将ext4文件系统挂载到指定设备上。 ```c static struct file_system_type ext4_fs_type = { .owner = THIS_MODULE, .name = "ext4", .mount = ext4_mount, .kill_sb = kill_block_super, .fs_flags = FS_REQUIRES_DEV, }; MODULE_ALIAS_FS("ext4"); MODULE_ALIAS("fs-ext4"); ``` 这部分定义了一个file_system_type结构体,用于注册ext4文件系统类型。其中mount指向ext4_mount函数,kill_sb指向kill_block_super函数。 ```c static int __init init_ext4_fs(void) { int err = init_ext4_fs_once(); if (err) return err; err = register_filesystem(&ext4_fs_type); if (err) goto out1; err = ext4_register_li_request(); if (err) goto out2; return 0; out2: unregister_filesystem(&ext4_fs_type); out1: destroy_ext4_fs(); return err; } module_init(init_ext4_fs); static void __exit exit_ext4_fs(void) { ext4_unregister_li_request(); unregister_filesystem(&ext4_fs_type); destroy_ext4_fs(); } module_exit(exit_ext4_fs); ``` 这部分是初始化和销毁ext4文件系统的函数。 以上就是ext4文件系统的主要代码,对其进行注释可以更好地理解它的实现原理和具体实现方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值