Daily Archives: February 16, 2018

Fix Hard Disk Bad Sectors in Linux

Bad Sector in a Hard Drive is a physical problem.  If bad sectors start appearing, it’s time to change the hard drive. Every OS has its own tools to scan and fix bad sectors. For example Windows has chkdsk application. Here we will discuss how to fix bad sectors in Linux.

  1. Download Ubuntu ISO and burn it on CD, DVD or a USB drive. If you have any other Linux live CD, that would also work.
  2. Boot system with the CD or USB created in step-1.
  3. Open a terminal window.
  4. Run command fdisk -l to find out the hard drive and partition device names.
  5. Type following command to run fix bad sectors application. Note: This command requires sudo privileges. Replace sda1 with the partition device name found in step-4.

            sudo e2fsck -cfpv /dev/sda1

The parameters have the following meanings: “c” searches for bad blocks and adds them to the list, “f” forces a check on the file system, “p” repairs anything that can be safely repaired and “v” is verbose mode so you can see the command progress.

This command can take a long time to run, even several hours on a particularly large drive.

Example:

ubuntu@ubuntu:~$ sudo fdisk -l
Disk /dev/loop0: 1.4 GiB, 1532116992 bytes, 2992416 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x032959e3

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1945352191 1945350144 927.6G 83 Linux
/dev/sda2 1945354238 1953523711 8169474 3.9G 5 Extended
/dev/sda5 1945354240 1953523711 8169472 3.9G 82 Linux swap / Solaris


Disk /dev/sdb: 28.7 GiB, 30752000000 bytes, 60062500 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x05160d8f

Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 60062499 60060452 28.7G c W95 FAT32 (LBA)


ubuntu@ubuntu:~$ sudo e2fsck -cfpv /dev/sda1
/dev/sda1: Updating bad block inode.

191888 inodes used (0.32%, out of 60792832)
 60 non-contiguous files (0.0%)
 194 non-contiguous directories (0.1%)
 # of inodes with ind/dind/tind blocks: 0/0/0
 Extent depth histogram: 144736/6
 4952754 blocks used (2.04%, out of 243168768)
 11 bad blocks
 1 large file

110870 regular files
 16787 directories
 55 character device files
 25 block device files
 0 fifos
 2 links
 64140 symbolic links (47056 fast symbolic links)
 2 sockets
------------
 191881 files
ubuntu@ubuntu:~$

Remove the live Linux CD or bootable USB and reboot the system.