Common disk errors include physical failures, bad sectors or blocks, and inconsistent filesystems, which can lead to various problems. Diagnosing these issues in Linux can be done using built-in command line tools.

The disk must not be mounted when performing these tests. If it's necessary to check the root filesystem and it cannot be unmounted due to logged-in users, you can boot into a live Linux system, such as the Ubuntu installer disk. This method is also helpful for recovering partition tables.

Steps to scan for disk error and bad sector in Linux:

  1. Open the terminal application.
  2. Display the list of available disks on your system.
    $ lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    loop0    7:0    0 55.4M  1 loop /snap/core18/1997
    loop1    7:1    0  219M  1 loop /snap/gnome-3-34-1804/66
    loop2    7:2    0 64.8M  1 loop /snap/gtk-common-themes/1514
    loop3    7:3    0 32.3M  1 loop /snap/snapd/11588
    loop4    7:4    0   51M  1 loop /snap/snap-store/518
    loop5    7:5    0 65.1M  1 loop /snap/gtk-common-themes/1515
    sda      8:0    0   20G  0 disk 
    ├─sda1   8:1    0    1M  0 part 
    ├─sda2   8:2    0  513M  0 part /boot/efi
    └─sda3   8:3    0 19.5G  0 part /
    sdb      8:16   0   20G  0 disk /mnt/data
    sr0     11:0    1 1024M  0 rom
  3. Ensure the disk you wish to examine is unmounted.
    $ sudo umount /dev/sdb
    [sudo] password for user:
  4. Assess the disk's S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology) health status using smartctl.
    $ sudo smartctl -H /dev/sdb
    smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.11.0-16-generic] (local build)
    Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    SMART Health Status: OK
  5. Examine the filesystem consistency on the disk with fsck.
    $ sudo fsck /dev/sdb
    fsck from util-linux 2.36.1
    e2fsck 1.45.7 (28-Jan-2021)
    /dev/sdb: clean, 11/1310720 files, 126322/5242880 block
  6. Inspect the disk for bad blocks or bad sectors using badblocks.
    $ sudo badblocks -v /dev/sdb
    Checking blocks 0 to 20971519
    Checking for bad blocks (read-only test): done                                                 
    Pass completed, 0 bad blocks found. (0/0/0 errors)
Discuss the article:

Comment anonymously. Login not required.