How to find out bad sectors on your linux hard disk


Badblocks is a Linux utility to assess unhealthy sectors on a disk power. It creates a list of those sectors which can be used with other applications like mkfs, so that they aren’t used at some point and for that reason does not corrupt the data. This article explains about – how to find out bad Sectors ie. bad Blocks on your Linux Hard Disk.

To get the information about Block Devices on your machine, use the following command –

$ lsblk

Checking Bad Sectors

There are so many sophisticated methods which are available to find bad blocks. The most used method is as shown below-

To get the information about bad blocks status, install the following package on Ubuntu as shown below –

$ sudo apt-get install smartmontools

The sample output should be like this −

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
   s-nail
Suggested packages:
   exim4 | mail-transport-agent gsmartcontrol smart-notifier
The following NEW packages will be installed:
   s-nail smartmontools
0 upgraded, 2 newly installed, 0 to remove and 284 not upgraded.
Need to get 795 kB of archives.
After this operation, 2,398 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 s-nail amd64 14.8.6-1 [353 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 smartmontools amd64 6.4+svn4214-1 [442 kB]
Fetched 795 kB in 1s (541 kB/s)
Selecting previously unselected package s-nail.
(Reading database ... 174772 files and directories currently installed.)
Preparing to unpack .../s-nail_14.8.6-1_amd64.deb ...
Unpacking s-nail (14.8.6-1) ...
.............................................................................................

To get the more information about smartctl, use the following command –

$ smartctl -h

The sample output should be like this –

smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-31-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

Usage: smartctl [options] device

============================================ SHOW INFORMATION OPTIONS =====

   -h, --help, --usage
   Display this help and exit

   -V, --version, --copyright, --license
   Print license, copyright, and version information and exit

   -i, --info
   Show identity information for device

   --identify[=[w][nvb]]
   Show words and bits from IDENTIFY DEVICE data (ATA)

   -g NAME, --get=NAME
   Get device setting: all, aam, apm, lookahead, security, wcache, rcache, wcreorder

   -a, --all
   Show all SMART information for device

   -x, --xall
   Show all information for device

   --scan
   Scan for devices

   --scan-open
   Scan for devices and try to open each device

================================== SMARTCTL RUN-TIME BEHAVIOR OPTIONS =====

   -q TYPE, --quietmode=TYPE (ATA)
      Set smartctl quiet mode to one of: errorsonly, silent, noserial

   -d TYPE, --device=TYPE
      Specify device type to one of: ata, scsi, sat[,auto][,N][+TYPE], usbcypress[,X], usbjmicron[,p][,x][,N],    usbsunplus, marvell, areca,N/E, 3ware,N, hpt,L/M/N, megaraid,N, aacraid,H,L,ID, cciss,N, auto, test

   -T TYPE, --tolerance=TYPE (ATA)
      Tolerance: normal, conservative, permissive, verypermissive

   -b TYPE, --badsum=TYPE (ATA)
      Set action on bad checksum to one of: warn, exit, ignore

   -r TYPE, --report=TYPE
      Report transactions (see man page)

   -n MODE, --nocheck=MODE (ATA)
      No check if: never, sleep, standby, idle (see man page)

.........................................................................................

Verifying The hard disk health

To verify the hard disk health, use the following command –

$ sudo smartctl -H /dev/sda

The sample output should be like this −

smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-31-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

If the above result gives a failure information, then use the following command to scan the bad blocks.

$ sudo badblocks -v /dev/sdb

It takes few minutes to check hard disk. In my case, it has given the following result −

Checking blocks 0 to 3595263
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)

Congratulations! Now, you know “How to find out bad Sectors ie. bad Blocks on your Linux Hard Disk? ”. We’ll learn more about these types of commands in our next Linux post. Keep reading!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Oct-2019

882 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements