Sub topic 6
Disk commands: chkdsk, format, and diskpart
This chapter assumes you can open an elevated Command Prompt and read /? help, as covered earlier. You should also know what a partition, a volume, and a file system are.
chkdsk: check a volume
chkdsk (check disk) scans a volume's file system and reports problems. Run alone, it only reads. It repairs nothing.
| Switch | What it does |
|---|---|
| `/f` | Fixes file system errors |
| `/r` | Finds bad sectors and recovers readable data. It includes `/f`, so it takes much longer |
chkdsk C: /f
chkdsk D: /rA volume must be locked before chkdsk can fix it. If you run /f on the system drive, Windows offers to schedule the check for the next restart. Answer Y, then restart.
format: erase and prepare a volume
format writes a new file system to a volume and erases the data on it. A quick format (/Q) rebuilds the file system structures but skips the surface scan. A full format also checks the disk for bad sectors, so it takes longer.
format E: /FS:NTFS /Q /V:DataHere /FS picks the file system (NTFS, exFAT, or FAT32), and /V sets the volume label. Use exFAT when a removable drive must work on both Windows and macOS and hold files over 4 GB. FAT32 cannot store files that large.
diskpart: manage disks, partitions, and volumes
diskpart is an interpreter with its own prompt. You start it, then type its commands. Its commands act on whatever object is currently selected.
diskpart
list disk
list volume
exitListing is safe. Changes are not. The usual pattern is to list, select, and then act.
diskpart
list disk
select disk 1
detail disk
clean
create partition primary
format fs=ntfs quick label=Data
assign letter=E
exitselect disk 1 is an example. Your disk number will differ.
Common errors
- "Access denied" or "You do not have sufficient privileges": the Command Prompt is not elevated. Reopen it as administrator.
- "Cannot lock current drive":
chkdskcannot lock the volume because it is in use. Schedule the check for restart. - A disk shows as raw or offline: use Disk Management or
diskpartto bring it online and initialize it. Do not format it until you know the data on it is not needed. - Formatting the wrong drive letter: drive letters can change between sessions. Check the label and size with
list volumefirst.
Exercise
A technician must repair file system errors on the C: drive and recover data from bad sectors. Which command does this, and why does Windows ask to restart?
Show answer
Run chkdsk C: /r from an elevated Command Prompt. The /r switch includes /f, so it fixes errors and also locates bad sectors. Windows asks to restart because C: is in use and cannot be locked, so the check is scheduled for the next boot.
Exercise
Which diskpart command erases the partition table of the selected disk, and what should you run first to avoid selecting the wrong disk?
Show answer
clean erases it. Run list disk and detail disk first to check the disk number, size, and model.