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
Kiran Kumar
Hi there! I'm Kiran Kumar, founder of I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities, especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. I hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!


  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

  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



Please enter your comment!
Please enter your name here




Basics of Working with the SQLite Database in Python

A database is one of the most useful and popular files for storing data; they can be used to store any kind of data, including text, numbers, images, binary data, files, etc. SQLite is a relational database management system based on the SQL language. It is a C library, and it provides an API to work with other programming languages, including Python. It does not require a separate server process to be run as needed in large database engines like MySQL and Postgresql.

5 Ways to Check the Linux Version

When most people talk of Linux, they are always referring to a Linux distribution. However, this is not the case. Linux itself is a kernel which acts as a bridge between user applications and the hardware. When we talk of a Linux distribution, we refer to an operating system developed from the Linux kernel. A distribution comes with a package manager, pre-installed applications, a Desktop Environment, and several more features.

Getting Started with Linux Operating System

The Linux operating system brings forth a vibrant mix of features and security, making it the best alternative to macOS or Windows operating systems. In this post, we will give you a master guide on Getting started with Linux systems - taking you from a complete beginner to a level where you can begin testing the various Linux distributions available with much ease.

How to Create a Comprehensive Mail Server on Ubuntu

Postal is a free and open-source mail server used to send and receive emails. It comes loaded with tons of excellent features and functionalities, making it extremely popular among large organizations as well as in enterprise settings.

The 10 Best Linux Performance Monitoring Tools

Do you want to monitor the performance of your Linux system? Are you looking for some powerful performance monitoring tools to help you out? If you agree, it's your day as we have put together a detailed list of the ten best Linux performance monitoring tools.

How to Boot your Windows or Linux PC from a USB Drive

Sometime back, the process of installing an operating system required users to pop a bootable media disk into their DVD or CD drive and use it to boot the PC. But times have changed. Nowadays, the most common way of installing an OS is booting from a USB drive. The use of USB drives is further propelled by the current production of slim and lightweight laptops with no support for DVD/CD drives.


Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

6 Essential Command-Line Utilities Every Linux User Should Know

Last week, we shared with you several "cool and fun" commands to get comfortable and confident with the Linux command-line. In our quest to further aid Linux users with mastery of the command line, or CLI, we present you with a variety of command-line utilities essential for all Linux users, regardless of proficiency level.

7 Best Ways to Kill Unresponsive Programs in Linux

For dealing with a frozen app or desktop, you can't use the CTRL+ALT+DEL in Linux system. Instead, there are powerful alternatives that come in handy in frustrating situations. We pick the best methods available for you.

Top 10 Reasons to use Xfce as your Desktop Environment

There are many choices for desktop environments for Linux based operating systems. Mainly, you can install any DE of your choice on most of the Linux based distributions, even if they are not offered as a package officially. In our recent articles, we discussed the best of KDE and Cinnamon. In this article, we wish to present to you the top reasons why you should consider Xfce as your desktop environment.

Top 10 reasons to use KDE as your Desktop Environment

In this article, we will take a look at yet another popular desktop environment, KDE. It's one of the most amazing Linux Desktop environments available in the market.