The Disk Defragmenter that's built into Windows 2000 and Windows Server 2003 offers a great improvement over previous...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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:
- Locates the other fragments of the file stored at other locations on the disk.
- Copies them into a single contiguous file at a point on the disk that contains sufficient free space.
- Compares the copied file to the original to make sure that nothing was changed or corrupted.
- 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.)
- 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
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 SearchWin2000.com site expert.