从格式化为 exfat 的损坏 U 盘上恢复数据的记录

把一个格式化为 exfat 格式的 64GB U 盘放到一个老旧的 Android 平板上用了一下,结果就无法识别了。在电脑上也是无法用,Windows 提示需要格式化,Linux 无法挂载但是可以显示硬件信息。虽然数据丢失也影响不大,可是为了减少整理数据的时间,还是尽量修复了一下。以下是修复过程记录。

初步估计这个 U 盘只是分区表被破坏了,这是常见问题。但是因为 exfat 格式的容错能力非常差(无日志且只有一个文件分配表(FAT, File Allocation Table),所以它就这么不工作了。不到万不得已还是不要用 exfat 比较好。UBUNTU 社区有份很好的数据恢复手册,给了我很大的帮助(逃离 Windows 投奔 openSUSE 之后第一次在 Linux 下尝试恢复被损坏的磁盘)。

下面的记录比较长,这里简单列一下:

  • 首先制作一个该 U 盘的镜像,以免恢复过程出错;
  • 直接使用 Windows 的检查修复磁盘指令即可修复,
    chkdisk /f f:

    本来 Linux 应该也有个类似的修复的指令的,但是我不会。

U 盘硬件信息

在 Windows 系统的电脑上插上 U 盘会提示需要格式化。在 Linux 系统中挂载,提示如下,

# mount /dev/sdc1 lttusb
FUSE exfat 1.1.0
ERROR: exFAT file system is not found.

dmesg 查看显示信息为,

[64101.274020] usb 4-1.2: new high-speed USB device number 9 using ehci-pci
[64101.636628] usb 4-1.2: New USB device found, idVendor=0951, idProduct=1666
[64101.636633] usb 4-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[64101.636635] usb 4-1.2: Product: DataTraveler 3.0
[64101.636637] usb 4-1.2: Manufacturer: Kingston
[64101.636639] usb 4-1.2: SerialNumber: 0019E06B9C90BF70E711234B
[64101.636933] usb-storage 4-1.2:1.0: USB Mass Storage device detected
[64101.637601] scsi host14: usb-storage 4-1.2:1.0
[64102.733049] scsi 14:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
[64102.734211] sd 14:0:0:0: Attached scsi generic sg4 type 0
[64103.867458] sd 14:0:0:0: [sdc] 122915328 512-byte logical blocks: (62.9 GB/58.6 GiB)
[64103.868076] sd 14:0:0:0: [sdc] Write Protect is off
[64103.868083] sd 14:0:0:0: [sdc] Mode Sense: 23 00 00 00
[64103.868685] sd 14:0:0:0: [sdc] No Caching mode page found
[64103.868698] sd 14:0:0:0: [sdc] Assuming drive cache: write through
[64103.900219] sdc: sdc1
[64103.903081] sd 14:0:0:0: [sdc] Attached SCSI removable disk

fdisk 显示信息为,

Disk /dev/sdc: 58.6 GiB, 62932647936 bytes, 122915328 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xadc56094

Device Boot Start End Sectors Size Id Type
/dev/sdc1 * 8064 122915327 122907264 58.6G 7 HPFS/NTFS/exFAT

lsusb 显示信息为,

Bus 004 Device 009: ID 0951:1666 Kingston Technology DataTraveler G4
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

用到的一些软件

主要是免费软件。也就偶尔用一次的功能真心不舍得去买软件。

Linux 上的 PhotoRecTestDisk。openSUSE 上可以直接从官方库里安装,

# zypper in photorec qphotorec testdata

其中 qphotorec 是 PhotoRec 的图形界面。

Linux 上的 gnu_ddrescue。可用于制作 U 盘的镜像。安装,

# zypper install gnu_ddrescue

Windows 下的挂载虚拟镜像为磁盘的工具 ImDisk(命令行 imdisk)或者带图形界面的 OSFMount

制作文件系统的镜像文件

为了避免修复/恢复过程中对 U 盘进行了操作而导致不可逆转的二次破坏,先将 U 盘的内容镜像出来。这样即使恢复过程出错也还可以使用镜像来继续恢复。当然,最好的是直接对镜像再备份之后进行恢复操作

制作 U 盘的镜像参考了这里的一个恢复磁盘的记录。

新建一个文件夹用于存放镜像文件,

# mkdir /usbresc

看看要恢复的驱动器分区,

# fdisk -l

这里假设是 /dev/sdcsdc1 分区。

为了将 U 盘整个内容镜像到一个文件里,费了挺大劲儿。

尝试 1:ddrescue

直接从命令行操作,

# ddrescue -d /dev/sdc1 /usbresc/sdc1.img /usbresc/sdc1.log
GNU ddrescue 1.20
Press Ctrl-C to interrupt
rescued: 50348 MB, errsize: 0 B, current rate: 78994 B/s
 ipos: 50348 MB, errors: 0, average rate: 21957 kB/s
 opos: 50348 MB, run time: 38m 13s, remaining time: 8m
time since last successful read: 0s
Copying non-tried blocks... Pass 1 (forwards)
ddrescue: Input file disappeared: No such file or directory

这个过程比较漫长。我的 64GB U 盘用了大约 40 分钟。而且可以看出来这个镜像应该并不完整,得到的文件容量 50GB 小于实际容量。所以这个肯定是废的。

之后又试了两次,虽然比上面这个得到的文件再大些,但依旧低于实际容量值。

NOTE:

也许可以试试直接用 Linux 里的 dd 这个方法:

# dd if=/dev/sdc of=/usbresc/sdc3 bs=512

其中 bs 是 Sector size,可以通过 fdisk -l 查询到(总容量大小是 bs*sectors)。

还可以试试使用 ddrescue 的另一组指令重新镜像。但是没机会测试了。参考:http://www.forensicswiki.org/wiki/Ddrescue

First you copy as much data as possible, without retrying or splitting sectors:

ddrescue --no-split /dev/hda1 imagefile logfile

Now let it retry previous errors 3 times, using uncached reads:

ddrescue --direct --max-retries=3 /dev/hda1 imagefile logfile

If that fails you can try again but retrimmed, so it tries to reread full sectors:

ddrescue --direct --retrim --max-retries=3 /dev/hda1 imagefile logfile

尝试 2:TestDisk

NOTE: TestDisk 也许可以修复我的 U 盘,但是因为不熟悉,没成功。但是它成功创建了正确的镜像,完成了本该 ddrescue 完成的任务。

现在改用 testdisk 试试看。

命令行输入 testdisk,会让选择驱动器,选择 /dev/sdc 然后 Quick Search。大约 5 分钟。提示“No partition found”。

然后进行 Deep Search。不行,同上。

然后选择 [Advanced] Filesystem Utils,之后选择 Create Image 生成 U 盘的镜像 image.dd。这次镜像成功,大小跟 64GB U 盘该有的容量大小相符

NOTE:testdisk 刚开始检测的时候有这么个提示,

Hint: None partition table type has been detected.
Note: Do NOT select ‘None’ for media with only a single partition. It’s very
rare for a disk to be ‘Non-partitioned’.

所以我就选择了 Intel(第一个)。结果证明修复后的 U 盘检测结果还是如上,所以如果是 exfat 文件系统或许真该选择 None。我如果选择 None 也许能直接恢复文件也说不定。当然,即使能恢复,也不如下面的方法简便。

到 Windows 下修复文件系统

到 Windows 下(汗,不知道 Linux 下与 chkdsk 功能一样的软件是什么)。

挂载虚拟硬盘

首先使用 ImDisk(命令行 imdisk)或者带图形界面的 OSFMount。 将镜像文件 image.dd 挂载为虚拟硬盘,然后使用 Windows 命令行下的 chkdsk /f 修复。

这里使用的是 PASSMARK 提供的免费软件 OSFMount。

步骤:

  • 下载安装 OSFMount;
  • 运行 OSFMount;
  • 单击图形界面左下角的 Mount new;
  • 在弹出窗口的 Image file 一行选择 image.dd;
  • 修改自动探测的参数:
    • 勾去 Read-only drive;
    • 勾选 Mount as removable media;
    • 单击 OK 确认并回到主窗口;
  • 记录该虚拟硬盘的驱动器号(第一列的字母,这里假设为 H)。

使用 CHKDSK 修复磁盘镜像

步骤:

  • 打开命令行窗口(开始 -> 附件 -> 命令行窗口);
  • 输入 chkdisk h: 输出类似于,
     The type of the file system is exFAT.
     The volume is in use by another process. Chkdsk
     might report errors when no corruption is present.
     Volume Serial Number is 2815-8665
     Windows found errors on the disk, but will not fix them
     because disk checking was run without the /F (fix) parameter.
     Corruption was found while examining the boot region.
     Windows is verifying files and folders...
     Volume label is USBDISK.
     File and folder verification is complete.
     Windows found problems with the file system.
     Run CHKDSK with the /F (fix) option to correct these.
    
     61450496 KB total disk space.
     57074304 KB in 54 files.
     1536 KB in 12 indexes.
     0 KB in bad sectors.
     256 KB in use by the system.
     4374400 KB available on disk.
     
     131072 bytes in each allocation unit.
     480082 total allocation units on disk.
     34175 allocation units available on disk.

    提示可以通过 /F(fix)参数修复文件系统;

  • 接着输入
    chkdisk /f h:

    输出类似于,

    The type of the file system is exFAT.
     Volume Serial Number is 2815-8665
     Corruption was found while examining the boot region.
     Windows is verifying files and folders...
     Volume label is USBDISK.
     File and folder verification is complete.
     Windows has made corrections to the file system.
    
     61450496 KB total disk space.
     57074304 KB in 54 files.
     1536 KB in 12 indexes.
     0 KB in bad sectors.
     256 KB in use by the system.
     4374400 KB available on disk.
    
     131072 bytes in each allocation unit.
     480082 total allocation units on disk.
     34175 allocation units available on disk.

    提示文件系统已修复。

检查驱动器 H 发现已可以正常访问,文件也都在。修复完成。

使用 CHKDSK 直接修复 U 盘

既然可以修复,而且已经有一份磁盘镜像可用于恢复文件,下面直接修复 U 盘,看是否可行。

假设 U 盘盘符为 F。接着在命令行中输入,

chkdisk /f f:

提示跟前面的类似。磁盘已修复。

后记

期间还在 Windows 下使用 Active UNERASER 试着恢复文件,很快扫描完毕且可以恢复文件(将文件复制到另外的地方)。但是未注册版的 UNERASER 一次只能复制一个文件,复制第二个文件要关闭 UNERASER 后重新打开、重新扫描,依次类推。它至少告诉我文件是可以恢复的。©

本文发表于水景一页。永久链接:<http://cnzhx.net/blog/recovery-data-from-an-exfat-formatted-usb-stick/>。转载请保留此信息及相应链接。

1 条关于 “从格式化为 exfat 的损坏 U 盘上恢复数据的记录” 的评论

时间过去太久,评论已关闭。
如果您有话要说,请到讨论区留言并给出此文章链接。
谢谢您的理解 :-)