In today’s article, we’re going to learn how to check a disk for errors. We’ll be using a multi-pronged process to thoroughly check a disk for errors in the Linux terminal. By itself, none of these are particularly complicated. As such, I expect this to be a relatively easy article to follow.
If you’ve been seeing errors when transferring data to a disk, it’s probably a good sign that it’s time to check that disk for errors. You may also want to check a disk for errors if you’ve not used it before – like if it is used or if you have just purchased it.
To perform these tests, the disk must not be mounted! If need be, you’ll have to do these tests from a live environment. That’s easy enough. Remember how you installed Linux? Well, that same installation media is (usually) the same media you’ll need to enter a live environment. You will, of course, need to boot to the media when you start your system – be it USB, or CD, or DVD. It’s much the same as though you were going to install Linux – except you don’t opt to do the installation – you just work in the live environment.
Anyhow, we’ll be using a few tools for this. All of these tools will almost certainly be available by default. If they’re not, ummm… Well, if they’re not, pick a different distro’s live environment to use, or install them yourself! These tools are all on the installation media for distros in the Ubuntu family, for example. So, yeah, find a distro where they are available – which should be pretty much all of them.
Check A Disk For Errors:
So, you’re booted to a live instance of your favorite distro (or the disk you’re going to check is unmounted) and you’re ready to start testing. Well, you need an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press
Once you have your terminal open, use
lsblk to identify the disk you wish to check for errors. For the purposes of this exercise, we’re going to assume the disk you’re checking for errors is known as ‘sda’. Be sure to change that to suit your particular needs.
First, let’s check for S.M.A.R.T. errors (which we’ve previously covered in-depth). You can do so with this command:
sudo smartctl -H /dev/sda
Next, let’s check for bad blocks. Bad blocks are physical points on your device that no longer work properly. Some bad blocks isn’t, necessarily, indicative of immediate disk failure. Some bad blocks may be normal. Still, let’s check it.
If you’re really into this, you’ll want to check it for bad blocks – and then check it again soon after. That will let you know if the number of bad blocks is increasing. If the number is rapidly increasing, disk failure will likely soon follow. Otherwise, you’re probably okay for the time being.
sudo badblocks -v /dev/sda
Finally, let’s check for file-system consistency. This is typically done with the ‘fsck’ command, a command you should have some understanding of. There are many ways to run the command, but you can just use the following command to see what’s going on:
sudo fsck /dev/sda
Now, you’ve run three tests. Between them all, you should have a pretty good understanding of your disk’s health and you’ll know how to check a disk for errors. Again, you’ll want to check a disk for errors when the situation dictates – especially if you’re getting disk errors while in the operating system.
When you get disk errors, it’s time to consider retiring the drive. Depending on the severity of the errors, you might wish to stop using the drive immediately, creating an image of the drive, and retiring the drive from your system. Disk failures happen and recovering data from a failed drive can be a major hassle. So, use these warnings as a reason to consider replacing your drives if drive failure is in the cards.
And there you have it! You now know how to check a disk for errors! It’s a handy skill to have. After all, disks fail. Knowing when they are going to fail is a good thing. Being prepared for disk failure is a bonus and a good idea! It’s also worth checking new disks. I’ve tested new disks and had unsatisfactory results that meant I returned the disk to the retailer, so it’s a concern and worth taking the time to test.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.