Common disk errors are physical failures, bad sectors or blocks, and inconsistent filesystems. These disk errors can be checked using standard tools in Linux from the command line.

The disk must not be mounted when performing these tests. In the case where it's a root filesystem, and it's not possible to be unmounted when when there are logged-in users, you can use a live Linux system such as by booting into Ubuntu installer disk. It is similar to when recovering a lost partition table.

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

  1. Launch terminal.
  2. List available disks on your system.
    $ lsblk
    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. Make sure the disk you want to check is not mounted.
    $ sudo umount /dev/sdb
    [sudo] password for user:
  4. Check disk S.M.A.R.T. health status using smarctl.
    $ 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,
    SMART Health Status: OK
  5. Check for filesystem consistency of disk using 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. Check for disk bad blocks or bad sector 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.