Header Ads

How to Fix Bad Blocks and Bad Sectors on Hard Disks in Linux

fixing-bad-blocks-linux-image


Bad blocks in hard disks are commonly physical, arising due to the permanent damage to hard disk or OSes restricting and blocking the disk space for its use.

If errors occur while reading or writing data to a specific location on the hard disk, or if any folder stored on the hard disk is corrupted or missing, points to the hard disk containing bad blocks or sectors

When bad blocks start occurring, it's about time to replace the hard disk. In today's post, we'll discuss how to identify bad blocks on the hard disk in Linux. Also, we'll discuss how to fix bad blocks on the hard disk.

I. How to check for bad blocks on the hard disk in Linux

1. Using Badblocks Tool To Check Bad Blocks In Linux

  • The overall status of the hard disk can be determined using the Badblocks tool through the Linux terminal.
  • This process may take a while in generating the complete hard disk report.
  • This command has read-only permission, so writing tests cannot be performed.

A specific part of the hard disk can also be checked with Badblocks command, by merely selecting the particular portion of the hard disk inside the Badblocks command. To find the disk path, use command 'fdisk -l'.

Usage
(replace sda with disk name)

`sudo badblocks -sv -b 512 /dev/sda`

`sudo badblocks -s /dev/sda`


Run the following command within the Linux terminal to automatically generate the log files of all the bad blocks or sectors found on the hard disk.

This command would generate the document if bad sectors were found on the hard disk. (Replace sda which your disk name)

`sudo badblocks -v /dev/sda > badsectors.txt`


2. How To Check for Bad Sectors On Hard Disk In Linux

The fdisk list command is employed to watch hard disc for bad sectors. This command displays an inventory of all the storage devices connected with the PC. Linux terminal must be run as the superuser; otherwise, difficulties may arise while running the command.

`sudo fdisk -l`

3. How To Check Bad Sectors On Hard Disk In Linux Using Smartmontools

The Smartmontools is a reliable and useful method for contemporary disks like ATA/SATA, which comes with self-monitoring and analysis. First, require to install the Smartmontools, the below command installs the Smartmontools utility.

`sudo apt update`

`sudo apt install smartmontools`
           

Once the installation is complete, Smartmontools can be used from the Linux terminal. Run the "smartctl"  command to generate a smart report for the hard disk.

`sudo smartctl -a /dev/sda`


The whole generated test report is checked by scrolling below. This report includes a serial number, firmware version, form factor. Also, the Smart-health self-assessment report appears at the rock bottom of the terminal.

4. Using GNOME Disk Management Utility To Check Hard Disk Assessment

  • If the above-mentioned methods are challenging to follow, try this GUI tool for assessment in a few clicks. 
  • This quick method helps to seek out the present state, temperature, and overall assessment of the hard disk.
  • Linux (Ubuntu distros) feature this pre-installed disk management utility tool for GNOME known as Disk or Disks.
  • If you're using Linux Mint, click the start icon (mint logo) to open the menu panel and search for the 'Disks' application.
  • Select your hard disk on the left-side panel, and tap on the menu icon on the top-right corner of this window.
  • Choose 'Smart data and self-tests' and click the 'Start' button to start the tests.
When the self-test is complete, the disk assessment report appears with fail and error counts, as shown below.




!IMPORTANT - Before proceeding with steps given below, make sure you have taken a backup of the faulty disk drive. The following steps do not guarantee to fix disk drives, because the whole process depends on the condition of the disk drive. If it's mission-critical data that is present in your disk drive, we suggest you to contact professional support for data recovery.


II. How To Fix Bad Blocks On Hard Disk In Linux

1. Download and burn Linux Mint ISO to a removable storage like pen-drives (on Windows, use Rufus application for easy burning).

Linux Mint downloads page - https://linuxmint.com/download.php

Rufus downloads page - https://rufus.ie/downloads/

2. Restart the machine and boot from Pen-drive. If you have enabled Fastboot, you may have to give priority to Pen-drive in BIOS settings.

3. Open Linux terminal and check all hard drive partitions using "fdisk -l" command. Note the disk location for the hard drive, which needs to be scanned with the "e2fsck" command.

4. Use e2fsck utility to fix the errors on disk (replace sdb2 with name of disk)

`sudo e2fsck -cfpv /dev/sdb2`

5. Exit the Linux terminal when the "e2fsck" process is complete, and restart your PC and remove the bootable medium.

Note: The same can be achieved using the GUI disks tool. Follow up-to Step 2, and for step 3, open the 'Disks' tool and choose the 'Repair Filesystem' option.


Final Thoughts;

Hard drives get corrupted and worn-out with use. Sudden power surges and force shutdowns may also damage the drives. Following proper shutdown procedures and using 'Safely remove'/'Unmount' procedures before removing devices can prolong the life of the disk drives. When you start noticing problems and slowdowns, it's best to replace the devices as soon as possible.

When your friends face hard drive issues, share these simple steps to fix the disk issues easily. Got questions? Let us know on the comments section below.

:::author|103:::

No comments