• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Data Recovery Pit

The Data Recovery Expert

  • Best
  • Guides
  • Reviews
Home / Guides

June 3, 2022 Pramesh Khanna

How to Recover Bad Sectors in Ubuntu

Bad Sectors on Ubuntu

No matter the operating system you run, the reasons for developing a bad sector on your hard disk are similar. Bad sectors are small areas of your hard drive that have become damaged or corrupted. When you try to access data on a bad sector, it can cause your computer to freeze, crash, or even fail to boot up. It’s possible to use a data recovery tool to recover data from bad sectors on Ubuntu only if you are lucky. However, in most cases, once a bad sector has formed, on Ubuntu or otherwise, it is permanent, and you can’t repair it.

Therefore, if your information is stored in those hard drive sectors, it’s extremely tough to get it back. Luckily, Linux has terminal utilities that may aid in the management of hard drive’s bad sectors. You may use these commands to scan and label them as unusable. If you suspect that something is wrong with your hard drive, it is important to back up your data as soon as possible. Once a bad sector forms, it will only worsen over time and eventually lead to complete data loss.

Table of Contents

  • Possible Causes of Bad Sectors on a Disk
  • 1. Preparing to Manage Bad Sectors in Linux
  • 2. Scanning for Bad Sectors on Ubuntu
  • 3. Recover Bad Sectors in Ubuntu

Possible Causes of Bad Sectors on a Disk

The most common cause is the wear and tear from daily HDD use. Over time, magnetic materials that store your data can degrade and eventually stop working altogether. In other cases, bad sectors can be caused by a hardware failure, such as a dropped hard drive or a power surge. Further, in some rare cases, a software issue can also be the reason for developing one, such as a virus or malware infection.

1. Preparing to Manage Bad Sectors in Linux

It’s good to run the following commands while your disk isn’t mounted with the operating system. As a result, you should try this using a LIVE operating system boot from a USB stick. You can create a LIVE USB for Ubuntu OS, but this is not mandatory. Even if you are using an active Linux distribution, you can still execute these commands. However, you should not scan or mark the mounted “/” root filesystem.

2. Scanning for Bad Sectors on Ubuntu

First, identify the disk partition you wish to scan for bad sectors. If you have GParted, a free app that can assist with partition recovery on Ubuntu, use it. Otherwise, run the following command to view your disk partitions.

sudo lsblk –o name,mountpoint,label,size,uuid

If you’re using the LIVE USB method, make sure your HDD and USB stick are identifiable. The most common “/dev/sda” should be used for an HDD.

Then, run the badblocks command with the verbose (-v) option to check whether you have any bad sectors on your hard drive. Save the output to a text file for further inspection. This is only a test to see if your hard drive has any damaged sectors.

sudo badblocks –v /dev/sda1 > ~/bad_sectors.txt

3. Recover Bad Sectors in Ubuntu

You can use the e2fsck command to check and repair damaged sectors on ext2, ext3, and ext4 file systems. To check and repair your files, access the command line with administrator privilege and run the command below.

sudo e2fsck -cfpv /dev/sda1

If you’re using a USB drive, update the device identifier on sda1 with your device’s actual identifier. The parameters “c” and “f” check for corrupted blocks and add them to a list. If anything can be fixed, the “p” parameter does so, while the “v” verbose option displays the terminal output of the operation as it goes. The “bad_sectors.txt” file created in the earlier steps can also be used to force e2fsck to repair only the file’s bad sectors via the following command.

sudo e2fsck -l bad_sectors.txt /dev/sda1

If you are using a FAT32 file system, use fsck:

sudo fsck -l bad_sectors.txt /dev/sda1

However, depending on the size of your disk partition and the condition of your disk, executing the command may take several hours to repair all bad sectors. Try not to cut off the process through CTRL+C or CTRL+Z while running.

Ubuntu

Next Article
How to Edit and Recover the Ubuntu Hosts File
How to Restore a Windows Server

Primary Sidebar

Author

Pramesh Khanna

Pramesh is a tech expert, written more than 500 data recovery articles for different publications. His experience in a computer shop where he was in charge of recovering files from hard drives introduced him to the world of data recovery.


LinkedInTwitter
Related Posts

Footer

data-recovery-pit-logo
Info
  • About
  • Privacy Policy
  • Terms and Conditions
  • Contact Us
Site
  • Sitemap
  • Services
  • Advertise
  • Disclaimer
  • Facebook
  • Twitter
  • Pinterest

Copyright © 2025 · Data Recovery Pit

This site uses cookies to serve you better. By continuing to use this website, you agree to our cookie and Privacy Policy.