Operating System - Linux
1829748 Members
4015 Online
109992 Solutions
New Discussion

how to check hard disk for bad sectors under linux ?

 
SOLVED
Go to solution
'chris'
Super Advisor

how to check hard disk for bad sectors under linux ?

hi

how to check hard disk for bad sectors under linux ?
I use linux SuSE 8.2 and Ext3 file system.

kind regards
chris
11 REPLIES 11
Alexander Chuzhoy
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

try
first umount the disk partition

then
e2fsck -c umounted partition

Mark Grant
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

Have a look at the "badblocks" command. The man page describes everything useful.
Never preceed any demonstration with anything more predictive than "watch this"
Jerome Henry
Honored Contributor
Solution

Re: how to check hard disk for bad sectors under linux ?

You can also :
shutdown -rF now
forces checking on reboot.
Ext3 is a problem on checking, as partition is always considered as consistent because of the journal. It's a good idea to proceed to the file checking from time to time at boot time.
You can set it with tune2fs :
tune2fs -c 12 -i 25 /dev/hda3
for example : this will force file checking every 12 boots, or every 25 days (first delay) on hda3. It's a good idea to use it, my experience (and many others' undoubtedly !) shows that with journalisation, it's often too late when you realize that consitency is not there anymore !

hth

J
You can lean only on what resists you...
Mark Grant
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

Jerome,

I was under the impression that this does not check for bad areas on the disk, it only checks for inconsistancies in the filesystem itself. Am I wrong?
Never preceed any demonstration with anything more predictive than "watch this"
'chris'
Super Advisor

Re: how to check hard disk for bad sectors under linux ?

hi Jerome

I've forgotten: my /boot is on Ext2 file system and rest on Ext3

# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/hda3 ext3 41286828 7017948 32171596 18% /
/dev/hda1 ext2 46636 6008 38220 14% /boot
/dev/hda4 ext3 35364880 1866420 31701992 6% /usr
shmfs shm 386252 0 386252 0% /dev/shm


can I use this command

tune2fs -c 12 -i 25 /dev/hda

for the whole disk an all partitions ?

greetings
chris
Jerome Henry
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

Ooops ! Yes, you are right Mark !
Even if both problems are related, the right command is undoubtedly here badblocks -nsv /dev/hda1 n to make non destructive tests, s to tell you which blocks are tested (be careful : slooows the process), and v to tell you if everything goes right.

Obviously 0 here chris...

J
You can lean only on what resists you...
Jerome Henry
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

Chris,

As /boot is ext2, it shouldn't have this problem, as it should be checked.
you still can use tune2fs to tune checking intervals. But the command applies to each partition, so you have to enter it for each.
Entering it today with the same values will make checking occur the same day, but you can't use /dev/hda with it.


J
You can lean only on what resists you...
'chris'
Super Advisor

Re: how to check hard disk for bad sectors under linux ?

thanks for answers !

that means badblocks test is looking for bad sectors also ?

what's different exactly between blocks and sectors ?

Jerome Henry
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

The sector is the physical space your HD maker thought was necessary to write 512 bytes (4096 bits, so 4096 different information). It depends on your HD speed, head sensitivity, and so on.
From that, each operating system groups sectors in order to simplify disk administration (if your average file size is 3.5 ko, it would be faster to administrate 4.0 ko as the minimum unit to describe a file, instead of administrating 7 sectors to describe the same file. That's why most OSes group sectors in blocks. It looses some space, as in ths example I loose 0.5 ko for the file, but it goes in this example 8 time faster than administrating each sector).
On doing fdisk /dev/hda, you'll be able to check disk block size :
For example :
[root@localhost etc]# fdisk -l /dev/hda

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes

Périphérique Amorce Début Fin Blocs Id Système
/dev/hda1 * 1 382 3068383+ 7 HPFS/NTFS
/dev/hda2 383 1148 6152895 7 HPFS/NTFS
/dev/hda3 1149 1786 5124735 c Win95 FAT32 (LBA)
/dev/hda4 1787 4864 24724035 5 Etendue
/dev/hda5 1787 2296 4096543+ 83 Linux
/dev/hda6 2297 2678 3068383+ 83 Linux
/dev/hda7 2679 2805 1020096 82 Echange Linux
/dev/hda8 2806 2901 771088+ 83 Linux
/dev/hda9 2902 4481 12691318+ 83 Linux
/dev/hda10 4482 4863 3068383+ 83 Linux

The block size is :
Units = cylindres of 16065 * 512 = 8225280 bytes. The block size is units / 1024, here 8132.5, which is odd, I know. Sorry. Most of the time it is 1024 bytes, 2048, 4096 or 81
You can lean only on what resists you...
'chris'
Super Advisor

Re: how to check hard disk for bad sectors under linux ?

thanks !

but is it any difference between
blocks and sectors ?
Stuart Browne
Honored Contributor

Re: how to check hard disk for bad sectors under linux ?

The first line of Jerome's post stated what a sector is. A block is a file-system (read: logical) representation of how to arrange data on a disk.

There isn't necessarily any direct correlation between a sector and a block. When you start talking RAID array's, this becomes very clear.
One long-haired git at your service...