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:
- 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:
- 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.
- 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:
- 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:
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.