chkdsk

检查卷的文件系统和文件系统元数据是否存在逻辑和物理错误。 If used without parameters, chkdsk displays only the status of the volume and doesn't fix any errors. If used with the /f, /r, /x, or /b parameters, it fixes errors on the volume.

Important

Membership in the local Administrators group, or equivalent, is the minimum required to run chkdsk. To open a command prompt window as an administrator, right-click Command prompt in the Start menu, and then select Run as administrator.

Important

Interrupting chkdsk isn't recommended. However, canceling or interrupting chkdsk shouldn't leave the volume any more corrupt than it was before chkdsk was run. Running chkdsk again checks and should repair any remaining corruption on the volume.

Note

Chkdsk 只能用于本地磁盘。 该命令不能与通过网络重定向的本地驱动器号一起使用。

Syntax

chkdsk [<volume>[[<path>]<filename>]] [/f] [/v] [/r] [/x] [/i] [/c] [/l[:<size>]] [/b] [/scan] [/forceofflinefix] [/perf] [/spotfix] [/sdcleanup] [/offlinescanandfix] [/freeorphanedchains] [/markclean] [/?]

Parameters

Parameter Description
<volume> 指定驱动器号(后跟冒号)、装入点或卷名。
[<path>]<filename> 仅用于文件分配表(FAT)和 FAT32。 Specifies the location and name of a file or set of files that you want chkdsk to check for fragmentation. You can use the wildcard characters ? and * to specify multiple files.
/f 修复了磁盘上的错误。 磁盘必须锁定。 If chkdsk can't lock the drive, a message appears that asks you if you want to check the drive the next time you restart the computer.
/v 选中磁盘时,显示每个目录中每个文件的名称。
/r 查找不良扇区并恢复可读信息。 磁盘必须锁定。 /r includes the functionality of /f, with the additional analysis of physical disk errors.
/x 首先强制该卷卸载(如有必要)。 驱动器的所有打开句柄都失效。 /x also includes the functionality of /f.
/i 仅用于 NTFS。 Performs a less vigorous check of index entries, which reduces the amount of time required to run chkdsk.
/c 仅用于 NTFS。 Doesn't check cycles within the folder structure, which reduces the amount of time required to run chkdsk.
/l[:<size>] 仅用于 NTFS。 将日志文件大小更改为键入的大小。 If you omit the size parameter, /l displays the current size.
/b 仅用于 NTFS。 清除卷上错误的群集列表,并针对错误重新扫描所有已分配的和免费的群集。 /b includes the functionality of /r. 将卷映像化到新的硬盘驱动器后,请使用此参数。
/scan 仅用于 NTFS。 对卷运行联机扫描。
/forceofflinefix Use with NTFS only (must be used with /scan). 绕过所有联机修复;发现的所有缺陷都排队进行脱机修复(例如 chkdsk /spotfix)。
/perf Use with NTFS only (must be used with /scan). 使用更多系统资源尽快完成扫描。 这可能会对系统上运行的其他任务产生负面影响。
/spotfix 仅用于 NTFS。 对卷运行现成修复。
/sdcleanup 仅用于 NTFS。 Garbage collect unneeded security descriptor data (implies /f).
/offlinescanandfix 对卷运行脱机扫描并修复。
/freeorphanedchains 仅用于 FAT/FAT32/exFAT。 释放任何孤立的群集链,而不是恢复其内容。
/markclean 仅用于 FAT/FAT32/exFAT。 Marks the volume clean if no corruption was detected, even if /f wasn't specified.
/? 在命令提示符下显示帮助。

Remarks

  • The /i or /c switch reduces the amount of time required to run chkdsk by skipping certain volume checks.

  • If you want chkdsk to correct disk errors, you can't have open files on the drive. 如果文件已打开,将显示以下错误消息:

    Chkdsk cannot run because the volume is in use by another process. Would you like to schedule this volume to be checked the next time the system restarts? (Y/N)
    
  • If you choose to check the drive the next time you restart the computer, chkdsk checks the drive and corrects errors automatically when you restart the computer. If the drive partition is a boot partition, chkdsk automatically restarts the computer after it checks the drive.

  • 还可以使用 chkntfs /c 命令来计划下次重启计算机时要检查的卷。 Use the fsutil dirty set command to set the volume's dirty bit (indicating corruption), so that Windows runs chkdsk when the computer is restarted.

  • You should use chkdsk occasionally on FAT and NTFS file systems to check for disk errors. Chkdsk examines disk space and disk use and provides a status report specific to each file system. 状态报告显示文件系统中发现的错误。 If you run chkdsk without the /f parameter on an active partition, it might report spurious errors because it can't lock the drive.

  • Chkdsk corrects logical disk errors only if you specify the /f parameter. Chkdsk must be able to lock the drive to correct errors.

    Because repairs on FAT file systems usually change a disk's file allocation table and sometimes cause a loss of data, chkdsk might display a confirmation message similar to the following:

    10 lost allocation units found in 3 chains.
    Convert lost chains to files?
    
    • If you press Y, Windows saves each lost chain in the root directory as a file with a name in the format File<nnnn>.chk. When chkdsk finishes, you can check these files to see if they contain any data you need.

    • If you press N, Windows fixes the disk, but it doesn't save the contents of the lost allocation units.

  • If you don't use the /f parameter, chkdsk displays a message that the file needs to be fixed, but it doesn't fix any errors.

  • 如果在 chkdsk /f* 大型磁盘或具有大量文件的磁盘上使用(例如,数百万个文件), chkdsk /f 可能需要很长时间才能完成。

  • Use the /r parameter to find physical disk errors in the file system and attempt to recover data from any affected disk sectors.

  • If you specify the /f parameter, chkdsk displays an error message if there are open files on the disk. If you don't specify the /f parameter and open files exist, chkdsk might report lost allocation units on the disk. 如果尚未在文件分配表中记录打开的文件,可能会发生这种情况。 If chkdsk reports the loss of a large number of allocation units, consider repairing the disk.

  • 由于启用了共享文件夹卷影副本时无法锁定共享文件夹卷卷的 卷影副本 ,因此针对源卷运行 chkdsk 可能会报告错误或导致 chkdsk 意外退出。 You can, however, check shadow copies for errors by running chkdsk in Read-only mode (without parameters) to check the Shadow Copies for Shared Folders storage volume.

  • The chkdsk command, with different parameters, is available from the Recovery Console.

  • On servers that are infrequently restarted, you might want to use the chkntfs or the fsutil dirty query commands to determine whether the volume's dirty bit is already set before running chkdsk.

chkdsk 在不同媒体上的表现

  • Physical nature: HDDs use spinning magnetic platters. 扇区和块从拼盘中物理读取。

  • chkdsk 运行时:

    • The physical head must move to each data location being checked, which is slower due to mechanical movement.
    • Checking for bad sectors (with /r) takes longer as every sector's physical integrity is checked and bad ones are replaced if possible.
    • 对于大型驱动器来说,高小时运行时并不少见。

通常,在大容量 HDD 上, /r 或者在 /b 读取每个扇区时花费相当长的时间。 即使没有错误且大部分为空的驱动器,物理读取速度也会使该过程成为瓶颈。

在某些情况下,在大容量 HDD 上,可能会 chkdsk 太快地完成其进程。 如果发生这种情况,可能是:

  • 卷作系统(OS)或其他进程装载为脏或锁定。
  • chkdsk 作实际上并没有扫描驱动器上的每个扇区。
  • HDD 可能有读取头失败或其他硬件问题,导致 chkdsk 行为不可预知。
  • chkdsk 作仅对文件系统结构执行联机扫描,在启动到 OS 之前未显式运行脱机扫描。

chkdsk查看日志可能会指向扫描过程中的潜在问题。 若要了解详细信息,请参阅 查看 chkdsk 日志

了解退出代码

The following table lists the exit codes that chkdsk reports after it has finished.

Exit code Description
0 未找到任何错误。
1 找到并修复了错误。
2 Performed disk cleanup (such as garbage collection) or didn't perform cleanup because /f was not specified.
3 Could not check the disk, errors could not be fixed, or errors were not fixed because /f was not specified.

Examples

若要检查驱动器 D 中的磁盘并出现 Windows 修复错误,请键入:

chkdsk d: /f

If it encounters errors, chkdsk pauses and displays messages. Chkdsk finishes by displaying a report that lists the status of the disk. 在完成之前 chkdsk ,无法打开指定驱动器上的任何文件。

若要检查当前目录中 FAT 磁盘上的所有文件是否存在非连续块,请键入:

chkdsk *.*

Chkdsk displays a status report, and then lists the files that match the file specifications that have noncontiguous blocks.

查看 chkdsk 日志

有两种方法可用于使用事件查看器和 PowerShell 在 Windows 中检索 chkdsk 日志文件。

若要使用事件查看器查看日志,请执行以下步骤:

  1. Start >Control Panel>Administrative Tools>Event Viewer.

    Alternatively, press Win + R keys to bring up the run dialog box, type eventvwr.msc, and select OK.

  2. Expand Windows Logs> right-click on Application> select Filter Current Log.

  3. “筛选器当前日志 ”窗口中,导航到 “事件源 ”下拉菜单,选择 ChkdskWininit

  4. Select OK to finish filtering for these two sources.