All the devices that we use are sure to fail one day; however, to prevent ourselves from the potential losses that are associated with these failures, we should try our levels best to keep monitoring these devices for their health and immediately taking any action if we find any anomalous behavior. The hard disks that we use with our computer systems also fail now and then due to several reasons. One such reason is the presence of bad sectors in our hard disk.

The major problem with these bad sectors is that we cannot remove them altogether from our hard disk for getting rid of them. The maximum we can do is to stop our operating system from using these bad sectors for putting our data on them. Therefore, in this article, we will walk you through the method of checking hard disk for errors and preventing our OS from writing data on the bad sectors using Linux Mint 20.

Method of Checking Disk for Errors in Linux Mint 20:

For checking your disk for errors in Linux Mint 20, you will need to perform the following steps:

  • We will be checking the hard disk for errors via the command line in Linux Mint 20. Therefore, we will first launch the terminal by clicking on the terminal icon located on the taskbar or pressing Ctrl Alt T keyboard shortcut. The newly launched terminal window is shown in the image below:

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

  • Now you need to know about your hard disk partitions so that you can identify the portion that you want to check for errors. For doing that, type the following command in your terminal and then press the Enter key:

This command requires root privileges to run. That is why we have used the “sudo” keyword before it. It is also shown in the following image:

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

  • The output of this command will show you all the partitions of your hard disk. We want to check the portion highlighted in the image shown below for errors using Linux Mint 20. Here, /dev/sda is the portion of the disk that we want to examine. In your case, this portion might have a different name.

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

  • Once you manage to identify the portion of the hard disk that you want to check for errors, the next step is to look for all the bad sectors in the identified portion and listing them down in a text file. For doing that, you need to type the following command in your terminal and then press the Enter key:

sudo badblocks –v /dev/sda > /scan_result/badsectors.txt

Here, the badblocks command also requires root privileges to execute and it will scan the specified portion of the hard disk (/dev/sda in this case) for any bad sectors, and if it finds any, it will list them down in the file named badsectors.txt which will be placed in the scan_result directory. Here, you should replace /dev/sda with the exact name of the hard disk portion that you want to scan for bad sectors. This command is also shown in the following image:

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

  • Once this command is executed successfully, all the bad sectors will be stored in the badsectors.txt file. Now, our goal is to convey this message to our Linux Mint 20 that it should not be using the bad sectors mentioned in the badsectors.txt file in any way. For doing that, you will need to type the following command in your terminal and then press the Enter key:

sudo fsck –l /scan_result/badsectors.txt /dev/sda

The fsck command also requires root privileges to run. This command will prevent our Linux Mint 20 to use the sectors listed in the badsectors.txt file while working with the /dev/sda partition. This command is also shown in the image below:

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

Conclusion:

By following the method described in this article, we can easily aggregate all the bad sectors together in a text file. We can prevent our operating system from using these bad sectors for writing our precious data. In this way, we can not only prevent our data from corruption or loss, but we can also use a hard disk with bad sectors for our routine tasks without any difficulty.

About the author

Check Disk for Errors Linux Mint 20 Disk Management Linux Mint Monitoring

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.