Commands.page Logo

How to Check for Bad Blocks on Ubuntu File System

Maintaining the integrity of your storage drives is essential for system stability on Ubuntu. This article outlines the specific terminal command used to detect physical defects on your hard drive or SSD. You will learn how to execute the scan safely, understand the required permissions, and know the precautions necessary to avoid data loss during the diagnostic process.

The Primary Command

The command used to check for bad blocks on a file system is badblocks. This utility searches for bad blocks on a device or partition and can output a list of them for further processing by tools like mke2fs or fsck.

Safety Precautions

Before running any disk diagnostic tool, you must ensure the target partition is unmounted. Running badblocks on a mounted file system can lead to severe data corruption. If you need to scan your root partition, you must boot from a Live USB environment.

How to Run the Scan

  1. Open the terminal application.
  2. Identify your drive letter using lsblk.
  3. Unmount the partition with sudo umount /dev/sdX1.
  4. Execute the command sudo badblocks -sv /dev/sdX1.

The -s flag shows progress, and the -v flag provides verbose output. If the command returns no output, the drive has no detected bad blocks. If numbers appear, those represent the block addresses of physical defects.

Integrating with Fsck

While badblocks finds defects, the fsck command repairs file system inconsistencies. You can trigger a bad block check during a file system repair by running sudo fsck -c /dev/sdX1. This ensures that any found bad blocks are marked in the file system to prevent future data writes to those areas.