Programming Field

Chkdsk - DOS/Command Prompt Reference

Checks the disk (drive/volume). If the disk is in use by the system, administrator privileges are required to execute.

[MS-DOS/Windows 95/98/Me] To check for errors, please use Scandisk.

* The ReFS file system cannot be checked (it will display ‘does not need to be checked’).

Syntax

chkdsk[.exe] [<volume>[<file-name>]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:<size>]] [/B]
  [/scan [/forceofflinefix] [/perf]] [/spotfix] [/sdcleanup]
  [/offlinescanandfix] [/freeorphanedchains] [/markclean]
<volume> Specifies the disk to check. <volume> will be the drive letter (in the form of ‘X:’), mount point, or volume name (obtained using tools like Mountvol). If omitted, the current drive will be used.
<file-name> [FAT/FAT32] Specifies the filename to check for fragmentation. This is only effective if the disk for <volume> is formatted with FAT/FAT32.
/F

If errors are found on the disk, repairs will be carried out. Chkdsk will display a message and terminate if it cannot lock the disk due to files being in use or other reasons (you can also schedule it to run at the next restart).

If /F is specified, there is a possibility of modifying disk data for repairs, so in cases where the disk is in a serious condition, other errors may occur.

[Windows 8 or later] When using this option, an offline scan (checking the disk while it is not in use; may require a computer restart) will be performed. If you want to perform repairs with an online scan, use the /scan option.

/V Displays detailed information during the check. For FAT/FAT32, it will show all complete file names on the disk. For exFAT, it will display progress, and for NTFS, it will show cleanup messages (if any exist).
/R [Windows NT series / XP or later] Checks for bad sectors, and if found, marks those sectors as ‘bad’ and attempts to recover readable data.
/X [Windows NT series / XP or later] If necessary, forcibly dismounts the volume. If this option is not specified, a prompt will appear asking whether to dismount if the check cannot proceed due to reasons like files being open (volume in use). If canceled here, you can schedule the check to be performed at the next computer restart.
/I [Windows NT series / XP or later] [NTFS] Skips the index check. This will speed up the check completion time but may leave errors unresolved.
/C [Windows NT series / XP or later] [NTFS] Skips the folder structure check. This will speed up the check completion time but may leave errors unresolved.
/L[:<size>] [Windows NT series / XP or later] [NTFS] Changes the size of the log file within the NTFS volume. Specifies the size in kilobytes after ‘:’ as <size>. If only ‘/L’ is specified, it will display the current log file size and exit.
/B [Windows Vista or later] [NTFS] Rechecks bad clusters within the volume. If this option is specified, /R will be automatically enabled.
/scan [Windows 8 or later] [NTFS] Performs an online scan on the volume and repair to the extent possible. ‘Online scan’ means scanning while the disk is in use. From Windows 8 and later, online scans are performed by default, but if you don't use this option, it will only check in read-only mode. Additionally, if you use /F, it will be an offline scan. If you specifically want an offline scan, use /offlinescanandfix.
/forceofflinefix [Windows 8 or later] [NTFS] Does not perform repairs during online scans and mark for repairs during offline scans. This option requires ‘/scan’.
/perf [Windows 8 or later] [NTFS] Prioritizes performance during online scans, aiming to finish the scan as quickly as possible. This option requires ‘/scan’. Note that using this option may impact the performance of other running programs.
/spotfix [Windows 8 or later] [NTFS] Repairs errors marked during an unsuccessful repair attempt with /scan (or when using /forceofflinefix). This option cannot be used in conjunction with ‘/scan’.
/sdcleanup [Windows 8 or later] [NTFS] Removes unnecessary security descriptors (garbage collect) within the volume.
/offlinescanandfix [Windows 8 or later] Conducts an offline scan and repair on the volume. This is essentially similar in meaning to using the /F option.
/freeorphanedchains [Windows 10 or later] [FAT/FAT32/exFAT] If isolated files are found, instead of repairing them to make them accessible, deletes (releases) them.
/markclean [Windows 10 or later] [FAT/FAT32/exFAT] Even if scanned without using /F and no issues are found, marks it as ‘clean’.

Details

Chkdsk is primarily used in Windows NT series/XP and later versions to check and repair volume damage. However, if there are errors due to physical deterioration, Chkdsk scanning or repairs may potentially worsen the situation. If errors are detected multiple times, it is better to consider options such as replacing the disk.

Chkdsk returns the following exit codes. You can use commands like If Errorlevel to perform branching in your processes based on these codes.

CodeMeaning
0No errors were found.
1Errors were found and repaired.
2Disk cleanup was performed, or not performed because /F option was not present (if needed).
3The disk could not be checked, errors could not be repaired, or errors were not repaired because the /F option was not present.

Samples

Sample 1

chkdsk C:

Conducts a scan of the C drive. Since the /F option is not present, it will only perform a read-only check.

[Windows 8 or later] If no options are specified, it will conduct an online scan (checking while keeping the disk in use).

Sample 2

chkdsk C: /scan

[Windows 8 or later] Performs an online scan (check and repair errors to the extent possible) on the C drive.

Sample 3

chkdsk C: /spotfix

[Windows 8 or later] Repairs errors on the C drive that could not be fixed with /scan. By executing this after Sample 2, you can perform error repairs without a full offline scan by restarting the computer.