にせデュアルブートFreeBSD

某商用製品の真似をして、/と/usrが二つあってどちらからも起動できるFreeBSDを作る。

1.インストール
4つのスライスを作る。
1番目はレスキュー領域
2番目は/と/usrその1
3番目は/と/usrその2 2番目と全く同じ大きさにする
4番目はその他の領域、/home /tmp /var swap
インストールは2番目と4番目を使用
1番目と3番目のスライスは切るだけで現時点では触らず
FreeBSD BootMgrをインストール


2.レスキュー領域にインストール
何かを適当にインストール


3.3番目のスライスにラベル付け
2番目のスライスのコピーなので、2番目のスライスのラベルをバックアップしてそのま3番目のスライスに書き込む
この辺を参照。
http://www.jp.freebsd.org/cgi/mroff.cgi?sect=8&cmd=&lc=1&subdir=man&dir=jpman-6.4.2%2Fman&subdir=man&man=bsdlabel

# bsdlabel ad4s2
# /dev/ad4s2:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 16777216 0 4.2BSD 0 0 0
c: 33554304 0 unused 0 0 # "raw" part, don't edit
d: 16777088 16777216 4.2BSD 0 0 0

# bsdlabel ad4s2 > ad4s2.txt
# bsdlabel -R ad4s3 ad2s2.txt



4.三番目のスライスにファイルシステム作成
mkfsではなくnewfsを使う。
http://www.jp.freebsd.org/cgi/mroff.cgi?subdir=man&lc=1&cmd=&man=newfs&dir=jpman-5.4.0%2Fman§=0

# newfs /dev/ad4s3a
/dev/ad4s3a: 8192.0MB (16777216 sectors) block size 16384, fragment size 2048
using 45 cylinder groups of 183.72MB, 11758 blks, 23552 inodes.
super-block backups (for fsck -b #) at:
160, 376416, 752672, 1128928, 1505184, 1881440, 2257696, 2633952, 3010208,
3386464, 3762720, 4138976, 4515232, 4891488, 5267744, 5644000, 6020256,
6396512, 6772768, 7149024, 7525280, 7901536, 8277792, 8654048, 9030304,
9406560, 9782816, 10159072, 10535328, 10911584, 11287840, 11664096, 12040352,
12416608, 12792864, 13169120, 13545376, 13921632, 14297888, 14674144,
15050400, 15426656, 15802912, 16179168, 16555424

# newfs -U /dev/ad4s3d
/dev/ad4s3d: 8191.9MB (16777088 sectors) block size 16384, fragment size 2048
using 45 cylinder groups of 183.72MB, 11758 blks, 23552 inodes.
with soft updates
super-block backups (for fsck -b #) at:
160, 376416, 752672, 1128928, 1505184, 1881440, 2257696, 2633952, 3010208,
3386464, 3762720, 4138976, 4515232, 4891488, 5267744, 5644000, 6020256,
6396512, 6772768, 7149024, 7525280, 7901536, 8277792, 8654048, 9030304,
9406560, 9782816, 10159072, 10535328, 10911584, 11287840, 11664096, 12040352,
12416608, 12792864, 13169120, 13545376, 13921632, 14297888, 14674144,
15050400, 15426656, 15802912, 16179168, 16555424

5.作成したファイルシステムに現在稼働中の/と/usrをバックアップ
ここを参照
http://www.jp.freebsd.org/QandA/HTML/1859.html
ただし、通常稼働中のファイルシステムをバックアップするには-Lオプションが必要なので追加する。

# mount /dev/ad4s3a /mnt
# dump -L0af - / | ( cd /mnt && restore rf - )
DUMP: Date of this level 0 dump: Wed Jun 22 00:15:28 2011
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping snapshot of /dev/ad4s2a (/) to standard output
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 275698 tape blocks.
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
warning: ./.snap: File exists
expected next file 94209, got 10
DUMP: DUMP: 275575 tape blocks
DUMP: finished in 21 seconds, throughput 13122 KBytes/sec
DUMP: DUMP IS DONE

# umount /mnt
# mount /dev/ad4s3d /mnt
# dump -L0af - /usr | ( cd /mnt && restore rf - )
DUMP: Date of this level 0 dump: Wed Jun 22 00:18:13 2011
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping snapshot of /dev/ad4s2d (/usr) to standard output
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 3856608 tape blocks.
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
warning: ./.snap: File exists
expected next file 23653, got 3428
DUMP: 73.11% done, finished in 0:01 at Wed Jun 22 00:25:04 2011
DUMP: 88.27% done, finished in 0:01 at Wed Jun 22 00:29:33 2011
DUMP: DUMP: 3857611 tape blocks
DUMP: finished in 829 seconds, throughput 4653 KBytes/sec
DUMP: DUMP IS DONE



6.3番目のスライスのfstab書き換え
マウントして適当に書き換え


7.3番目のスライスから起動
再起動し、ブートマネージャにてF3を押し3番目のスライスから起動


8.二度目以降のバックアップ
二回目以降は4.以降を繰り返し。
手間なのでスクリプト化したい。