3.10. Checking a Volume for Errors

Problem

You want to check a volume for errors.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. Right-click the drive you want to defragment and select Properties.

  3. Click the Tools tab.

  4. Under Error-checking, click the Check Now button.

  5. If you want to fix any file system errors that are found, check the box beside Automatically fix file system errors. If you want to perform a thorough scan of the disk and check for bad sectors, check the box beside Scan for an attempt recovery of bad sectors.

  6. Check the disk options you want and click Start.

  7. Click OK when the check completes.

Using a command-line interface

The chkdsk utility can detect problems with a volume and attempt to fix them. Specify the name of the volume you want to check to run chkdsk in read-only mode:

> chkdsk D:

Use the /f option to have chkdsk attempt to fix any errors it finds:

> chkdsk D: /f

With the /f option, chkdsk will try to lock the drive, so if it is in use by another process, you will only be able to schedule it to run during the next reboot. You can include the /x option with /f to force the volume to be dismounted (for a nonsystem volume).

Using VBScript

' This code tries to perform a chkdsk on the specified volume.
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strDrive = "<Drive>" ' e.g., D: boolFixErrors = True ' True = chkdsk /f, False = chkdsk ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objDisk ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.