Disk errors in Linux can lead to slow applications, kernel warnings, and permanent data loss if they go unnoticed. Regular checks on attached disks catch failing hardware and filesystem inconsistencies before they corrupt important data or bring services down.

Block devices expose disks and partitions under paths like /dev/sda and /dev/sdb1, which tools can probe at both the hardware and filesystem levels. Utilities such as lsblk show how these devices map to mount points, smartctl queries S.M.A.R.T. attributes from the drive firmware, fsck validates on-disk filesystem metadata, and badblocks performs sequential reads to locate sectors that no longer return clean data.

Thorough checks require taking filesystems offline so no writes occur while metadata repairs or bad-block scans are in progress. On systems where a disk holds the root or boot filesystem, checks are best performed from a live Linux environment or rescue mode. Heavy scans can run for hours on large disks, and misidentifying the target device can destroy data, so device names and mount points from lsblk should be verified carefully before starting maintenance.

Steps to check disk errors in Linux:

  1. Open a terminal with access to sudo privileges.
  2. List available disks to identify the device name for the disk that requires checking.
    $ lsblk
    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
    loop0    7:0    0   512M  0 loop /mnt/bench
    loop1    7:1    0   256M  0 loop /mnt/errorcheck
    ##### snipped #####
    vda    254:0    0   1.8T  0 disk 
    `-vda1 254:1    0   1.8T  0 part /etc/hosts
                                     /etc/hostname
                                     /etc/resolv.conf
    vdb    254:16   0 606.5M  1 disk 
    ##### snipped #####

    Use the NAME and MOUNTPOINT columns to correlate devices like loop1 with their filesystems and mount points.

  3. Unmount the filesystem on the target disk or partition so no data is being written during testing.
    $ sudo umount /dev/loop1

    Replace loop1 with the correct disk or partition, such as sdb1, and ensure no processes are using the mount point before unmounting.

  4. Check the disk's S.M.A.R.T. overall health status using smartctl.
    $ sudo smartctl -H /dev/loop1
    smartctl 7.4 2023-08-01 r5530 [aarch64-linux-6.12.54-linuxkit] (local build)
    Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org
    
    /dev/loop1: Unable to detect device type
    Please specify device type with the -d option.
    
    Use smartctl -h to get a usage summary

    Some virtual disks and loop-backed devices do not expose S.M.A.R.T. data; if smartctl cannot detect a device type, try a hardware-backed disk or specify a device type with -d.

  5. Run fsck on the disk or partition to check and repair filesystem-level inconsistencies.
    $ sudo fsck -f -y /dev/loop1
    fsck from util-linux 2.39.3
    e2fsck 1.47.0 (5-Feb-2023)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    errorcheck: 11/65536 files (0.0% non-contiguous), 8268/65536 blocks

    Running fsck on a mounted or actively used filesystem can corrupt data; always unmount the filesystem first or use a live environment for root and boot partitions.

  6. Scan the disk for bad blocks using badblocks in read-only mode.
    $ sudo badblocks -v /dev/loop1
    Checking blocks 0 to 262143
    Checking for bad blocks (read-only test): done
    Pass completed, 0 bad blocks found. (0/0/0 errors)

    Read-only scans avoid overwriting data but can still take many hours on large disks; avoid the -w option unless data is fully backed up because it performs destructive write testing.

  7. Remount the disk once all checks have completed without errors.
    $ sudo mount /dev/loop1 /mnt/errorcheck

    Adjust the device and mount point so they match the original mapping, for example mounting sdb1 back on /mnt/data or another appropriate directory.

  8. Verify that the disk is mounted correctly and visible at the expected mount point.
    $ df -h /mnt/errorcheck
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/loop1      224M   24K  206M   1% /mnt/errorcheck

    Confirm that the Mounted on column shows the expected path (such as /mnt/errorcheck) and that the reported size matches the disk identified earlier with lsblk.