Check hard disk for Bad Sectors by command-line in Ubuntu, Linux Mint, and elementary OS

Hard disk failures are just a thing that’s bound to happen to every computer. But, time of complete failure is something that you should estimate based on the scan results. Presence of bad sectors is the beginning of the end of a hard disk drive. Bad sectors are hardware related and can’t be fixed. You can only monitor it and make your OS to not use the bad sectors for writing data.

In this session of Terminal Tuts, let’s learn how to find out the presence of bad sectors and errors in your computer’s hard disk. We had already published the GUI method of finding SMART status and errors using ‘Disks’ utility – just FYI.

Scan for Bad Sectors and Errors on the hard disk in Ubuntu, Linux Mint, and elementary OS

Note that if you want to scan your computer’s internal hard disk which is mounted, you should be using an Ubuntu Live USB drive and boot into it. Then launch ‘Terminal’ from the Live environment and follow these steps. If you are checking an external hard disk, you need to see that it is not mounted.

Step 1: First, let’s use the fdisk command to find out the hard disk partitions status.

sudo fdisk -l
fdisk command output
fdisk command output

You should see a few entries of RAM. For example,  Disk /dev/ram15 seen in my test PC. You can ignore it as this is the RAM disk driver used by main system memory as a block device.

In the above screen-shot example, /dev/sda is the hard disk of size 465.8 GB that I’m interested in scanning.

Step 2: Next, let’s find if there are any Bad Sectors on the hard disk. We shall use badblocks command. Make sure to enter your hard disk info instead of /dev/sda in below command. My test PC has /dev/sda for the hard disk. This command will scan for bad blocks in the hard disk and then export the result to the file badsectors.txt in the ‘scan_result’ directory.

sudo badblocks -v /dev/sda > /scan_result/badsectors.txt

Step 3: Finally we shall use fsck command to tell Ubuntu not to use the bad sectors mentioned in the badsectors.txt file. That way life of the hard disk is increased a bit until you get a new one for replacement.

sudo fsck -l /scan_result/badsectors.txt /dev/sda

Related Articles


  1. how long did it take to scan your 465.8 GB drive? step 2 from start to finish.

    I started it on a 1.5Tb external drive and it ran for over 30 minutes (without any clue how long was left), so killed it. Can we run it with the ‘-s’ option (to show progress bar)?, if so, does it give a good indication of progress?

    • Sorry, I don’t remember how long it took, but generally badblocks command is not the fastest. It takes several days sometimes to even complete a 1TB hard disk. 30 minutes is too short in your case. You can use -s to show progress bar. The command format for it: badblocks -s device. All the best!

      • I ran the badblocks test on my 1.5TB external usb drive with the -s switch. It gives % complete and time elapsed (in seconds). Once it hit 1% I looked at the time elapsed. It said 138 seconds, so I multiplied this by 100 = 138000, then divided by 60 (to get minutes), again divided by 60 (to get hours) = 3.8 hours.

        Left it running this time. It actually took around 4 hours to complete. So with the -s switch you can get an idea/estimate (early on in the process) how long it will take to complete.

        Here’s my output:

        test@test:~$ sudo badblocks -v -s /dev/sdc > ~/testbadblocks-ext-hdd.txt
        Checking blocks 0 to 1465105407
        Checking for bad blocks (read-only test): 0.00% done, 0:00 elapsed. (0/0/0 errdone
        Pass completed, 0 bad blocks found. (0/0/0 errors)

        The process was pretty resource hungry. Don’t know if running it in the background/low priority will make it less resource intensive. (probably take longer to complete) Something to ponder.

        • 138 seconds is just over 2 minutes… I don’t know what kind of maths you applied but if the elapsed time said 138 seconds that means that it took 2 minutes and 18 seconds to reach a progress of 1%.

  2. Hello Sir,
    I cannot access my hard drive partitions on my Ubuntu OS. I have a 500Gb Hard disk size which is not accessible or rather even visible with the Ubuntu OS. Any suggestions?

  3. Dear Kiran, Thank you for this article. it’s really helpful. there’s only one problem (maybe 2) . When I run the fsck command, I receive the following error messages:
    fsck: the -l option can be used with one device only — ignore
    e2fsck: need terminal for interactive repairs
    any idea what can be done about them?

  4. Hi there, just a question. If my hard drive shows 0 bad sectors, should i tell Ubuntu the output file or it is not necessary?
    Best regards,

  5. Hello, I have a new laptop with a new SSD hard disk and I don’t have ‘SDA’ name for my hard disk partition. Since new SSDs are using NVMe drivers the name of partitions comes such as “nvme0n1p1”. I cannot use these kinds of names with smart or any other application so far. Disks program also does not give me anything because the “self-test” button is inactive.

    Do you know how can I get information about the health of my hard disk with NVMe drivers?

    • Dear Mustafa,

      SSDs do not need to be checked for bad sectors. They are not mechanical drives. If they start to fail it is because of flash memory’s limited rewrite potential. A SSD that is failing has run it’s usable lifespan, and needs to be replaced immedeately. Perhaps SSDs of the future will use memory technologies with indefinite rewrites. But until then it’s best to replace them about every 5 years, before they show signs of failure.

  6. Dear Kiram,

    Thank your for sharing this information. I would suggest you to use:

    sudo badblocks -vs /dev/sda > /scan_result/badsectors.txt

    because it takes some time to finish the task and “-vs” (specially the “s”) give you a update of the task completed.

  7. christophe@christophe-ESPRIMO-E5731:~$ sudo badblocks -v /dev/sdb1 > /scan_result/badsectors.txt
    bash: /scan_result/badsectors.txt: No such file or directory

      • the ‘ > /scan_result/badsectors.txt ‘ part means “write the results to this file”. You’re getting that error because the directory /scan_result does not exist, so use a different directory, like ~/Desktop/badsectors.txt or something

  8. If you get :
    badblocks: Value too large for defined data type invalid end block (7814026240): must be 32-bit value

    Then add -b 4096
    sudo badblocks -b 4096 -vs /dev/sdb > ~/Desktop/badsectors.txt


  9. fsck from util-linux 2.34
    fsck: the -l option can be used with one device only — ignore
    e2fsck: need terminal for interactive repairs

Leave a Reply to QuikMaths Cancel reply

Please enter your comment!
Please enter your name here


More Articles Like This