解决‘$MFTMirr does not match $MFT (record 0)’

最近在ubuntu上COPY 文件到移动硬盘上(NTFS),中途挂掉,结果无法访问NTFS移动硬盘,

按照在墙外的某wordpress blog,解决了这个问题~

 

How to fix ‘$MFTMirr does not match $MFT (record 0)’

Sometimes, when you are executing a file transfer between your computer hard drive and an external drive and your computer shutdown for some reason (in my case, no battery/ac power) it’s pretty common to get some errors on external drives that uses NTFS as they file system.

The most common message is:

Error mounting: mount exited with exit code 13: $MFTMirr does not match $MFT (record 0).
Failed to mount ‘/dev/sdb3′: Input/output error
NTFS is either inconsistent, or there is a hardware fault, or it’s a
SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows
then reboot into Windows twice. The usage of the /f parameter is very
important! If the device is a SoftRAID/FakeRAID then first activate
it and mount a different device under the /dev/mapper/ directory, (e.g.
/dev/mapper/nvidia_eahaabcc1). Please see the ‘dmraid’ documentation
for more details.

One workaround for this issue is to do as the message says, boot on Windows and try to use the awesome NTFS tool that Windows offer. But a perfect solution for a Linux users is to use the ntfsprogs utility.

UPDATE: On some recent Linux releases, you need to install ntfs-3g utilties.  Try sudo apt-get install ntfs-3g or download from http://www.tuxera.com/community/ntfs-3g-download/

ntfsprogs is a suite of NTFS utilities based around a shared library. The tools are available for free and come with full source code.

  • mkntfs: Create an NTFS volume on a partition
  • ntfscat: Print a file on the standard output
  • ntfsclone: Efficiently backup/restore a volume at the sector level
  • ntfscluster: Given a cluster, or sector, find the file
  • ntfsfix: Forces Windows to check NTFS at boot time
  • ntfsinfo: Dump a file’s attributes, completely
  • ntfslabel: Display or set a volume’s label
  • ntfslib: Move all the common code into a shared library
  • ntfsls: List directory contents
  • ntfsresize: Resize an NTFS volume
  • ntfsundelete: Find files that have been deleted and recover them
  • ntfswipe: Write zeros over the unused parts of the disk
  • ntfsdefrag: Defragment files, directories and the MFT
  • ntfsck: Perform consistancy checks on a volume
  • nttools: Command-line tools to view/change an offline NTFS volume, e.g. ntfscp, ntfsgrep, ntfstouch, ntfsrm, ntfsrmdir, ntfsmkdir
  • ntfsdiskedit: Walk the tree of NTFS ondisk structures (and alter them)

Be careful with these utilities, they might damage the filesystem, or your hard disk !

With ntfsprogs installed (sudo apt-get install ntfsprogs) you should execute the following commands in a terminal:

sudo ntfsfix /dev/partitionName

After this command you should expect the following output:

~$ sudo ntfsfix /dev/sdb3
Mounting volume... FAILED
Attempting to correct errors...
Processing $MFT and $MFTMirr...
Reading $MFT... OK
Reading $MFTMirr... OK
Comparing $MFTMirr to $MFT... FAILED
Correcting differences in $MFTMirr record 0...OK
Processing of $MFT and $MFTMirr completed successfully.
Setting required flags on partition... OK
Going to empty the journal ($LogFile)... OK
NTFS volume version is 3.1.
NTFS partition /dev/sdb3 was processed successfully.

After this step you should be able to access your external drive partition as usual, mount or use nautilus to access your files.

Source:  http://gnuwin32.sourceforge.net/packages/ntfsprogs.htm

NTFS文件系统中,$MFTMirr$MFT 的一个重要镜像文件,用于冗余存储部分关键文件记录,以提高文件系统的可靠性和恢复能力。$MFTMirr 主要存储了 $MFT 中前几个关键元文件的镜像记录,例如 $MFT 自身、根目录、位图等。 要确认 $MFTMirr 的起始位置,可以通过 $MFT 记录中的特定签名来识别。在 NTFS 文件系统中,每条 MFT 记录的开头都有一个固定签名,通常为 ASCII 字符串 "FILE" 或 "BAAD"(表示损坏的记录)。对于 $MFTMirr 来说,其对应的 MFT 记录在 $MFT 文件中的位置是固定的,且可以通过 WinHex 工具进行定位。 ### 使用 WinHex 定位 $MFTMirr 的起始位置 1. **确定 $MFT 的起始簇号** 首先,需要从 NTFS 分区的引导记录(BPB)中获取 $MFT 的起始簇号。在 WinHex 中打开磁盘,定位到分区的引导扇区(通常是分区的第 0 扇区),查找偏移 0x30 处的 8 字节值,该值表示 $MFT 的起始簇号。 2. **计算 $MFTMirr 的 MFT 记录偏移** 每个 MFT 记录大小为 1024 字节,而 $MFTMirr 对应的记录通常位于 $MFT 文件中的第 2 个 MFT 记录(索引为 1,因为记录从 0 开始计数)。因此,$MFTMirr 的 MFT 记录偏移为: ``` $MFT 起始偏移 + (1 * 1024) ``` 3. **跳转至 $MFTMirr 的 MFT 记录** 在 WinHex 中,可以手动计算出 $MFT 的起始位置后,加上 1024 字节偏移,即可跳转到 $MFTMirr 的 MFT 记录位置。此时应看到记录头的签名 "FILE",并且记录中包含 $80 属性(数据属性),该属性中包含 Run List,用于定位 $MFTMirr 文件的实际存储位置。 4. **解析 $80 属性中的 Run List** 在 $MFTMirr 的 MFT 记录中找到 $80 属性,解析其属性体中的 Run List。Run List 描述了 $MFTMirr 文件数据在磁盘上的物理存储位置和长度。通过解析 Run List,可以确定 $MFTMirr 的起始簇号和大小。 5. **定位 $MFTMirr 文件的实际位置** 根据 Run List 中的信息,计算出 $MFTMirr 文件的起始扇区,并在 WinHex 中跳转到该位置查看其内容。$MFTMirr 通常包含前 16 条 MFT 记录的镜像,包括 $MFT 自身、$MFTMirr、$LogFile、$Volume 等元文件的记录。 ### 示例:定位 0x1AC12000 处的 MFT 记录 若已知某个 MFT 记录位于偏移 0x1AC12000 处,可以通过 WinHex 打开磁盘并直接跳转至该偏移位置。检查该位置是否为有效的 MFT 记录,即开头为 "FILE" 签名,并且记录中包含 $80 属性。若确认是 $MFTMirr 的记录,则可通过解析其 $80 属性中的 Run List 来定位 $MFTMirr 文件的实际存储位置。 ### 代码示例:解析 MFT 记录头 以下是一个简单的 Python 代码片段,用于读取 MFT 记录的前 4 字节以验证其签名: ```python with open('ntfs_partition.img', 'rb') as f: mft_offset = 0x1AC12000 # 假设 MFT 记录位于此偏移 f.seek(mft_offset) signature = f.read(4) print(f"Signature: {signature.decode('ascii')}") ``` 若输出为 `Signature: FILE`,则表示该位置是一个有效的 MFT 记录。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值