Windows 2000 Offline Active Directory Defrag

This article explains the mechanism and step-by-step procedure for performing an offline defragmentation of the Active Directory database in Microsoft Windows 2000. While the operating system automatically conducts garbage collection and online defragmentation at scheduled intervals, this built-in process only redistributes free space internally without reducing the physical file size of the database. To reclaim unused disk space and shrink the ntds.dit file on a Windows 2000 domain controller, administrators must manually perform an offline compaction using Directory Services Restore Mode and the ntdsutil command-line utility.

Why Offline Defragmentation Is Required

In Windows 2000, Active Directory utilizes the Extensible Storage Engine (ESE, or JET blue) to store objects within %SystemRoot%\NTDS\ntds.dit. The background online defragmentation process runs automatically every 12 hours. However, it cannot release physical storage back to the file system because the database file is locked exclusively by the operating system. Performing an offline defragmentation creates a brand-new, compacted copy of ntds.dit containing only active objects and contiguous storage allocations.

Step 1: Booting into Directory Services Restore Mode

Because the Active Directory service cannot be stopped independently in Windows 2000 while the operating system is running in standard mode, the domain controller must be taken offline:

  1. Restart the Windows 2000 Server domain controller.
  2. Press F8 during the initial boot sequence when the Windows 2000 startup menu appears.
  3. Select Directory Services Restore Mode (Windows 2000 domain controllers only) and press Enter.
  4. Log on using the local Administrator account and the Directory Services Restore Mode password designated during the DCPROMO configuration.

Step 2: Running the NTDSUTIL Command

Once logged in, open the Command Prompt (cmd.exe) to access the database management utility:

  1. Enter ntdsutil and press Enter.
  2. At the ntdsutil: prompt, type files and press Enter to open the file management menu.
  3. At the file maintenance: prompt, confirm the current path settings by typing info to verify the location of the existing ntds.dit file and log files.

Step 3: Compacting the Database

Windows 2000 requires an empty target folder with sufficient disk space to hold the compacted database file. The target drive must have enough free space to hold at least the projected size of the newly compacted database.

  1. Ensure a destination directory exists (for example, C:\CompactDB).
  2. At the file maintenance: prompt, execute the following command:
    compact to C:\CompactDB
  3. The ESE engine analyzes the database, reads all records, and writes a defragmented copy of ntds.dit to the specified directory.
  4. Once completed, type quit twice to exit the file maintenance prompt and then exit ntdsutil.

Step 4: Replacing the Database File

The compacted file must replace the original database file before returning the server to production:

  1. Copy the newly created file (C:\CompactDB\ntds.dit) to the original database directory (by default, %SystemRoot%\NTDS\ntds.dit), overwriting the old, fragmented file.
  2. Delete the log files (*.log) in the %SystemRoot%\NTDS folder. Windows 2000 requires log file removal after a compact operation so the database engine can regenerate clean log files at the next startup. Do not delete the checkpoint file (edb.chk) if present, though standard procedure often permits deleting all .log files.
  3. Remove the temporary folder (C:\CompactDB).

Step 5: Normal System Restart

Restart the server normally without pressing F8. Windows 2000 will boot in full Directory Services mode, load the newly compacted ntds.dit file into memory, initialize fresh transaction logs, and resume normal Active Directory operations with an optimized database footprint.