News Stay informed about the latest enterprise technology news and product updates.

Built-in Windows defragmenter better by leaps and bounds

Life is a lot easier for administrators now that the Disk Defragmenter utility is a built-in feature in newer versions of Windows Server. There are some limitations in an enterprise environment, however.

The Disk Defragmenter that's built into Windows 2000 and Windows Server 2003 offers a great improvement over previous editions of Windows. This is especially true for those of us who cut our teeth on Windows NT 4, where the only way to perform disk defragmentation was through the use of third-party add-ons.

In 2000 and Server 2003, the defragmenter can be run through the Computer Management utility, or as part of a customized Microsoft Management Console (MMC) snap-in. To use the Disk Defragmenter, you need to be logged onto the machine as a member of the local administrators group -- or preferably using the runas command -- to maintain the principle of least privilege.

So what actually happens when you defragment a hard drive? As you can see in the screenshot below, the blue areas represent contiguous files, or those that are stored with little to no defragmentation. The red areas represent files that are fragmented. When you click "Defragment" within the GUI, the defragmentation process begins to scan your entire hard drive. When it finds a fragment of a file, it performs the following tasks behind the scenes:

  1. Locates the other fragments of the file stored at other locations on the disk.
  2. Copies them into a single contiguous file at a point on the disk that contains sufficient free space.
  3. Compares the copied file to the original to make sure that nothing was changed or corrupted.
  4. Updates the Master File Table (MFT), which is an index on your hard drive that contains the location of every file stored on the drive. (A new addition to the defragmenter in Windows Server 2003 is that the MFT itself can now be optimized. This wasn't the case in Windows 2000.)
  5. Deletes the original fragments and informs the MFT that the space that held those fragments is now free space.

Because of this process of continually copying files during the defrag process, any volume that you defragment needs to have at least 15% free space in order for the defragmenter to function. You may also need to run chkdsk before running the defragmenter, since the utility won't run if the volume has been marked as dirty, which indicates possible corruption.

You can also run the Disk Defragmenter from the command line, using defrag.exe. The command-line defragmenter uses the following syntax:

defrag Volume [/a] [/v] [/f]

Volume refers to the drive letter or mount point of the volume that you want to defragment. By adding the /a switch, you can analyze the volume and display a report indicating whether you should defrag the volume or not -- just like the "Analyze" button in the MMC snap-in. The /v switch will display a more verbose report than the /a switch, including a complete analysis and defragmentation report. Finally, the /f switch will force defrag.exe to defragment the volume even if there is insufficient free space to function efficiently.

While the built-in Disk Defragmenter

For more information

Read Microsoft's Knowledge Base article on defragmenting

Find out why disk defragging is a lowly, but critical chore

Learn the top 10 disk defragging pointers

is a welcome addition to the Windows operating system, it does have several significant limitations that you need to be aware of if you're looking for an enterprise defragmenting solution. The Windows defragmenter can only operate on local disk volumes; you can't launch a scan or a defrag of a volume on a machine residing across your network. Additionally, you can only defragment a single volume at a time, and you can't defrag one volume while scanning another. And according to Microsoft, you can't schedule a defragmentation job to run at a later time.

Now, I've seen some administrators work some interesting mojo by integrating the defrag.exe command-line defragmenter into VBScript, and then using the Task Scheduler to automate the script. However, this is almost entirely a homegrown solution that may or may not scale well to a large environment. In a future segment, I'll look at some third-party alternatives that can offer better functionality for centralized management across a large network.

Laura E. Hunter is a Microsoft MVP and site expert.

Dig Deeper on Windows Server storage management

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.