Disk Recovery

最后更新:2021-06-01  版本:1.0.10.0601

 

简介

disk recovery - 转储受损的磁盘和文件
  • FreeBSD recoverdisk 工具的跨平台改进版。
  • 支持手动设置块尺寸和扇区尺寸。对未受损的区域以较大的块尺寸进行高效读取,对包含坏道的块使用 Med 区块及逐扇区恢复。
  • 可指定对于每个坏扇,最多尝试重复读取几次。
  • 可指定遇到无法恢复的坏扇时,使用的填充值。
  • 直接访问源物理设备,禁用了操作系统缓存机制和预读策略:确保更可靠高效的恢复操作,防止由于缓存和预读机制而反复读取一个坏道导致性能和可靠性下降,甚至进一步损伤设备。
  • 源既可以是一个磁盘设备,也可以是普通文件。方便仅需要恢复个别有坏道文件的情形。
  • 目的既可以是一个磁盘设备,也可以是普通文件。将一个磁盘设备转储到镜像文件不需要专门准备一个扇区尺寸一致的专用磁盘,而且可以方便地使用 WinImage、R-Studio 等工具对镜像文件进行扫描和恢复。
  • 可指定冷却间隔,例如:指定 "30/5" 表示每工作 30 分钟后,自动停止 5 分钟。冷却机制防止本已损伤的设备因为过热和疲劳而进一步恶化。
  • 在磁盘设备健康水平进一步恶化前,尽可能多地抢救数据:rdd 先以大块(默认 1MB)为单位转储数据,期间跳过无法读取(受损)的部分;然后集中尝试以中块(Med,默认 32KB)为单位读取所有受损的大块,期间跳过无法读取(受损)的中块;最后再逐扇区地尝试恢复所有受损的中块,对超过指定重试次数仍无法正常读取的扇区按预定义的填充值(默认 0x00)进行转储。
  • 可指定转储的范围,跳过坏块密集或者无需进行恢复的部分。
  • 可指定日志文件和日志级别。
  • 极高的 IO 并发效率:源读取、目标写入以及日志记录均在各自的工作线程中完成。
  • 可指定读线程和写线程间的数据缓存队列尺寸,也可根据当前系统的可用物理内存数量进行自动判断。
  • 可指定进程的运行优先级。例如:较低的进程优先级可以大大降低程序对前台用户体验的影响。
  • 使用清晰的 '-from' 和 '-to' 开关项来指定源和目的以及执行前确认机制,避免由于参数错误带来的灾难性后果。
  • 支持 Win32 和纯 DOS 环境(纯DOS环境中需要 HX DOS Extender 支持且功能受限)。
  • 支持 POSIX 环境,提供 linux x86/x64、FreeBSD、Mac OS X、Solaris 等版本下载。

 

更新历史

2021-06-01, Ver 1.0.10.0601

* NEW: 新增 linux arm64 版。
* UPD: 一些次要优化和修复。

2020-10-03, Ver 1.0.8.1003

* NEW: 新增 aligned 选项。

2020-09-19, Ver 1.0.7.0919

* UPD: 优化源设备结尾判定。
* UPD: 增强 Seek 操作失败保护。
* UPD: 仅更新 linux x64 以及 MSW x86/x64 版本。

2020-09-14, Ver 1.0.6.0914

* UPD: 次要改进:改进磁盘扇区尺寸自动检测算法。
* UPD: 新增 Windows x64 版。
* UPD: 基于最新版本底层支撑平台编译 linux x64 和 MSW x86/x64 版本。

2013-04-26, Ver 1.0.5.0426

* UPD: 改进 Windows 版的物理设备结尾判定算法。
* UPD: 改进扇区读错误信息的显示方式。

2013-04-23, Ver 1.0.4.0423

* NEW: 新增耗时显示。

2013-04-16, Ver 1.0.3.0416

* NEW: 新增恢复范围(-secrange 和 -perrange)选项。

2013-04-08, Ver 1.0.2.0408

* FIX: 修正了扇区(第三轮迭代)读取失败后,错误提示信息措辞不正确的问题。
* UPD: 更新自动生成的日志记录格式为 'rdd_YYYYMMDD-hhmm.log'。
* NEW: 将启动命令行记入日志文件。
* NEW: 新增扇区尺寸自动判断功能。
* NEW: 在每秒刷新的状态行中加入剩余尺寸提示。

2013-04-04, Ver 1.0.1.0403

NEW: 发布。

 

数据恢复算法说明

首先使用较大的 IO 块尺寸(Big 块,由 '-block' 参数指定)高效地恢复源设备中尚未受损的部分,并将无法读取的 IO 块临时存入 Big 坏块队列中。

当源设备中的所有内容均读取完毕后,将使用一个介于 Big 块和扇区尺寸之间的 IO 块尺寸(Med 块)来逐个读取 Big 坏块队列中记录的那些坏块。此轮迭代主要是为了以 Med 块为步进值跳过那些连续存在的坏扇(坏道)部分,以确保在硬件未被彻底损耗前尽可能多地抢救数据。类似于第一轮的 Big 块遍历,所有无法读取的 Med 块都将被存入一个 Med 坏块队列中。

当源设备上的所有的 Big 坏块上均已执行了 Med 遍历后,将以扇区为单位来逐个读取 Med 坏块队列中记录的那些坏块。此时,每个扇区将最多被尝试读取 "重试次数"(由 '-retry' 选项指定)+1 次。若最终无法读取该扇区中的内容,此扇区将以 '-fill' 选项指定的值来进行填充。

以上算法确保在设备状态相对尚好的初期,尽可能地跳过坏扇/坏道密集区以更多地恢复数据。然后,在大部分完好数据均已被恢复的前提下,再进行更细致的恢复尝试。

此算法在配合设备直接访问和冷却间隔等机制后,可产生更优恢复效能。

 

参考案例

请参考:https://bbs.et8.net/bbs/showthread.php?t=1038956

本工具是其中 recoverdisk 的跨平台改良版,可以在 msfBSD、Linux rescue 以及 Windows PE 等各种常用恢复环境中运行。

此外,经测试,rdd 可以很好地工作在 AHCI 模式下。配合读写线程分离的设计,在未遇到错误时,基本可以当前系统的磁盘 IO 性能峰值进行数据转储;在遇到坏块时,其直接访问物理设备和禁用预读等措施也可带来相对较优的表现。

追加说明:

此外,经测试,rdd 可以很好地工作在 AHCI 模式下。配合读写线程分离的设计,在未遇到错误时,基本可以当前系统的磁盘 IO 性能峰值进行数据转储;在遇到坏块时,其直接访问物理设备和禁用预读等措施也可带来相对较优的表现。

UPDATE: 更多的测试表明,在 FreeBSD 下恢复坏块较多的磁盘时,AHCI 还是比 IDC 性能差一些的。其它平台还没测完。
UPDATE: linux 下 ahci 模式性能不比 ide 模式差,而且 ahci 模式下貌似还能恢复一些 ide 模式读不出来的坏扇(就是那种有点问题,但努力努力还能读出来的)。
UPDATE: Windows 平台,根据鲨鲨兄的测试结果来说表现不佳。或者在坏块较多时,系统会一直卡在某个坏块无法返回;或者恢复进度很慢,两三天也无法有什么实质性的进展。

 

注意事项

  1. 目标文件或目标存储设备中的内容将被覆盖。
  2. 转储包含坏扇的磁盘设备是一个耗时工作,根据损伤程度以及转储区尺寸的不同,本操作可能会持续数小时至数天时间。
  3. 请确认扇区尺寸已被正确设置,因为直接访问底层硬件要求每次 IO 都要以扇区为单位进行,同时提交到 IO 操作的内存基址也必须是扇区尺寸的整数倍,方便将其加入非分页池,直接通过 DMA 提交给磁盘控制器。所以不正确的扇区尺寸将可能导致读取失败。

 

帮助屏幕

#rdd

==============================================================================
  Disk Recovery Tool Ver 1.0.10.0601 by BaiYang / 2013 - 2021
                           http://baiy.cn
==============================================================================
  Try to dump physically damaged disk or files

[USAGE]: rdd {-from|-fromdisk} {-to|-todisk} [Options]

==============================================================================
Options:
  -from:    - specify the source device or file path.
  -to:      - specify the destination device or file path.
  -sector:  - specify the sector or stripe size for the storage device.
                DEFAULT: auto detect (NOTE: may be faked by driver).
  -block:   - specify the maximum size per io operation should be taked.
                DEFAULT: 1MB.
  -maxbuf:  - specify maximum size of the buffer queue between the reading.
              thread and the writing thread.
                DEFAULT: smaller one of 256 blocks and one-thirdd of the
                current available (free) physical memory.
  -retry:   - maximum number of retries for a sector read error, DEFAULT: 0.
  -fill:    - specify the fill value for bad sectors, DEFAULT: 0x00.
  -secrange:- specify the sector range to dump. format is: [][-].
              the sector number counted from 0.
                DEFAULT: dump whole source.
  -perrange:- specify the percentage range to dump. format: [][-].
                DEFAULT: '0.00-100.00' (top to tail).
  -aligned  - data will be written to the target in alignment with the source
              offset position.
              DEFAULT: overwrite the target file from the beginning.
  -logfile: - write logging to specified logfile.
                DEFAULT: use './rdd_YYYYMMDD-hhmm.log'
  -loglevel:- specify the lowest logging level, could be:
                DebugOnly (Most Detail)
                Info (DEFAULT)
                Warning
                Error
                FatalError
                Disabled (Close Logging Output)
  -priority:- specify the process running priority, can be:
                Idle
                BelowNormal
                Normal (DEFAULT)
                AboveNormal
                High
                Realtime
  -cooldown:- specify the duty-cycle for cooling down the device. the format
              is 'MM/mm'. e.g.: '30/10' means 10-minute cooling down break
              every 30 minutes.
                DEFAULT: no cooling down break.
  -h or -?  - this screen.
  --help    - this screen.

==============================================================================
Windows Only Options:
  -fromdisk: - specify the source disk number. '-fromdisk:X' is a shortened
               form of '-from:"\\.\PhysicalDriveX"', wherein X belongs [0..9].
  -todisk:   - specify the source disk number. '-todisk:X' is a shortened form
               of '-to:"\\.\PhysicalDriveX"', wherein X belongs [0..9].

==============================================================================
Recognized size representaion for '-sector', '-block' and '-maxbuf' options:
  Decimal digital with suffix 'm' or 'mb' (case-insensitive):
    recognized as megabytes.
  Decimal digital with suffix 'k' or 'kb' (case-insensitive):
    recognized as kilobytes.
  Decimal digital with no or others suffix: recognized as bytes.

==============================================================================
Recognized value representaion for '-fill' option:
  Hexadecimal, Prefix: 0x, x (case-insensitive)
  Octal,       Prefix: 0
  Binary,      Prefix: 0b, b (case-insensitive)
  Decimal,     Prefix: NONE (1-9)

==============================================================================
Identify the device name:
  On Windows platform, The storage device number could be identified by using
  the Disk Manager (right click 'My Computer' and select 'Management').

  On linux and other unix like platforms, the device can be found in the /dev
  folder.

==============================================================================
Examples:
  rdd -from:/dev/sda -to:~/disk.img -logfile:~/rdd-sda.log
  rdd -fromdisk:1 -todisk:2 -sector:4k
  rdd -fromdisk:1 -to:datapart2.img -sector:4k -perrange:51.45-87.5
  rdd -from:"D:\My Data\file.dat" -to:E:\rec.dat -retry:3 -fill:B10101010
  rdd -fromdisk:1 -to:D:\disk.img -sector:4k -priority:idle
  rdd -from:/dev/sda -to:/data/disk.img -cooldown:20/5
  rdd -from:/dev/sda -to:/data/disk.img -perrange:34.25
  rdd -from:/dev/sda -to:/data/disk.img -secrange:-11785600

 

简单中文帮助

#rdd

==============================================================================
                磁盘恢复工具 Ver 1.0.10.0601, 白杨 / 2013 - 2021
                           http://baiy.cn
==============================================================================
  尝试转储带有物理损伤的磁盘或文件

[用法]: rdd {-from|-fromdisk} {-to|-todisk} [Options]

==============================================================================
选项:
  -from:    - 指定源设备或源文件路径。
  -to:      - 指定目标设备或目标文件路径。
  -sector:  - 指定源设备的扇区或区块(RAID)尺寸。
                默认: 自动判断(注意:驱动程序可能报告虚假尺寸)。
  -block:   - 指定每次 IO 操作的最大尺寸。
                默认: 1MB。
  -maxbuf:  - 指定读写线程间缓存队列的最大尺寸。
                默认: 256 个 IO 块或当前系统中可用物理内存的三分之一,取两者间
                的较小值。
  -retry:   - 针对单个坏扇的最大重试读取次数, 默认: 0(不重试读取)。
  -fill:    - 指定坏扇的填充值, 默认: 0x00。
  -secrange:- 指定要转储的扇区范围。格式为: [<起始扇区>][-<结束扇区>]。扇区从 0
              开始计数。
                默认: 转储整个源。
  -perrange:- 以百分比来指定要转储的范围。格式为: [<起始位置>][-<结束位置>].
                默认: '0.00-100.00' (整个源)。
  -aligned  - 数据将按照源中的偏移地址被对齐地写入目标文件或设备。
                默认: 从目标文件的头部开始写入。
  -logfile: - 指定要写入的日志文件。
                默认: 将日志写入到 './rdd-YYYYMMDD-hhmm.log'。
  -loglevel:- 指定日志级别, 可以是:
                DebugOnly (最详细)
                Info (默认)
                Warning
                Error
                FatalError
                Disabled (禁用日志机制)
  -priority:- 指定进程的运行优先级, 可以是:
                Idle
                BelowNormal
                Normal (默认)
                AboveNormal
                High
                Realtime
  -cooldown:- 指定存储设备的冷却周期, 格式为: 'MM/mm'。例如: '30/10' 每工作 30 
              分钟后,冷却 10 分钟。
                默认: 持续工作,无冷却机制。
  -h or -?  - 此说明。
  --help    - 此说明。

==============================================================================
仅针对 Windows 的选项:
  -fromdisk: - 指定源磁盘号。'-fromdisk:X' 是 '-from:"\\.\PhysicalDriveX"' 的简
               写形式, 其中 X 的取值范围为 [0..9]。
  -todisk:   - 指定目标磁盘号。'-todisk:X' 是 '-to:"\\.\PhysicalDriveX"' 的简写
               形式, 其中 X 的取值范围为 [0..9]。

==============================================================================
为 '-sector', '-block' and '-maxbuf' 等选项指定尺寸:
  由 'm' or 'mb' (忽略大小写) 结尾的十进制数字: 识别为兆字节(MB)。
  由 'k' or 'kb' (忽略大小写) 结尾的十进制数字: 识别为千字节(KB)。
  其它: 识别为十进制字节数。

==============================================================================
为 '-fill' 选项指定值:
  0x, x (忽略大小写) 开头: 识别为十六进制值。
  0 开头                 : 识别为八进制值。
  0b, b (忽略大小写) 开头: 识别为二进制值。
  1-9 开头               : 识别为十进制值。

==============================================================================
识别设备名:

  在 Windows 平台上,存储设备号(磁盘号)可以使用磁盘管理器等工具查看。可通过
  以下步骤打开磁盘管理器:右击 "我的电脑" -> 选择 "管理" -> 选择 "磁盘管理"。

  在 linux 和其它类 unix 平台上,可通过 /dev 目录查看当前系统中已识别的存储设
  备。

==============================================================================
使用范例:
  rdd -from:/dev/sda -to:~/disk.img -logfile:~/rdd-sda.log
  rdd -fromdisk:1 -todisk:2 -sector:4k
  rdd -fromdisk:1 -to:datapart2.img -sector:4k -perrange:51.45-87.5
  rdd -from:"D:\My Data\file.dat" -to:E:\rec.dat -retry:3 -fill:B10101010
  rdd -fromdisk:1 -to:D:\disk.img -sector:4k -priority:idle
  rdd -from:/dev/sda -to:/data/disk.img -cooldown:20/5
  rdd -from:/dev/sda -to:/data/disk.img -perrange:34.25
  rdd -from:/dev/sda -to:/data/disk.img -secrange:-11785600

 

下载

rdd_msw_x86.zip (Windows/DOS,DOS 版需要 HXDOS 环境支持且功能受限)
rdd_msw_x64.zip
rdd_linux_x86.zip (在 Ubuntu 11.04 上测试通过)
rdd_linux_x64.zip (在 Ubuntu 16.04 上测试通过)
rdd_linux_arm64.zip (在 Ubuntu 18.04 上测试通过)
rdd_freebsd_x64.zip (在 FreeBSD 7.0 上测试通过)
rdd_macosx_x64.zip (在 Mac OS X 10.14 上测试通过)
rdd_solaris_x86.zip (在 OpenSolaris 2009.06 上测试通过)