badsectコマンド萌え

FreeBSDにも、Windowsでいうところのchkdiskまたはscandiskに相当するコマンドがあった。それがbadsectコマンド。ただ、簡単に使える代物ではない。次のような儀式で、不良セクタをファイルに変換して封じ込める。
まずは、fdiskでハードディスクのプロパティを調査。

# fdisk
******* Working on device /dev/ad0 *******
parameters extracted from in-core disklabel are:
cylinders=35152 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=35152 heads=16 sectors/track=63 (1008 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 35433153 (17301 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 15/ sector 63
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>

ここで、63 + 35433153 = 35433216 で、次のddコマンドを実行するためのパラメータを計算。そして、こんな感じで実行。これは相当時間がかかるけれど、ひたすら我慢。

# dd if=/dev/ad0s1d of=/dev/null count=35433216 conv=sync,noerror
dd: /dev/ad0s1d: Input/output error
12450830+0 records in
12450830+0 records out
6374824960 bytes transferred in 4096.515440 secs (1556158 bytes/sec)
dd: /dev/ad0s1d: Input/output error
dd: /dev/ad0s1d: Input/output error
12451154+0 records in
12451154+0 records out
6374990848 bytes transferred in 4102.444891 secs (1553949 bytes/sec)
dd: /dev/ad0s1d: Input/output error
dd: /dev/ad0s1d: Input/output error
12451478+0 records in
12451478+0 records out
6375156736 bytes transferred in 4108.605407 secs (1551660 bytes/sec)
(途中略)
dd: /dev/ad0s1d: Input/output error
16777205+0 records in
16777205+0 records out
8589928960 bytes transferred in 5573.389691 secs (1541240 bytes/sec)

この結果を受けて、やっとこbadsectを実行。ちなみにデバイスディレクトリの関係は、/dev/ad0s1d が /var。

# cd /var
# mkdir BAD
# badsect BAD 12450830 12451154 12451478 (途中略)
# fsck /dev/ad0s1d

これで今度こそ直ったかなぁ。
badsectで固めた不良セクタは、こんな感じ。ただ、朝と今のサイズが違っているような気がする。しかもオーナーは絶対違う。

# ls -l
total 34
-rw-r--r--  1 fml  fml  2223 Nov 11  2005 12450830
-rw-r--r--  1 fml  fml  1899 Nov 11  2005 12451154
-rw-r--r--  1 fml  fml  1972 Nov 11  2005 12451478
-rw-r--r--  1 fml  fml  3410 Nov 11  2005 12795229
-rw-r--r--  1 fml  fml  2088 Nov 11  2005 12926519
-rw-r--r--  1 fml  fml  2062 Nov 11  2005 12986973
-rw-r--r--  1 fml  fml  1878 Nov 11  2005 13124739
-rw-r--r--  1 fml  fml  3343 Nov 11  2005 13134873
-rw-r--r--  1 fml  fml  1856 Nov 11  2005 13364615
-rw-r--r--  1 fml  fml  2054 Nov 11  2005 16777205
-rw-r--r--  1 fml  fml  1662 Nov 11  2005 16777206