It is better to be discussing about bad sector fixing, First of all need to understand about bad sectors. Bad Sector is the space of Hard Disk which an Operating Systems is not able to access , and can’t use because of permanent damage in hard disk. If the bad sector continues to accumulate then it can affect your hard disk drive or even worse.
Step-1 : Check your hard disk Information using fdisk command
[root@techbrown ~]# fdisk -l
Step-2 : Perform Hard Drive scanning for Bad Sectors
For this Use badblocks command, badblocks command is the command which is used to perform scanning or testing of hard drive or external drives to find bad sectors.badblocks is the utility in linux based operating system.
Using badblocks command users can detect all the bad sectors present in hard drives, and save them to the text files (which is created by user). So the user can use this with e2fsck using this user can configure operating systems to not store the data in damaged sectors.
[root@techbrown ~]# badblocks -v /dev/sdb > /techbrown-badsectors.txt
Note: Replace /dev/sdb with your partition or hard disk.
When we run these badblocks command automatically a “techbrown-badsectors” text files will be created. after this command this files contain all bad sectors.
Step-3 : Download the Ubuntu 20.04 ISO image
Download and burn Ubuntu 20.04 LTS ISO image to a DVD or make a pendrive bootable using it. If already having another system or live CD (ISO file) which can access the hard drive, you may skip this step.
Step-4 : Restart the computer
Restart the computer and boot from the DVD or alternate system.
Strep-5 : Open the terminal window
Press Ctrl+Alt+T This will launch the Terminal
Step-6 : Select noted badblocks hard drive or disk with e2fsck
e2fsck command is the command used for check the file system like ext2 ext3 and ext4. and the fsck tool check the error in the file system and repair it.
[root@techbrown ~]# e2fsck -cfpv /dev/sda4
In this command replace “sda4” with your actually noted badblocks device name. This can be done as entire drive as well as partition such as sda is entire drive or sda1 is a partition.
Here these are the options are given below
- c = Searches the badblocks and add them to the list.
- f = File system seems clean still option f forces a check up on file system.
- p = Repairs anything that can be safely repaired
- v = Verbose Using this, user can see the command progress.
The command e2fsck take a long time to run depends on the size of hard drive. It takes several hours take so keep patients during the command run.
Step-7 : Exit the Terminal
Exit the terminal after the command ‘e2fsck’ is finished.
Step-8 : Remove the Ubuntu 20.04 DVD OR unmount the bootable Pendrive
If any and reboot the system. After reboot your file system is up to date with the bad sectors and will avoid them. you can check the file system any repairable issue have been fixed.
That’s all for now.