LinuxCommandLibrary

mbadblocks

Check a RAID array for bad blocks

SYNOPSIS

mbadblocks [ -s ] [ -v ] [ -t test_pattern ] [ -b block_size ] [ -p num_passes ] [ -w ] [ -o output_file ] device

PARAMETERS

device
    The block device corresponding to the ext2/3/4 filesystem to be scanned (e.g., /dev/sdb1).

-s
    Shows the progress of the scan, including current block number and estimated time.

-v
    Produces verbose output, providing more detailed information about the scanning process.

-t test_pattern
    Specifies the test pattern to be used by badblocks. Common patterns include '0x00' (zeros), '0xff' (ones), or 'random' (random data).

-b block_size
    Specifies the block size of the filesystem in bytes. If not specified, mbadblocks attempts to determine it automatically.

-p num_passes
    Specifies the number of times the drive should be scanned. More passes increase accuracy but take longer.

-w
    Enables write-mode testing, which performs destructive write tests on the disk. All data on the device will be overwritten and lost. This option is highly discouraged on filesystems containing valuable data.

-o output_file
    Specifies the file where the list of found bad blocks will be written. This file is crucial for the subsequent offline marking phase.

DESCRIPTION

mbadblocks is a utility that automates the process of finding bad blocks on an ext2, ext3, or ext4 filesystem and subsequently marking them in the filesystem's bad block inode. What distinguishes mbadblocks from a direct use of badblocks and e2fsck is its two-phase operation designed to minimize downtime for large filesystems.

The first phase involves running badblocks to scan the device. Crucially, this scan can be performed while the filesystem is mounted and in use, allowing the system to remain online during the potentially lengthy scanning process. The detected bad blocks are written to a specified output file.

The second phase requires the filesystem to be unmounted. mbadblocks then invokes e2fsck, passing the list of bad blocks from the output file to mark them as unusable within the filesystem's metadata. This ensures that the filesystem does not allocate data to these faulty sectors, preventing data corruption. This approach is highly beneficial for enterprise environments or systems with very large storage volumes where continuous operation is critical.

CAVEATS

  • The initial scanning phase can be performed on a mounted filesystem, but the final phase of marking bad blocks in the filesystem metadata requires the filesystem to be unmounted.
  • Using the -w (write-mode) option is destructive and will erase all data on the target device. Exercise extreme caution.
  • While the online scan minimizes downtime, it can still impact disk I/O performance during its operation.
  • mbadblocks is designed specifically for ext2, ext3, and ext4 filesystems. It will not work on other filesystem types like XFS or Btrfs.

TWO-PHASE OPERATION

mbadblocks operates in two distinct phases:
1. Online Scan: badblocks is run on the device to identify faulty sectors, saving the list to an output file. This phase can be executed while the filesystem is actively in use.
2. Offline Marking: The filesystem must be unmounted. e2fsck is then automatically called by mbadblocks, using the previously generated bad block list to mark these sectors as unusable within the filesystem's inode table, thus preventing future data corruption.

IMPORTANCE OF OUTPUT FILE

The file specified with the -o option is critical. It serves as the bridge between the online scanning phase and the offline marking phase. Without this file, the bad blocks found during the scan cannot be reliably communicated to e2fsck for permanent marking.

HISTORY

mbadblocks is part of the e2fsprogs suite, a collection of utilities for managing ext2, ext3, and ext4 filesystems. It was developed to address the practical challenge of performing bad block checks on increasingly large storage volumes without requiring extended periods of system downtime. Its design reflects the need for a more flexible approach to disk health maintenance, particularly for server environments where continuous availability is paramount. It bridges the gap between passive bad block detection and active, metadata-level marking.

SEE ALSO

badblocks(8), e2fsck(8), fsck(8), tune2fs(8), debugfs(8)

Copied to clipboard