Fix bad sectors on linux

How to Fix Bad Sectors on Linux

We’re here to talk about how to fix bad sectors on Linux and keep your hard disk in good shape. Read on to find out more!

Bad sectors are the most annoying problem for an end-user. Every operating system has specific tools called system software to fix the bad sectors. For instance, Microsoft Windows has a utility called chkdsk that can be used to check disks for errors. Note that having a bad sector is a physical problem, and the usual solution is to mark them and avoid writing in the future. 

One of the ways to check for bad sectors is to boot the system with some other drive and then scan your drive for bad sectors. If an external drive is not available, you can also boot the system in single-user mode. 

There is a tool called e2fsck in Linux that can be used to check the file system and then use badblocks to check the drive. This article will discuss in detail the e2fsck command and its various options. In addition, a step-by-step procedure is provided to scan your system for errors and fix them.

How to Fix Bad Sectors on Linux?

Before we get to the meat of it, you might want to understand what a bad sector means, and how it can adversely affect the system. Finally, we will take a look at the multiple ways to fix this issue on Linux OS

What are bad sectors?

Hard disk stores data in the form of sectors. A collection of sectors form a track, and a collection of tracks form clusters. Bad sectors are those sectors of the disk that have been corrupted or damaged, and you can’t store data on those sectors. 

There can be multiple reasons for bad sectors, such as power failure, disk damage, age of a disk, etc. Despite a sector being corrupted, the operating system may consider them as normal and attempt to write to those sectors. This can lead to data loss. Therefore, those sectors must be marked such that the operating system avoids writing to these sectors. 

Tip: One should scan their drives regularly to eliminate issues with a system, such as slow read/ write, data loss, etc.

e2fsck command

The command scans your drive for errors. There are several options available with this command. The flag c searches for bad sectors and adds to a list, f checks for the file system, the p option attempts to repair any error (if possible), and v is the verbose mode.

Now, we will discuss the basic steps to fix bad sectors in a system.

Prepare a Bootable DVD

First, you need to have Ubuntu burned into a DVD. Make sure that you have another drive that has Linux or Ubuntu installed, and that can access your hard drive to be checked for bad sectors.

Restart the system

Now, restart your system and boot from the DVD. The particular step to enable boot drive from Basic Input Output System (BIOS) depends on your specific computer.

Open Terminal

Now, open a terminal. In Ubuntu, go to the start menu and select terminal. Alternatively, right-click on the desktop and select the terminal.

Noting down partition information

In the next step, we will note down the partition information. Run the following command:

$fdisk -1

This will display your hard drives available along with the partition information. Take note of the partition information for the particular drive you want to scan for bad sectors. The command will display a great deal of information, such as the physical devices connected along with the logical drives, with /dev/loop being virtual devices. You will also see /dev/sda and /dev/sdb as physical devices.

Alternatively, you can run the following command to note down the partition information:

$sudo lsblk -o name,mountpoint,label,size,uuid

Scan the drive

In the next step, we will scan the disk for errors. Type the following command to scan your drive:

$sudo e2fsck -cfpv /dev/sdal

This will check your device /dev/sda1 for errors.

Exit the terminal

Once the command e2fsck is finished, exit the terminal. You can type the following command or close the window interactively:


Reboot the system

Remove the DVD drive and reboot your system. Your system is up-to-date with bad sectors marked. So, they are not be used in the future by the system. If any error could be fixed, these issues would have been resolved.

Tip: The e2fsck command may take a long time, around hours, to complete. This depends upon the particular drive you want to scan for.

Using badblocks to scan for bad sectors

One can also use badblocks command to scan for bad sectors. Make sure to use the verbose flag (-v) so that the output can be analyzed later. The following command illustrates how we can use badblocks to scan for the bad sectors and save the file in results.txt

$sudo badblocks -v /dev/sdb1 > /home/user1/results.txt

The output of the badblocks command can also be passed to the e2fsck command to repair the errors logged in the file. The following command illustrates that:

$sudo e2fsck -1 results.txt /dev/sdb1

Bad sectors are a common problem that every computer user often faces. To avoid data loss and system performance issues, periodically scan your system for the bad sectors and fix those issues. We also discussed how to use the e2fsck command to scan your system for bad sectors and fix those issues. For more details about the command, you can also refer to the Linux manual.

If this guide helped you, please share it.

Leave a Reply
Related Posts