badblocks

USBメモリではおさまらない程度のテンポラリ領域が必要になったので、ジャンク箱から2.5inch4Gドライブを掘り出して使うことにした。そのまま使うは心配なので、出来る検査は最初にやっておきたい。3.5-2.5アダプタが見当たらないので、UBCDを使った検査ができない。しかたがないので、USBアダプタに接続して、badblockコマンドでやることにした。
スピンアップの音は特に問題なさそうなので、ドライブはたぶん生きているものと思われる。
ドライブはこれ。

scsi0 : SCSI emulation for USB Mass Storage devices
Vendor: HITACHI_ Model: DK238A-43 Rev: 0811
Type: Direct-Access ANSI SCSI revision: 02

とりあえず、リードだけテスト。4Gとはいえ、時間はかかる。

# badblocks -v /dev/sda
Checking blocks 0 to 4226040
Checking for bad blocks (read-only test): 2647680/ 4226040

テストはこんな感じで進む。不良ブロックが見付かれば、ブロックナンバがリストされる。-o オプションで不良ブロックをファイルに書きだし、それをfsckに渡し不良ブロックを使わないようにすることができる。
でも、IDEだとコマンドの挙動はどうなるのかな。エラーになった時点で代替処理かブロック無効化が自動で行われて、容量が減るだけかな? それをやるには、ちゃんとしたIDEコマンドを出さないとダメだったっけ。だいぶ長いことUBCDに頼りっきりなので、すっかり忘れてら...

# badblocks -v /dev/sda
Checking blocks 0 to 4226040
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found.

書き込みのテストもやる時にはこんな風。これをやるとディスク上のデータは消えてしまうので要注意。それに4種類のパターンで全面ライトとリードを行うので時間もかなりかかる。この4Gだと小一時間くらい。

# badblocks -v -w /dev/sda
Checking for bad blocks in read-write mode
From block 0 to 4226040
Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: done
Testing with pattern 0x00: done
Reading and comparing: done
Pass completed, 0 bad blocks found.

運用中のドライブで不良ブロックのエラーが出てきた場合は、fsckの-cオプションで不良ブロックリストをを作ってそこを使用しないようにすることもできるけど、一度そうなったドライブは、どんどん状況が悪化していくので単価の安くなった現在ではドライブ交換を行うほうがリスクが少なく効率的だ。

# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sda: 4327 MB, 4327464960 bytes
134 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 8308 * 512 = 4253696 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1017, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1017, default 1017):
Using default value 1017

Command (m for help): p

Disk /dev/sda: 4327 MB, 4327464960 bytes
134 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 8308 * 512 = 4253696 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 1017 4224587 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

# mkfs.ext3 /dev/sda1
mke2fs 1.37 (21-Mar-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
529056 inodes, 1056146 blocks
52807 blocks (5.00%) reserved for the super user
First data block=0
33 block groups
32768 blocks per group, 32768 fragments per group
16032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

# mount /dev/sda1 /mnt/
# cp -a /backup/portableHDD /mnt/
# sync
# umount /mnt/

作業終了。
同時に発掘された違う容量のもう1台では、不良ブロックが見付かった。

# badblocks -v -w /dev/sda
Checking for bad blocks in read-write mode
From block 0 to 4226040
Testing with pattern 0xaa: done
Reading and comparing: 3375744
done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: done
Testing with pattern 0x00: done
Reading and comparing: done
Pass completed, 1 bad blocks found.

二順目から出ていないということは、そこで代替処理が行われたと見るべきか、それとも、たまたまRWが不安定なセクタやタイミングであったと考えるべきか。
微妙だな...
この後、readのみをもう一度やってみたが、不良ブロックは出てこなかった。しかし、ライトテストをやったら、もっと手前の違うところでまた出た。こいつは常用には無理があるようだ。
仕方ないので、3台目。これはダメっぽい。磁石取ってステ。
んで、今4台目作業中。