磁盘扇区故障,坏块处理

/var/log/messages ,我看到其中一块scsi硬盘有问题:

scsi0: ERROR on channel 0, id 1, lun 0, CDB: Read (10) 00 03 74 5c 9d 00 01 00 00
Info fld=0x3745cc1, Current sda: sense key Medium Error
Additional sense: Unrecovered read error
end_request: I/O error, dev sda, sector 57957533
scsi0: ERROR on channel 0, id 1, lun 0, CDB: Read (10) 00 03 74 5c bd 00 00 08 00
Info fld=0x3745cc1, Current sda: sense key Medium Error
Additional sense: Unrecovered read error
end_request: I/O error, dev sda, sector 57957568
scsi0: ERROR on channel 0, id 1, lun 0, CDB: Read (10) 00 03 74 5c bd 00 00 08 00
Info fld=0x3745cc1, Current sda: sense key Medium Error
Additional sense: Unrecovered read error - recommend reassignment
end_request: I/O error, dev sda, sector 57957568

 

I)首先,我们必须知道上面显示的逻辑扇区在哪一个分区上:

[root@server ~]# fdisk -lu /dev/sda

Disk /dev/sda: 36.7 GB, 36778545152 bytes
255 heads, 63 sectors/track, 4471 cylinders, total 71833096 sectors
Units = settori of 1 * 512 = 512 bytes

Dispositivo Boot  Start        End    Blocks  Id  System
/dev/sda1    *       63     208844    104391  83  Linux
/dev/sda2        208845   12498569   6144862+ 83  Linux
/dev/sda3        12498570 15647309   1574370  82  Linux swap
/dev/sda4        15647310 71826614  28089652+  5  Esteso
/dev/sda5        15647373 71826614  28089621  83  Linux

 

II)两个坏的扇区都在 /dev/sda5,因此现在我们必须知道:

*文件系统块(block)的大小

*哪一个文件系统块包含这个逻辑块地址(LBA)

1)我们可以用tune2fs

[root@server ~]# tune2fs -l /dev/sda5 | grep Block
Block count: 7022405
Block size: 4096
Blocks per group: 32768

2) 计算规则是 b = (int)((L-S)*512/B)

>>> (57957568-15647373)*512/4096
5288774L

>>> (57957533-15647373)*512/4096
5288770L

III) 现在我们可以用debugfs 来定位被存储在这个块(block)上的节点以及包含这个节点的文件:

[root@server ~]# debugfs
debugfs 1.35 (28-Feb-2004)
debugfs: open /dev/sda5
debugfs: icheck 5288770
Block Inode number
5288770 2518362
debugfs: ncheck 2518362
Inode Pathname
2518362 /thema/cont/easythe/filesok/dbeucoge/keymov.ISD
debugfs: icheck 5288774
Block Inode number
5288774 2518362
debugfs: ncheck 2518362
Inode Pathname
2518362 /thema/cont/easythe/filesok/dbeucoge/keymov.ISD
debugfs: close

IV) 为了强制使硬盘从新指派这个坏的块(block),我们将这个坏的块(block)清零,并且同步(sync)硬盘:

root]# dd if=/dev/zero of=/dev/sda5 bs=4096 count=1 seek=5288770
root]# dd if=/dev/zero of=/dev/sda5 bs=4096 count=1 seek=5288774
root]# sync

注意:最后一步已永久并且是不可恢复的(irretreviably)摧毁该此文件中的数据除非你已经确定不需要文件或可以新的或正确的版本取代它,否则不要做这个操作。

现在一切都恢复正常:扇区已经被从新指派!

本文转载自这里。

你可能感兴趣的:(磁盘扇区故障,坏块处理)