in

Linux PC acting up? How to check for bad blocks on a hard drive – before it’s too late

synthetick / Getty Images

I’ve had it happen before. Back when drives consisted of spinning, magnetic platters, that dreaded “tick” was a sure sign a hard drive was failing. Once upon a nightmare scenario, I waited too late and wound up losing everything on my drive. Sure, I could have recovered that data, but at a pretty high monetary cost.

Also: The first 5 Linux commands every new user should learn

Since then, I’ve always been vigilant about checking for bad blocks and sectors on hard drives.

What is a bad block?

Simply put, a bad block is one that cannot be read or written to. This can happen because of physical damage to the drive or failing transistors on flash memory (think SSDs). When a block goes bad, it’s not usable. Too many bad blocks, and the drive will fail.

You don’t want that.

Also: Thinking about switching to Linux? 10 things you need to know

Before the bad blocks take you down, you should check for them. If you don’t, you could lose out. Let’s check.

<!–>

How to check for bad blocks on an older drive

What you’ll need: The only things you’ll need for this are a running instance of Linux and a user with sudo privileges.

–>

The first thing to do is locate the name of your drive and partition. To do that, you’ll need to use the fdisk utility with the command:

Show more

sudo fdisk -l

From the output of that, you should see the name of the drive you need to scan. The name will most likely be in the form of /dev/sda1.

Now it’s time to scan for those blocks. The tool you’ll use for this is aptly named badblocks and is installed on most Linux distributions (so you don’t have to install anything). Let’s say your drive name is /dev/sda1. To scan for bad blocks, the command would be:

Show more

sudo badblocks -v /dev/sda1 > badblocks.txt

The above command outputs the results of the command to the file badblocks.txt. You’ll also see the output of the command in the terminal window.

Also: There’s a new coolest Linux distribution ready to wow you

If badblocks report that there are, in fact, bad blocks on your drive, you’ll want to mark them as unusable. If your OS attempts to use a bad block or sector, it could cause problems, and this avoids that.

Also: The best Linux distros for beginners

To do that, we’ll employ the file created by badblocks and use the e2fsck command. This only works on the ext2, ext3, and ext4 filesystem types. The command used for this (sticking with the example name we’ve been using) would be:

Show more

sudo e2fsck -l badblocks.txt /dev/sda1

If your file system is of a different type, you’ll use the fsck command like so:

sudo fsck -l badblocks.txt /dev/sda1

How to check for bad blocks on a modern drive

The good news is that you don’t have to mark bad blocks on an SSD, but it’s good to regularly check the health of the drive.

If your system uses an SSD, you’ll need to use a tool called smartmontools. Chances are that this application isn’t installed on your system.

1. Install smartmontools

To install smartmontools on a Debian/Ubuntu-based distribution, issue the command:

sudo apt-get install smartmontools -y

Also: 6 reasons why I’ve stuck with Ubuntu-based Linux distros for the last 20 years

On Fedora-based distributions, that command would be:

sudo dnf install smartmontools -y

2. Run a health check

Now that smartmontools has been installed, run a health check with the command:

sudo smartctl -H /dev/sda1

And there you go. You now have either marked those blocks as bad, or you know the general health of your SSD.

Also: 10 Linux apps I install on every new machine (and why you should, too)

Get the morning’s top stories in your inbox each day with our Tech Today newsletter.

–>


Source: Information Technologies - zdnet.com

Google is using passkeys and new security tools to help you fight cyberattacks – here’s how

5 preinstalled apps you should delete from your Samsung phone immediately