How to fix corrupted hard drive using CMD?

What causes hard drive corruption?

There are several potential causes of hard drive corruption:

  • File system errors – The file system manages how data is stored on the drive. If it becomes corrupted, access to data is disrupted.
  • Bad sectors – Portions of the physical disk become damaged and unreadable.
  • Malware or viruses – Malicious programs can attack the file system or overwrite data.
  • Improper ejection – Removing external drives without properly ejecting can lead to corruption.
  • Power failure – A power outage while writing data could corrupt the file structure.
  • Driver conflicts – Outdated, buggy, or incompatible drivers may interact poorly with the disk.
  • Physical damage – Dropping or jarring a disk while in use could physically damage it.

Corruption can occur in the disk’s firmware, file system, partition table, or stored data. The end result is an inability to reliably access files and folders as expected.

How can you tell if a hard drive is corrupted?

There are several signs that point to a corrupted hard drive:

  • Inability to boot into the operating system
  • Missing, inaccessible, or strangely named files and folders
  • Frequent crashes and freezes
  • Unusual noises from the hard drive
  • S.M.A.R.T. errors reported by disk utilities
  • Disk errors flagged by the operating system
  • Problems installing updates or saving files
  • Data stored on the drive appears corrupted

Essentially any ongoing problem related to reading, writing, or accessing data on the hard drive may indicate corruption. The system will struggle or fail entirely to work with the damaged disk.

Can CMD check and fix hard drive errors?

Yes, the Windows Command Prompt provides several useful tools for checking and repairing hard drive issues. Here are some of the key commands available:

  • Chkdsk – Scans and repairs file system issues. It can fix many drive errors.
  • Sfc /scannow – Verifies and replaces important system files.
  • DISM – Lets you repair the Windows image and components.
  • Format – Completely erases and reformats a partition.
  • Bootrec – Repairs the master boot record and boot configuration.
  • Diskpart – A multifunction utility that can wipe, format, and partition drives.

The CLI provides low-level access to the hard drive for troubleshooting. Admins can use these tools to diagnose corruption issues and automatically repair the drive where possible.

How to use Chkdsk to fix drive errors

Chkdsk (“check disk”) is one of the best tools for checking and repairing file system problems. To use it:

  1. Open the Command Prompt as administrator.
  2. Type “chkdsk C: /f” and press Enter to scan drive C.
  3. Type “Y” and press Enter to confirm you want to proceed.

Chkdsk will check the file system structure for issues and repair any found problems.

Common repairs include:

  • Fixing invalid file record segments.
  • Recovering bad sectors.
  • Recovering orphaned files/folders.
  • Correcting invalid directory entries.
  • Updating disk allocation maps.

The /f parameter tells Chkdsk to fix any errors found. Omit /f to check the drive without repairing.

You can scan other drives by substituting C: with the drive letter.

Using Sfc for system file repair

Sfc (“system file checker”) verifies system files and can replace corrupted ones with cached copies. To use it for corruption repair:

  1. Open an elevated Command Prompt.
  2. Enter “sfc /scannow” and press Enter.
  3. Wait for the scan to reach 100%. Repairs happen automatically.
  4. Restart your computer when done to complete the process.

Sfc will scan Windows system files and check them against a known good cache. Any errors or violations are automatically fixed by replacing files.

This can help repair drive issues caused by missing system files. The scan may take 15-30 minutes.

Using DISM for image repair

The Deployment Image Servicing and Management (DISM) tool can repair the Windows image and its components. To use it:

  1. Open Command Prompt as admin.
  2. Type “DISM /Online /Cleanup-Image /RestoreHealth” and press Enter.
  3. DISM will scan Windows and attempt repairs. This may take 5+ minutes.
  4. Restart your PC when finished for changes to complete.

DISM works at a lower level than Sfc, fixing issues in the Windows image itself. It is more comprehensive but also slower.

Use this if Sfc cannot repair all corruption issues. It may be able to fix problems like boot failures that Sfc cannot.

Fixing the MBR and boot configuration

The master boot record (MBR) stores info needed to boot into Windows. The Bootrec tool can automatically repair it.

To rebuild and fix the MBR:

  1. Open Command Prompt as admin.
  2. Type “bootrec /fixmbr” and press Enter to overwrite and rebuild the MBR code.
  3. Type “bootrec /fixboot” and press Enter to repair boot files.
  4. Type “bootrec /scanos” to find Windows installations.
  5. Type “bootrec /rebuildbcd” to fix BCD store issues.

For BCD issues, Bootrec may find multiple entries. Delete any that are unknown or redundant.

This automates fixing common boot and MBR-related problems that could be caused by corruption.

Erasing drives with Diskpart

The Diskpart utility provides full command line access to your disks. You can use it to clean, format, or fully erase drives.

To format a corrupted drive:

  1. Open Command Prompt as admin.
  2. Type “diskpart” and press Enter.
  3. Type “list disk” to view available disks.
  4. Select the corrupted disk (eg “select disk 2”).
  5. Type “clean” to erase all data and partitions.
  6. Type “create partition primary” to create a new partition.
  7. Type “format fs=ntfs quick” to do a quick format as NTFS.
  8. Type “assign” to make the partition active.
  9. Exit diskpart.

This will completely wipe and reformat the drive. Be absolutely certain you select the right disk, as this erases all data.

When to use data recovery software

CMD tools should be able to fix most filesystem problems. But if corruption occurs within stored files themselves, more advanced recovery software may be needed.

Consider data recovery software if:

  • CMD tools cannot access the files at all.
  • Files still appear corrupted after using CMD repairs.
  • You need to recover deleted files.
  • The partition table is damaged.
  • There is physical damage to the disk.

Software can rebuild heavily damaged disks sector-by-sector. CMD tools work well for general fixe

Conclusion

The Windows Command Prompt provides powerful utilities for diagnosing and repairing hard drive corruption issues. Chkdsk and Sfc can fix many file system and system file problems. DISM can repair the core Windows image itself. And tools like Bootrec and Diskpart give low-level access for repairs.

In most cases CMD tools should be able to fix drive errors and get Windows booting again. But for heavy corruption or recovering lost files, more advanced data recovery software may be required.

With the right tools, it’s often possible to repair a corrupted hard drive and regain access to your important files and system.