Disk errors in Linux can cause system instability and data loss. Common issues include bad sectors, disk failures, and filesystem inconsistencies. Regular checks with built-in tools help prevent these problems.
Ensure the disk is unmounted before running diagnostics. If unmounting is not possible, use a live Linux system like Ubuntu for checking.
Different tools check various aspects of disk health. Use smartctl for hardware checks, fsck for filesystem integrity, and badblocks to find bad sectors.
Steps to check disk errors in Linux:
- Open the terminal application.
- List available disks in 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
- Unmount the disk you intend to check.
$ sudo umount /dev/sdb [sudo] password for user:
Replace sdb with your specific disk identifier.
- Check 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
- Run fsck to check the filesystem.
$ 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
- Scan the disk for bad blocks 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)
- Remount the disk after completing all checks.
$ sudo mount /dev/sdb /mnt/data
Author: Mohd
Shakir Zakaria
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.