Recipe3.10.Checking a Volume for Errors


Recipe 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 = objWMI.Get("Win32_LogicalDisk.DeviceID='" & strDrive & "'") intRC = objDisk.ChkDsk(boolFixErrors) if intRC = 0 then    WScript.Echo "Chkdsk completed successfully." elseif intRC = 1 then    WScript.Echo "Chkdsk scheduled on next reboot." else    WScript.Echo "Error running chkdsk: " & intRC end if

Discussion

On Windows Server 2003, you can use the new vrfydsk command to perform the same function as chkdsk in read-only mode. Vrfydsk creates a shadow copy of the target volume, assigns a drive letter to it, runs chkdsk (read-only mode) against that drive, unassigns the drive, and removes the shadow copy. This is useful because often when running chkdsk on an active volume it may report transient errors that are due to the volume being in use. With vrfydsk, you don't have to worry about disk activity skewing the results. If vrfydsk reports that errors were found, you'll want to schedule a chkdsk /f as soon as possible on the volume.

See Also

MSDN: Chkdsk Method of the Win32_Volume Class, MS KB 160963 (CHKNTFS.EXE: What You Can Use It For), MS KB 187941 (An explanation of CHKDSK and the new /C and /I switches), MS KB 191603 (Modifying the Autochk.exe Time-out Value), MS KB 218461 (Description of Enhanced Chkdsk, Autochk, and Chkntfs Tools in Windows 2000), and MS KB 837326 (How to use the Vrfydsk.exe tool to check a volume for errors without taking the volume offline in Windows Server 2003).



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net