In this post you will learn how to check Bad Blocks or Bad Sectors on Hard Disk in Linux
The sector is the minimum storage unit of a hard drive. Most disk partitioning schemes are designed to have files occupy an integral number of sectors regardless of the file’s actual size.
Files that do not fill a whole sector will have the remainder of their last sector filled with zeroes. In practice, operating systems typically operate on blocks of data, which may span multiple sectors.
As bad sectors continue to accumulate, they can undesirably or destructively affect your disk drive or flash memory capacity or even lead to a possible hardware failure.
Check Bad blocks or Sectors using badblocks utility
A badblocks is a software app enables users to scan a device for bad sectors or blocks.
- Display info about all your disk drives or flash memory and their partitions using fdisk command as shown below.
- Check for a bad sectors or a bad blocks with command badblocks as follows:
badblocks -v /dev/sda4 > bad_sector.txt
NOTE: “-v” will display details of the operation (checking bad blocks and sectors) and The redirection will store the result of this operation in the file bad_sector.txt
NOTE: If you find any bad sectors on your disk drive, unmount the disk and instruct the operating system not to write to the reported sectors as shown below:
- Run e2fsck (for ext2/ext3/ext4 file systems) or fsck command with the bad_sector.txt file and the device file as in the command below.
e2fsck -l bad_sector.txt /dev/sda4 #For ext2/ext3/ext4 file systems OR fsck -l bad_sector.txt /dev/sda4 #For other file systems
Check Bad bloxks or Sectors using Smartmontools
Smartmontools (S.M.A.R.T. Monitoring Tools) is a set of utility programs (smartctl and smartd) to control and monitor computer storage systems using the Self-Monitoring, Analysis and Reporting Technology (S.M.A.R.T.) system built into most modern (P)ATA, Serial ATA, SCSI/SAS and NVMe hard drives, so that you can figure out any impending hardware failures.
- Install smartmontools with:
apt-get install smartmontools #On Debian/Ubuntu yum install smartmontools #On RHEL/CentOS
- Now run the smartctrl command with -H flag or –health and name your specific device as an argument to display the SMART overall health test result.
smartctl -H /dev/sda4
Result: tells you that your hard disk is healthy.
NOTE: You can also use -a or –all for an full overview of disk information to print out all SMART information concerning a disk and -x or –xall which displays all SMART and non-SMART information about a disk.
- Also you can go to smartctl man page or help page:
smartctl -h man smartctl
In this article, We will show you how to Check Bad Sectors or Bad Blocks on Hard Disk in Linux.