Forrest logo
back to the badblocks tool

badblocks:tldr:2b3ad

badblocks: Search an unmounted disk in destructive mode and output found blocks to a file.
$ sudo badblocks -o ${filename} -w ${-dev-sdX}
try on your machine

The command sudo badblocks -o ${filename} -w ${-dev-sdX} is used to check and repair bad blocks on a storage device, typically a hard disk drive or solid-state drive, in a Linux system.

Here's a breakdown of the components:

  • sudo: This is a command that allows a user with administrative privileges to execute a command as the superuser or root. It ensures the execution of the following command with elevated privileges.

  • badblocks: This is the command-line utility used to search for and identify bad blocks on a storage device. It examines specific sectors or ranges of sectors on the drive and reports any issues found.

  • -o ${filename}: This option specifies the output file where the results of badblocks will be saved. ${filename} is a placeholder that should be replaced with an actual file name and location.

  • -w: This option tells badblocks to perform a read-write test instead of just a read-only test. By writing and verifying data patterns on the storage device, it tries to detect any faulty sectors that may exist.

  • ${-dev-sdX}: This refers to the device that you want to check for bad blocks. ${-dev-sdX} is again a placeholder and should be replaced with the actual device name, such as /dev/sda or /dev/nvme0n1.

When you execute this command, badblocks will scan the specified device, write data patterns to it, and then read and compare the written data to check for any discrepancies. If it detects bad blocks, it will report them in the output file specified by -o.

It's important to note that this command should be used with caution as it involves read-write operations on the storage device, which can potentially lead to data loss if used incorrectly.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the badblocks tool