起動用ディスクイメージの作成
リリースの作成が完了しましたら、起動用のディスクイメージを作成します。(pkgsrcにsysutils/mkmemstick)とかあるみたいですが、以下の手順を簡略できるかどうかはわかりません。)
前準備
前準備としてはvnd(4)が使用できる状態であることを確認してください。vnd(4)はvnode disk driveでファイルをディスクデバイスとして扱うためのドライバーです。以下のコマンドをエラーなく実行できることを確認してください。
# usr/sbin/vnconfig -l vnd0: not in use vnd1: not in use vnd2: not in use vnd3: not in use #
ディスクイメージの作成
vnd(4)でアクセスするディスクイメージのファイルを以下の手順で作成します。ディスクイメージは今回の目的には32Mバイトもあれば足りるので、以下のようにして空の32Mバイトのファイルを作成します。
# dd if=/dev/zero of=disk.img bs=1m count=32 32+0 records in 32+0 records out 33554432 bytes transferred in 0.434 secs (77314359 bytes/sec)
次に、vnd0を構成します。
# vnconfig -c vnd0 /var/tmp/disk.img #
FDISKパーティションの作成
ここからは新しいディスクを準備するときの一般的な手順になりますが、まずFDISKパーティションを作成します。(NetBSDの場合はFDISKパーティションを作成せずに行えますし、むしろ手間は少ないのですが、今回は安全策を取って一般的なPCの構成に合わせて行いました。)
# fdisk -aui vnd0 fdisk: primary partition table invalid, no magic in sector 0 fdisk: Cannot determine the number of heads Disk: /dev/rvnd0d NetBSD disklabel disk geometry: cylinders: 32, heads: 64, sectors/track: 32 (2048 sectors/cylinder) total sectors: 65536 BIOS disk geometry: cylinders: 32, heads: 64, sectors/track: 32 (2048 sectors/cylinder) total sectors: 65536 Partitions aligned to 2048 sector boundaries, offset 32 Do you want to change our idea of what BIOS thinks? [n] Partition table: 0: <UNUSED> 1: <UNUSED> 2: <UNUSED> 3: <UNUSED> Bootselector disabled. No active partition. Which partition do you want to change?: [none] 0 The data for partition 0 is: <UNUSED> sysid: [0..255 default: 169] start: [0..32cyl default: 32, 0cyl, 0MB] 32 size: [0..32cyl default: 65504, 32cyl, 32MB] bootmenu: [] Partition table: 0: NetBSD (sysid 169) start 32, size 65504 (32 MB, Cyls 0-31) PBR is not bootable: All bytes are identical (0x00) 1: <UNUSED> 2: <UNUSED> 3: <UNUSED> Bootselector disabled. No active partition. Which partition do you want to change?: [none] 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 Update the bootcode from /usr/mdec/mbr? [n] y We haven't written the MBR back to disk yet. This is your last chance. Partition table: 0: NetBSD (sysid 169) start 32, size 65504 (32 MB, Cyls 0-31), Active PBR is not bootable: All bytes are identical (0x00) 1: <UNUSED> 2: <UNUSED> 3: <UNUSED> Bootselector disabled. First active partition: 0 Should we write new partition table? [n] y #
以上でfdisk(8)を実行して対話的にvnd0を操作しています。
- 最初のパーティション0をNetBSDのパーティションID 169で作成
- パーティションの開始は先頭から32セクタ(1トラック分)のオフセット
- サイズは残り全体
- 起動メニューは使用しないので空のまま
- アクティブパーティション(起動パーティション)を0に設定
- 標準のMBR(Master Boot Record)のブートコードを/use/mdec/mbrから書き込み
設定したFDISKパーティションをオプションなしのfdisk(8)で確認します。
# fdisk vnd0 Disk: /dev/rvnd0d NetBSD disklabel disk geometry: cylinders: 32, heads: 64, sectors/track: 32 (2048 sectors/cylinder) total sectors: 65536 BIOS disk geometry: cylinders: 32, heads: 64, sectors/track: 32 (2048 sectors/cylinder) total sectors: 65536 Partitions aligned to 2048 sector boundaries, offset 32 Partition table: 0: NetBSD (sysid 169) start 32, size 65504 (32 MB, Cyls 0-31), Active PBR is not bootable: All bytes are identical (0x00) 1: <UNUSED> 2: <UNUSED> 3: <UNUSED> Bootselector disabled. First active partition: 0 #
ディスクラベルの作成
次にディスクラベルを作成します。ディスクにディスクラベルが存在しない場合、カーネル(ディスクのドライバー)は架空の、といってもサイズは実際のディスクの大きさに合わせたディスクラベルをカーネル内に生成します。これを使うことでカーネルはディスクラベルがないにも関わらず、ディスク全体を表すdパーティション(amd64やi386のportの場合)にアクセスできるわけです。
ところが、fdisk(8)でFDISKパーティション構成を変更していますが、カーネル内の架空のディスクラベルは変更する前となっています。これを簡単に辻褄を合わせるために、ここでは一旦vnd0の構成を解除して、再び設定します。
# vnconfig -u vnd0 # vnconfig -c vnd0 /var/tmp/disk.img #
そして、disklabel(8)を対話的に起動してディスクラベルの作成と書き込みを行います。
# disklabel -iIr vnd0 Enter '?' for help partition> P 5 partitions: # size offset fstype [fsize bsize cpg/sgs] c: 65504 32 unused 0 0 # (Cyl. 0*- 31) d: 65536 0 unused 0 0 # (Cyl. 0 - 31) e: 65504 32 4.2BSD 0 0 0 # (Cyl. 0*- 31) partition> a Filesystem type [?] [unused]: 4.2BSD Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: 32 Partition size ('$' for all remaining) [0c, 0s, 0M]: $ a: 65504 32 4.2BSD 0 0 0 # (Cyl. 0*- 31) partition> e Filesystem type [?] [4.2BSD]: unused Start offset ('x' to start after partition 'x') [0.015625c, 32s, 0.015625M]: 0 Partition size ('$' for all remaining) [31.984375c, 65504s, 31.984375M]: 0 partition> P 5 partitions: # size offset fstype [fsize bsize cpg/sgs] a: 65504 32 4.2BSD 0 0 0 # (Cyl. 0*- 31) c: 65504 32 unused 0 0 # (Cyl. 0*- 31) d: 65536 0 unused 0 0 # (Cyl. 0 - 31) partition> W Label disk [n]? y Label written partition> Q #
ここでは以下の処理を行っています。
- disklabel(8)を対話的に、初期のディスクラベルの作成、カーネル内のディスクラベルの情報を無視して起動
- Pで現在の状態を確認
- aを入力してaパーティションをeパーティションと同じ内容で作成
- eを入力してeパーティションを解除
- 改めてPで現在の状態を確認
- Wでラベルを書き込み、確認を求めてくるのでyと入力
- Qでdisklabel(8)を終了
後は必須ではありませんが、気分の問題としてディスクラベルの他の情報を変更しています。
# disklabel -e vnd0 ...
通常はエディターのvi(1)が起動しますので、そこで以下のように直しています
- label: を fictitious から disk1 のような適当な文字列に変更
- rpm: を 3600 から 7200 に変更
最後にオプションなしのdisklabel(1)で設定したディスクラベルの状態を確認しておきます。
# disklabel vnd0 ...(中略)... 5 partitions: # size offset fstype [fsize bsize cpg/sgs] a: 65504 32 4.2BSD 0 0 0 # (Cyl. 0*- 31) c: 65504 32 unused 0 0 # (Cyl. 0*- 31) d: 65536 0 unused 0 0 # (Cyl. 0 - 31) #
ファイルシステムの作成とマウント
ファイルシステムの作成とマウントを行います。
# newfs -O2 /dev/rvnd0a /dev/rvnd0a: 32.0MB (65504 sectors) block size 8192, fragment size 1024 using 4 cylinder groups of 8.00MB, 1024 blks, 1920 inodes. super-block backups (for fsck_ffs -b #) at: 144, 16528, 32912, 49296, # mount /dev/vnd0a /mnt # df -k /mnt Filesystem 1K-blocks Used Avail %Cap Mounted on /dev/vnd0a 30695 1 29160 0% /mnt #
これで以下の処理を行っています。
- vnd0aにFFSv2でファイルシステムを作成
- /dev/vnd0a を /mnt にマウント
- df(1)でマウントされている状態を確認
必要なファイルのコピー
作成したファイルシステムに必要なファイルをコピーします。
# cp -p /data/release/amd64/binary/kernel/netbsd-INSTALL.gz /mnt/netbsd # cd /usr/mdec # cp -p boot /mnt # cp /usr/src/etc/etc.amd64/boot.cfg /mnt #
これで以下の処理を行っています。
- (内部にインストール用ramdiskイメージを含んだ)インストール用カーネルをコピー
- ブートプログラムbootをコピー
- boot(8)の設定ファイルboot.cfgをコピー
NetBSDのboot(8)は圧縮したままのカーネルも読めるので、そのままのコピーで済ませています。
ブートローダーの書き込み
installboot(8)を使用して、先に書き込んだbootを読み込むためのブートコードを書き込みます。
# installboot /dev/rvnd0a bootxx_ffsv2 #
起動設定
boot(8)に対する設定ファイルを編集して、以下のような内容とします。
# vi /mnt/boot.cfg ... # cat /mnt/boot.cfg menu=Boot normally:boot netbsd -1 menu=Boot single user:boot netbsd -1s menu=Disable ACPI and SMP:boot netbsd -12 menu=Drop to boot prompt:prompt default=1 timeout=20 #
ポイントは2つです。
- カーネルのオプションに -1 を加えてシングルプロセッサーで動作する様にしています。
- timeoutの値を長めに取って、VPSの仮想マシンを起動してからカーネルが起動するまでに十分な時間を確保しています。
後始末
最後にファイルシステムをアンマウントして、vnd0の構成を解除します。
# umount /mnt # vnconfig -u vnd0 #
これで /var/tmp/disk.img として必要なディスクイメージのファイルを作成できました。