How do you defragment the MFT on an NTFS disk?

28

12

A while ago, I nearly filled my hard drive, much more than the recommended maximum of 85% of capacity. I believe that NTFS started storing files in the space reserved for the Master File Table (MFT) and the MFT had to fragment elsewhere as it grew.
I have cleared off space on the hard drive, but the MFT apparently remains fragmented, and there's a lot of slow disk access for even very simple operations like opening a folder or small file. This is killing performance. I remember that Windows standard disk defragmenter doesn't defragment the MFT because the MFT is in use when the operating system is running. I'm running Vista Ultimate and its defragment utility has very little in the way of reporting, less than older versions.

I suspect that a solution might involve booting up from an optical disc with a basic OS ("Live CD") and running a defragment utility from that. Can anybody tell me what program to use, or how to defragment my MFT?

Thanks!

WBT

Posted 2011-07-27T23:29:56.043

Reputation: 1 383

See also How can I move the MFT to end of contiguous used space?

– Vadzim – 2019-01-18T09:54:10.330

1

It is not free, but I know Disckeeper can handle this.

– Zoredache – 2011-07-27T23:37:32.903

Answers

36

You can use the Sysinternals tool Contig:

contig.exe c:\$mft

Dmitri Sologoub

Posted 2011-07-27T23:29:56.043

Reputation: 361

2Didn't work for me. UltimateDefrag shows $MFT from a non-sytem partition is fragmented, but contig says "All files were either already defragmented or unable to be defragmented." Anyway I really don't know why theres is $MFT there. – Yuri Ghensev – 2016-06-20T17:01:07.590

Note: I tried to do this in PowerShell on Windows 10 and all it kept doing was print the help. In the normal command shell it worked as expected. EDIT: I just found out why: The $ has special meaning in PS and needs escaping: contig.exe 'c:\$mft' works. – Frederic Leitenberger – 2019-12-15T17:25:49.433

15

Auslogics Disk Defrag Pro will accomplish this for you. Whilst not a free program, you can download a free trial, and if you do decide to purchase the license is available for use on up to three PCs.

Ultradefrag is a free and powerful FOSS defragmentation tool for the Windows Platform. It can defragment any system files including registry hives and paging file. It includes MFT optimization, which processes the MFT only.

Simon

Posted 2011-07-27T23:29:56.043

Reputation: 4 193

@BornToCode Any way to get Ultradefrag to not move files to the end of the partition when it optimizes the MFT? – RockPaperLizard – 2016-07-27T22:15:20.237

1@RockPaperLizard - I don't know, but the alternative to not moving those few files to the end is to shift every other file on the disk. You might try running ordinary Windows Defrag or Diskeeper after Ultradefrag; bear in mind however, that ordering every file by how many times it's used will be a long-running operation that will fall apart the next time you launch a web browser. – KeithS – 2016-08-24T16:23:41.540

Note that you'll now need to follow the download link to the "old versions," as the current version 8 is no longer FOSS. – trlkly – 2019-09-01T20:16:33.447

3+1 Ultradefrag did miracles to me with a stubborn $MFT that even Contig (that got so many upvotes here) couldn't defeat – BornToCode – 2013-04-16T14:52:34.673

6

Best tool by far was the old JKdefrag, now Mydefrag. Will defrag the MFT. Also, it's free.

The original site is down but one can source to get the latest version is here: https://www.techspot.com/downloads/3720-jkdefrag-mydefrag.html

edit

Windows Defrag API, used by MyDefrag, supports defragging the MFT.

Following are the system file, stream, and stream types supported by FSCTL_MOVE_FILE in "filename:streamname:$typename" format.

$MFT::$DATA $MFT::$ATTRIBUTE_LIST $MFT::$BITMAP

And MyDefrag's script documentation:

Inode   Filename    Description
0   $MFT    Master File Table - An index of every file.
1   $MFTMirr    A backup copy of the first 4 records of the MFT.
2   $LogFile    Transactional logging file.
3   $Volume Serial number, creation time, dirty flag.
4   $AttrDef    Attribute definitions.
6   $Bitmap Contains volume's cluster map (in-use vs. free).
7   $Boot   Boot record of the volume.
8   $BadClus    Lists bad clusters on the volume.
9   $Quota  [Windows NT only] Quota information.
9   $Secure Security descriptors used by the volume.
10  $UpCase Table of uppercase characters used for collating.
11  $Extend A directory for: $ObjId, $Quota, $Reparse, $UsnJrnl.
$Extend\$ObjId  Unique Ids given to every file.
$Extend\$Quota  Quota information.
$Extend\$Reparse    Reparse point information.
$Extend\$UsnJrnl    USN Journal.
$Extend\$RmMetadata Transactional data.

While it won't run on a Live CD, it will run on Bart PE or the Ultimate Windows BootCD.

But neither is necessary to defrag the MFT.

surfasb

Posted 2011-07-27T23:29:56.043

Reputation: 21 453

the site is now: http://www.mydefrag.net/

– Randall Flagg – 2016-07-25T09:03:50.093

jkdefrag and mydefrag are now dead - mydefragGUI can still be downloaded at mydefrag.net as the above comment shows but there has been no update since 2009 – thomasrutter – 2017-11-16T03:47:36.107

I've read the author sold the software hence no updates. Having said that it is functionally complete and the best one it seems hence why I keep using it - http://www.hofmannc.de/en/windows-7-defragmenter-test/benchmarks.html

– Daniel Sokolowski – 2017-12-08T04:14:56.940

Yep, this. I believe the defrag API was changed with Vista, so you don't even need to reboot. – Hydaral – 2011-07-28T01:08:32.477

1MyDefrag runs only on Windows; you can't run it from an open-source LiveCD. It claims to only remove files from the reserved MFT space, not to defragment the MFT if it's already fragmented. Is there another program [to be posted as a different answer] that can defragment the MFT? – WBT – 2011-08-27T00:07:54.983

You are wrong. It's not explicit because the Defrag API supports defraging the MFT. Plus, you can check the MyDrag scripts. – surfasb – 2011-08-28T15:23:22.850

5

These steps worked for me:

  1. Run the MiniXP in Hiren's BootCD.
  2. Disable Hibernation, Virtual Memory and Kernel Memory Dump.
  3. Follow the instructions described in this link (use the fsutil).
  4. Run MyDefrag at MiniXP with the option "Consolidate free space".
  5. Start Windows again and now you can shrink you partition.

gagallo7

Posted 2011-07-27T23:29:56.043

Reputation: 336

-1

there is an option on ultimatedefrag that provides a boot time defrag , however it didn't work for me but i hope it works for you

ultimatedefrag > tools >settings... > boot time

select the drive that you want , it takes a while analyze the drive . when its done analyzing you can adjust the mft file location but i recommend to leave it how it is (if you changed it there is a button to rest it to default) . then toggle the Run during next boot option and just restart the pc

for me it stack at 24% every time and then boots up the windows without defraging the file but hope it works for you . share your expertise too

abbas handsome

Posted 2011-07-27T23:29:56.043

Reputation: 1