起動ドライブ (NetBSD) の引っ越し その2

HDD の引越し作業はこんな手順で行おうと思っている。

  1. 新しい HDD を PC につなぐ。デバイスは wd2。
  2. fdisk(8) で MBR を初期化する。
  3. MBR にブートコードを書き込む
  4. disklabel(8) でパーティションを作成する。
  5. 各パーティションにファイルシステムを作成する。
  6. 古いシステムドライブの中身をコピーする。
  7. パーティションテーブルにブートコードを書き込む。

以下は作業の様子。

1. 新しい HDD を PC につなぐ

こんな感じで認識された。

wd2 at atabus1 drive 1
wd2: 
wd2: drive supports 16-sector PIO transfers, LBA48 addressing
wd2: 1863 GB, 3876021 cyl, 16 head, 63 sec, 512 bytes/sect x 3907029168 sectors
wd2: 32-bit data port
wd2: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 6 (Ultra/133)

2. fdisk(8) で MBR を初期化する

$ sudo fdisk -u wd2
Disk: /dev/rwd2d
NetBSD disklabel disk geometry:
cylinders: 3876021, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 3907029168

BIOS disk geometry:
cylinders: 1024, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 3907029168

Partitions aligned to 16065 sector boundaries, offset 63

Do you want to change our idea of what BIOS thinks? [n] n

Partition table:
0: 
1: 
2: 
3: 
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none] 0
The data for partition 0 is:

sysid: [0..255 default: 169]
start: [0..243201cyl default: 2048, 0cyl, 1MB]
size: [0..243201cyl default: 3907027120, 243201cyl, 1907728MB]
bootmenu: [] NetBSD

Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0-243201/80/63)
        PBR is not bootable: All bytes are identical (0x00)
1: 
2: 
3: 
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none] 

Installed bootfile doesn't support required options.
Update the bootcode from /usr/mdec/mbr_bootsel? [n] y

We haven't written the MBR back to disk yet.  This is your last chance.
Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0-243201/80/63)
        PBR is not bootable: All bytes are identical (0x00)
1: 
2: 
3: 
Bootselector enabled, timeout 10 seconds.
No active partition.
Should we write new partition table? [n] y

ん、オフセットは 63 じゃなくて 2048 なのか。

よくわからんが、最近は 2048 がデフォルトということのようだ。

3. MBR にブートコードを書き込む

2 の途中で MBR に /usr/mdec/mbr_bootsel が書き込むかどうか訊かれてたのでもう必要ない。

fdisk(8) の man によれば、次のようにして mbr_bootsel を書き込めるようだ。

fdisk -c /usr/mdec/mbr_bootsel /dev/rwd0d

ここでアクティパーティションも設定しておこう。

$ sudo fdisk -a wd2
Disk: /dev/rwd2d
NetBSD disklabel disk geometry:
cylinders: 3876021, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 3907029168

BIOS disk geometry:
cylinders: 1024, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 3907029168

Partitions aligned to 16065 sector boundaries, offset 63

Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0/32/33-243201/80/63)
1: 
2: 
3: 
Bootselector enabled, timeout 10 seconds.
No active partition.
Do you want to change the active partition? [n] y
Choosing 4 will make no partition active.
active partition: [0..4 default: 4] 0
Are you happy with this choice? [n] y

We haven't written the MBR back to disk yet.  This is your last chance.
Should we write new partition table? [n] y
$

4. disklabel(8) でパーティションを作成する

disklabel(8) で BSD パーティションを作成する。

用語が錯綜してわかりにくいが、FDISK のパーティションの中に BSD のパーティション構造が入るという入れ子構造だ。以前 FreeBSD 界隈では FDISK パーティションを「スライス」と読んで区別していたが、BSD と直接関係ない FDISK 関連のドキュメントを読むときには FDISK の方も単に「パーティション」と呼ばれるわけなので、FDISK パーティションに別名をついけたところで混乱が収まるわけでもないと思う。

何はともあれ、2 で作成した FDISK パーティション 0 の中に、BSD パーティション構造を作成するということだ。BSD 界隈では、「ディスクラベル」を作成する、と呼ばれる。この言い回しもわかりにくいような気がする。用いるツールは disklabel(8)。

$ sudo disklabel -i wd2
Enter '?' for help
partition> E
# /dev/rwd2d:
type: ESDI
disk: WDC WD20EFRX-68E
label: fictitious
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 3876021
total sectors: 3907029168
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

5 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 c: 3907027120      2048     unused      0     0        # (Cyl.      2*- 3876020)
 d: 3907029168         0     unused      0     0        # (Cyl.      0 - 3876020)
 e: 3907027120      2048     4.2BSD      0     0     0  # (Cyl.      2*- 3876020)
partition> a
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: 2048
Partition size ('$' for all remaining) [0c, 0s, 0M]: 4126720
 a:   4126720      2048     4.2BSD      0     0     0  # (Cyl.      2*-   4095)
partition> b
Filesystem type [?] [unused]: swap
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: a
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 b:  16515072   4128768       swap                     # (Cyl.   4096 -  20479)
partition> e
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: b
Partition size ('$' for all remaining) [0c, 0s, 0M]: 32768c
 e:  33030144  20643840     4.2BSD      0     0     0  # (Cyl.  20480 -  53247)
partition> f
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: e
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 f:  16515072  53673984     4.2BSD      0     0     0  # (Cyl.  53248 -  69631)
partition> g
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: f
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 g:  16515072  70189056     4.2BSD      0     0     0  # (Cyl.  69632 -  86015)
partition> h
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: g
Partition size ('$' for all remaining) [0c, 0s, 0M]: 32768c
 h:  33030144  86704128     4.2BSD      0     0     0  # (Cyl.  86016 - 118783)
partition> i
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: h
Partition size ('$' for all remaining) [0c, 0s, 0M]: 786432c
 i: 792723456 119734272     4.2BSD      0     0     0  # (Cyl. 118784 - 905215)
partition> j
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: i
Partition size ('$' for all remaining) [0c, 0s, 0M]: 131072c
 j: 132120576 912457728     4.2BSD      0     0     0  # (Cyl. 905216 - 1036287)
partition> k
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: j
Partition size ('$' for all remaining) [0c, 0s, 0M]: $
 k: 2862450864 1044578304     4.2BSD      0     0     0  # (Cyl. 1036288 - 3876020)
partition> P
11 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:   4126720      2048     4.2BSD      0     0     0  # (Cyl.      2*-   4095)
 b:  16515072   4128768       swap                     # (Cyl.   4096 -  20479)
 c: 3907027120      2048     unused      0     0        # (Cyl.      2*- 3876020)
 d: 3907029168         0     unused      0     0        # (Cyl.      0 - 3876020)
 e:  33030144  20643840     4.2BSD      0     0     0  # (Cyl.  20480 -  53247)
 f:  16515072  53673984     4.2BSD      0     0     0  # (Cyl.  53248 -  69631)
 g:  16515072  70189056     4.2BSD      0     0     0  # (Cyl.  69632 -  86015)
 h:  33030144  86704128     4.2BSD      0     0     0  # (Cyl.  86016 - 118783)
 i: 792723456 119734272     4.2BSD      0     0     0  # (Cyl. 118784 - 905215)
 j: 132120576 912457728     4.2BSD      0     0     0  # (Cyl. 905216 - 1036287)
 k: 2862450864 1044578304     4.2BSD      0     0     0  # (Cyl. 1036288 - 3876020)
partition> W
Label disk [n]? y
Label written
partition> Q

5. 各パーティションにファイルシステムを作成する

newfs(8) に -O2 をつけてファイルシステムを作成する。-O2 は FFSv2 を指定するオプション。

newfs -O2 /dev/rwd2a

容量が大きいので時間がかかるかと覚悟していたのだがずいぶん早く終わった。FFSv2 だから?

6. 古いシステムドライブの中身をコピーする

$ sudo mount /dev/wd2a /mnt
$ cd /mnt
$ sudo dump -0 -a -f - /  | sudo restore -rf -

7. パーティションテーブルにブートコードを書き込む

あらかじめ dumpfs でファイルシステムの形式を確認しておく。

$ sudo dumpfs /dev/rwd2a
file system: /dev/rwd2a
format  FFSv2
...

セカンダリブートストラップコード /usr/mdec/boot を /boot (今は /mnt にマウントしてるので /mnt/boot)にコピーする。

$ sudo cp /usr/mdec/boot /mnt/boot

プライマリブートストラップコード /usr/mdec/bootxx_ffsv2 (ファイルシステムが FFSv2 の場合) を installboot(8) を使って書き込む。

$ sudo installboot -v /dev/rwd2a /usr/mdec/bootxx_ffsv2
File system:         /dev/rwd2a
Primary bootstrap:   /usr/mdec/bootxx_ffsv2
Ignoring PBR with invalid magic in sector 0 of `/dev/rwd2a'
Boot options:        timeout 5, flags 0, speed 9600, ioaddr 0, console pc

初めて実行すると “Ignoring PBR with invalid magic …” のメッセージが出るが、2回目以降では出ない。