checking bad sectors on hard drive

Issues related to applications and software problems
Post Reply
robertw
Posts: 174
Joined: 2012/04/25 13:26:59

checking bad sectors on hard drive

Post by robertw » 2018/02/09 13:40:14

hi all,

i have to check a hard drive as its producing bad superblock errors so a client was telling me so im now in the process of checking for bad sectors

im running this command -

fdisk -l

to get the list of all my hard drives in my system

~]# badblocks -v /dev/sdc > /badsectors.txt
Checking blocks 0 to 488386583
Checking for bad blocks (read-only test):

is this now checking for bad blocks on my hard drive, i see the hard drive led flashing but when i cat that file i see nothing in it

or maybe i need to press enter to start of the process?

cheers,

rob

tunk
Posts: 414
Joined: 2017/02/22 15:08:17

Re: checking bad sectors on hard drive

Post by tunk » 2018/02/09 13:55:08

If there's anything critical on the disk, I would first make a 1:1-copy with dd.
I've never used badblocks in read-only mode, but in write mode you get a line with elapsed time and %-completed.
smartctl -a /dev/sdc lists smart data, including pending and reallocated sectors.

User avatar
TrevorH
Forum Moderator
Posts: 23652
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: checking bad sectors on hard drive

Post by TrevorH » 2018/02/09 14:51:54

Important note: If the output of badblocks is going to be fed to the e2fsck or mke2fs programs, it is important that
the block size is properly specified, since the block numbers which are generated are very dependent on the block
size in use by the filesystem. For this reason, it is strongly recommended that users not run badblocks directly,
but rather use the -c option of the e2fsck and mke2fs programs.
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

Spork Schivago
Posts: 27
Joined: 2017/08/14 04:21:54

Re: checking bad sectors on hard drive

Post by Spork Schivago » 2018/02/09 15:48:01

robertw wrote:hi all,

i have to check a hard drive as its producing bad superblock errors so a client was telling me so im now in the process of checking for bad sectors

im running this command -

fdisk -l

to get the list of all my hard drives in my system

~]# badblocks -v /dev/sdc > /badsectors.txt
Checking blocks 0 to 488386583
Checking for bad blocks (read-only test):

is this now checking for bad blocks on my hard drive, i see the hard drive led flashing but when i cat that file i see nothing in it

or maybe i need to press enter to start of the process?

cheers,

rob
I'm with TrevorH. I'm curious as to why you're running badblocks instead of one of the fsck tools? Do you know what file system is being used? A long time ago (back in 2005), we had a server that had a power supply that died. We replaced it and when we turned it back on, we received an error message about a bad super block. It took me all night to figure out what happened. We almost lost all the data. It was an ext3 (I believe) file system and the journal had become corrupt. So, ext3 without a journal is just an ext2 partition. I discovered this on accident after running some commands and trying to mount the file system in a recovery environment. I didn't specify ext3, and it mounted just fine. I used mount to see that mount auto-detected it as an ext2 file system, and then realized what happened. I simply rebuilt the journal and we were back in business.

For what it's worth, if you do as trunk suggested and use dd to make a 1:1 copy, if there's any bad sectors, dd will fail. You'll know for certain at that point that the hard drive is failing, and a program such as ddrescue might of some use.

When I'm working on a hard drive that I suspect has bad sectors, I always copy the data off as soon as possible. I'll either use cp or ddrescue and do a simple pass, then try to get the more stubborn ones before the drive completely fails.

For badblocks, if you must run it, there's the -o output_file parameter, so you don't need to redirect output the way you're doing it. According to:

Code: Select all

man badblocks

       -o output_file
              Write the list of bad blocks to  the  specified  file.   Without
              this option, badblocks displays the list on its standard output.
              The format of this file is suitable for use by the -l option  in
              e2fsck(8) or mke2fs(8).

-- Niklaus Wirth's Law: software is getting slower more rapidly than hardware becomes faster.

Post Reply