Hard Drive Diagnostics in Linux

So this morning I had to deal with a server which has been consistently crashing once every week. Each crash indicated that there is something wrong with the file system – no I am not a programmer and nor am I about to spend a ton of time looking into the crash, for reasons I don’t want to get into here.

Anyway the OS that is being used is Fedora Core 2, which is no longer supported.  Now even though I think the OS is the problem I am going to scan the hard drive to make sure its working properly, if the drive isn’t function properly then this could be the root cause of the problem. So there are two great options for testing the hard drive. The first is SMART, luckily the hard drive is SMART capable. The second is badblocks, a program that is called E/2/3/4/fsprogs (you can download the program from sourceforge if it is not installed).

If you do not know what type of hard drive you have in your system you can run the following command:

fdisk -l

Because the hard drive in this server is SMART compatible I can run the following command which will output drive information for a particular drive: (PLEASE NOTE THAT THIS EXAMPLE WAS PERFORMED ON A RED HAT BASED SYSTEM)

smartctl -a /dev/HDD_DEVICE

This command will run a LONG test of your hard drive:

smartctl -t long /dev/HDD_DEVICE

Now to view the status of your test run this command(please note that the time it takes to test your hard drive will very depending on the capacity):

smartctl -l selftest /dev/HDD_DEVICE

If you don’t have a SMART capable hard drive you can use the E/2/3/4/fsprogs to check your hard drive. By running the following command you will initiate a scan of the hard drive:

badblocks -n -v /dev/HDD_DEVICE

Here is what I would run if I were you:

badblocks -n /dev/HDD_DEVICE -o outputfile &

This will output any bad blocks to the outputfile (you name it whatever you want) and the “&” runs the program in the background. For more information on E/2/3/4/fsprogs click the link!

Alternatively you can also use GOOGLE to help solve your problems! I also used this wonderful site to help me with hardware diagnostics.

Leave a Reply

Your email address will not be published. Required fields are marked *