NetBSD 5.0以降ではamd64環境(x86_64)でのXen Domain-0およびDomain-Uがサポートされる。 ここではNetBSD/amd64を基本環境としてXen Domain-0(64bit)環境およびそこからNetBSD/amd64(64bit)およびNetBSD/i386(32bit)の両方のDomain-Uを稼働させることを目標とする。
基本的に従来の方法とほとんど同じだが、NetBSD(i386/amd64)のブートローダの改良によりNetBSD 4.xまでより簡単になっている。
まずは必要な物を揃える。
誤解されている事が非常に多いが64bit用XenでもCPUが64bitに対応していさえすれば、ParaVirtualizationはIntel VT-xやAMD-Vと呼ばれる仮想化支援命令を持たないCPUでも問題なく動作する。つまり今時のCeleronや多くの国産NotePCのようにCore2DuoであってもIntel VT-xをBIOSで無効にしてあり変更できないものでも動くはず。動作しないのはhvmと呼ばれる完全仮想化であり、専用のParaVirtualization用kernelを持っているOSを動作させるだけであれば全く必要ない。
参考までにここで例として使っている環境は以下のような物である。見ての通り、64bit対応のCeleronなのでIntel VT-xはサポートされていない。
CPU | Intel Celeron D 336 2.8GHz (LGA775) |
---|---|
Memory | 2GByte |
ChipSet | Intel 865G |
HDD | 60GB EIDE Seagate ST360021A |
インストールメディアはCDでもいいし、Internet環境でもいい。5.0はまだリリースさていないが、snapshotや自身で作成したイメージを使う。ここでは自分で作成したNetBSD/amd64 5.0_BETAのイメージを使用している。
pkgsrcはNetBSDのftpサイトからtar ballで取得したり、cvsで取得したりできる。とりあえず新しめの方が良い。ここではpkgsrcのcurrentのものを使った。なお、binary packageで取得できるものもいくつかあるが、時期の問題もあるのでここでは必要な物は全てpkgsrcからmakeする。
必要な物が揃ったら、まずは普通にNetBSDをインストールする。ここでは先に述べたとおり、NetBSD/amd64を普通にインストールする。
ここでは60GBのHDを全て/の1パーティションとし、他にswapのみを作成する。他のOSとの共存はとりあえず全く考えない。
インストール前にハードウェアの時計はUTCに合わせて置いた方が後々悩まずに済むので、BIOSの時計は世界標準時にしておく。
NetBSD/amd64のBoot CDから起動し、メニューに答えていく。面倒なのでインストールする配布セットは全部入れる。X環境も最低限ライブラリが 必要になる。
インストールが終わったら再起動させる。
再起動後に、いくつかOSの初期設定を行う。基本的には好みで行えばいいが、最低限以下。
ユーザはuseraddコマンドで作成しておけば良い。rootで作業のために/etc/groupのwheelユーザに追加しておく。passwdで初期パスワードを作成しておくのも忘れずに。
他の設定の多くは/etc/rc.confファイルに設定する。とりあえず今回は以下を追加した。
hostname="amd64v" ifconfig_fxp0="dhcp" dhcpcd_flags="fxp0" sshd=YES
これ以外に、XenのDomain-U用にネットワークブリッジの設定をしておく。これは以下の内容の/etc/ifconfig.bridge0を作成する。
create !brconfig bridge0 add fxp0 up
fxp0の部分は実際に自分が使うハードウェアに合わせて名前を変更する(例えばwm0とかbge0とか色々)
設定が終わったら一旦rebootしておく。
インストールメディアから次のファイルを取得する。
amd64/binary/kernel/netbsd-XEN3_DOM0.gz
これを展開し、/に置く。例えばCDからなら以下のように実行する。
# mount -t cd9660 /dev/cd0a /mnt # cp /mnt/amd64/binary/kernel/netbsd-XEN3_DOM0.gz /tmp # gzip -d /tmp/netbsd-XEN3_DOM0.gz # cp /tmp/netbsd-XEN3_DOM0 /
/usr/pkgsrcにpkgsrcを展開する。
# cd /tmp # ftp ftp://ftp.netbsd.org/pub/NetBSD/packages/current-src/pkgsrc.tar.gz # tar zxf pkgsrc.tar.gz -C /usr
pkgsrcからsysutils/xenkernel33をmake installする。
# cd /usr/pkgsrc/sysutils/xenkernel33 # make install
xen kernelは/usr/pkg/xen3-kernelにインストールされる。今回は全部1パーティションなのでそのままでよいが、複数パーティションに分けている場合は、ルートパーティションにコピーしておく。 なお、xen kernelはgzip圧縮されているがそのままで問題ない。
pkgsrcからsysutils/xentools33をmake installする。
# cd /usr/pkgsrc/sysutils/xentools33 # make install
xen kernelは通常のNetBSD kernelよりも先にロードされなければならない。従来はこのためにgrubが必要だったが、NetBSD 5.0以降ではmulti-boot機能が追加されたため、標準のboot loaderで設定するだけでよい。 boot.cfg(5)にもあるように設定内容は/boot.cfgを以下のように編集する。
menu=Boot normally:boot netbsd menu=Boot single user:boot netbsd -s menu=Boot Xen with 512MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=512M menu=Boot Xen with dom0 in single-user mode:load /netbsd-XEN3_DOM0 -s;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=512M menu=Drop to boot prompt:prompt default=1 timeout=5
ここではDomain-0にメモリを512MB割り当てている。もちろん実際の実メモリに合わせてこの大きさは変更することができる。 また、上記では標準で通常のNetBSDが、キー入力で3を選ぶとXen環境が起動するようになっている。標準をXen環境にする場合はdefaultを3にするとか、メニュー項目そのものを変更すれば良い。
boot.cfgの設定まで終わったら、xen kernelを起動する。
# shutdown -r now
画面上はbootメニューが起動する。ここで3の[Boot Xen with 512MB for dom0]を選択すればxen kernelが起動し、続いてNetBSDの起動メッセージが画面上に流れる。
無事にlogin:プロンプトが出力されたら、今後はDomain-0上の作業に移る。
ここでうまく起動できなければ、PCをリセットし、1の[Boot normally]を選択して起動する。これは従来通りGENERICカーネルのamd64であるため、ここでファイルの設定を見直す。
これ以降の作業は基本的に従来のi386用xenと同じである。
うまく起動したら次にxen関係のdaemonを起動するよう/etc/rc.confに以下を追加する。
xend=YES xenbackendd=YES
また、起動スクリプトを/etc/rc.dにコピーする。
# cp /usr/pkg/share/examples/rc.d/{xend,xenbackendd} /etc/rc.d
システム全体を再起動してもいいが、次のように直接起動もできる。
/etc/rc.d/xend start /etc/rc.d/xenbackendd start
これらは仮に非Xen環境で起動した場合にはdaemon自体は起動に失敗するが、システム的には害を与えない。
うまくdaemonまで起動していれば次のように状態を見られる。
# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 512 1 r----- 20.0
これは1つだけのDomain-0が起動していることを意味している。
ここからはDomain-Uと呼ばれる複数のOSを同時に動かすための設定になる。まずは64bit用のNetBSD/amd64 Domain-Uをインストールする。
NetBSD/amd64のインストールメディアから以下のファイルを取り出す。
amd64/binary/kernel/netbsd-XEN3_DOMU.gz amd64/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz
これを適当なディレクトリに置く。
# mount -t cd9660 /dev/cd0a /mnt # cp /mnt/amd64/binary/kernel/netbsd-XEN3_DOMU.gz /xendata/netbsd64/ # cp /mnt/amd64/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz /xendata/netbsd64/ # gzip -d /xendata/netbsd64/netbsd-XEN3_DOMU.gz # gzip -d /xendata/netbsd64/netbsd-INSTALL_XEN3_DOMU.gz
Domain-Uのインストール先となる領域をここではファイルとして作成する。
# dd if=/dev/zero of=/xendata/netbsd64/netbsd64.img bs=1m count=4096
これで4Gのファイルができる。seekを指定して部分だけを作っても良いかもしれないが、ここでは明示的に作った。部分だけだと、どうも後述のsysinstでdisklabelがかけなかったりする場合があるような気がする。
Domain-U用の設定ファイルをDomain-0上で作成する。普通のテキストファイルで最低限以下の行があればいい。 ここでは/usr/pkg/etc/xen/netbsd64を作成する。
# kernel = "/xendata/netbsd64/netbsd-INSTALL_XEN3_DOMU" memory = 256 name = "NetBSD64_DOMU" vif = [ 'mac=00:16:3e:00:01:15,bridge=bridge0' ] disk = [ 'file:/xendata/netbsd64/netbsd64.img,0,w']
用意できたら実際にDomain-Uを起動する。
# xm create -c /usr/pkg/etc/xen/netbsd64
うまく行けば見慣れたNetBSDのインストーラ(sysinst)画面が出現する。
あとは普通にインストールするだけ。
Domain-0上でDomain-U用設定ファイルを以下のように変更する。
# kernel = "/xendata/netbsd64/netbsd-XEN3_DOMU" memory = 256 name = "NetBSD_DOMU" vif = [ 'mac=00:16:3e:00:01:15,brdige=bridge0' ] disk = [ 'file:/xendata/netbsd64/netbsd64.img,0,w'] root = "xbd0"
要はkernelをインストールカーネルから通常のカーネルに切り替えるだけ。rootの設定はmultiboot環境用に起動先を設定するもの。
これで起動すると、普通のNetBSD/amd64とほとんど同じNetBSDが起動する。以下は最低限の設定を行った後の起動メッセージ
# xm create -c /usr/pkg/etc/xen/netbsd64 Using config file "/usr/pkg/etc/xen/netbsd64". Loaded initial symtab at 0xffffffff80658464, strtab at 0xffffffff806a4b78, # entries 12954 Started domain NetBSD64_DOMU Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 5.0_BETA (XEN3_DOMU) #0: Thu Dec 18 22:26:25 JST 2008 oshima@sweety:/export/netbsd-5/obj/amd64/export/netbsd-5/src/sys/arch/amd64/compile/XEN3_DOMU total memory = 256 MB avail memory = 239 MB mainbus0 (root) hypervisor0 at mainbus0: Xen version 3.3 vcpu0 at hypervisor0: Intel 686-class, 2800MHz, id 0xf49 xenbus0 at hypervisor0: Xen Virtual Bus Interface xencons0 at hypervisor0: Xen Virtual Console Driver xencons0: using event channel 2 xbd0 at xenbus0 id 0: Xen Virtual Block Device Interface xennet0 at xenbus0 id 0: Xen Virtual Network Interface xennet0: MAC address 00:16:3e:00:01:15 unknown type console at xenbus0 id 0 not configured raidattach: Asked for 8 units Kernelized RAIDframe activated Searching for RAID components... boot device: xbd0 root on xbd0a dumps on xbd0b mountroot: trying lfs... mountroot: trying ffs... unknown type console at xenbus0 id 0 not configured root file system type: ffs unknown type console at xenbus0 id 0 not configured init: copying out path `/sbin/init' 11 Sun Dec 28 13:09:48 JST 2008 Starting file system checks: /dev/rxbd0a: file system is clean; not checking Setting tty flags. Setting sysctl variables: Starting network. Hostname: netbsd64_5 IPv6 mode: host Configuring network interfaces: xennet0. Adding interface aliases:. Building databases: dev, utmp, utmpx done Starting syslogd. Checking for core dump... Mounting all filesystems... Clearing temporary files. Checking quotas: done. /etc/rc: WARNING: No swap space configured! Starting virecover. Starting local daemons:. Updating motd. Starting sshd. postfix/postfix-script: starting the Postfix mail system Starting inetd. Starting cron. Sun Dec 28 13:10:02 JST 2008 NetBSD/amd64 (netbsd64_5) (console) login:
見ればわかるが、当然64bit kernelに64bit userlandである。
# file /sbin/init /sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for NetBSD 5.0, not stripped # cpuctl identify 0 cpu0: Intel (686-class), id 0xf49 cpu0: features bfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR> cpu0: features bfebfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX> cpu0: features bfebfbff<FXSR,SSE,SSE2,SS,HTT,TM,SBF> cpu0: features2 651d<SSE3,DTES64,MONITOR,DS-CPL,TM2,CID,CX16,xTPR> cpu0: features3 20100800<SYSCALL/SYSRET,XD,EM64T> cpu0: "Intel(R) Celeron(R) CPU 2.80GHz" cpu0: I-cache 12K uOp cache 8-way, D-cache 16KB 64B/line 8-way cpu0: L2 cache 0MB 64B/line 4-way cpu0: ITLB 4K/4M: 128 entries cpu0: DTLB 4K/4M: 64 entries cpu0: Initial APIC ID 0 cpu0: Cluster/Package ID 0 cpu0: family 0f model 04 extfamily 00 extmodel 00
次に32bit用のNetBSD/i386 Domain-Uをインストールする。
NetBSD/i386のインストールメディアから以下のファイルを取り出す。
i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz i386/binary/kernel/netbsd-INSTALL_XEN3PAE_DOMU.gz
これを適当なディレクトリに置く。
# mount -t cd9660 /dev/cd0a /mnt # cp /mnt/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz /xendata/netbsd32/ # cp /mnt/i386/binary/kernel/netbsd-INSTALL_XEN3PAE_DOMU.gz /xendata/netbsd32/ # gzip -d /xendata/netbsd32/netbsd-XEN3PAE_DOMU.gz # gzip -d /xendata/netbsd32/netbsd-INSTALL_XEN3PAE_DOMU.gz
ここで使用するkernelはXEN3PAEで、i386のアドレス拡張であるPAE専用のKernelである。xen 64bit kernelのParaVirtualizationで使用できる32bit OSはPAEモードでなければならない。通常のNetBSD/i386カーネルや32bit Xen用のカーネルは使用できないので注意する。
当然これらのファイルは32bitバイナリである。
# file * netbsd-INSTALL_XEN3PAE_DOMU: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for NetBSD 5.0, not stripped netbsd-XEN3PAE_DOMU: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for NetBSD 5.0, not stripped
32bit Domain-Uのインストール先となる領域をここではファイルとして作成する。当然だが、NetBSD/amd64とは別に用意する。
# dd if=/dev/zero of=/xendata/netbsd32/netbsd32.img bs=1m count=4096
設定そのものはkernelに変えているだけでamd64の場合と何ら変わりない。Macアドレスが重複しないように注意するくらい。
# kernel = "/xendata/netbsd32/netbsd-INSTALL_XEN3PAE_DOMU" memory = 256 name = "NetBSD32_DOMU" vif = [ 'mac=00:16:3e:00:01:16,bridge=bridge0' ] disk = [ 'file:/xendata/netbsd32/netbsd32.img,0,w']
# xm create -c /usr/pkg/etc/xen/netbsd32
sysinstが起動するので例によって普通にインストールする。
例によってxen設定ファイルを通常カーネルに切り替える。
# kernel = "/xendata/netbsd32/netbsd-XEN3PAE_DOMU" memory = 256 name = "NetBSD32_DOMU" vif = [ 'mac=00:16:3e:00:01:16,bridge=bridge0' ] disk = [ 'file:/xendata/netbsd32/netbsd32.img,0,w'] root = "xbd0"
これで起動すると、32bitなNetBSD/i386のDomain-Uが起動する。
# xm create -c /usr/pkg/etc/xen/netbsd32 Using config file "/usr/pkg/etc/xen/netbsd32". Loaded initial symtab at 0xc04dbdb8, strtab at 0xc05118ec, # entries 12807 Started domain NetBSD32_DOMU Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 5.0_BETA (XEN3PAE_DOMU) #1: Sat Dec 27 11:56:28 JST 2008 root@sweety:/export/netbsd-5/obj/i386/export/netbsd-5/src/sys/arch/i386/compile/XEN3PAE_DOMU total memory = 256 MB avail memory = 245 MB mainbus0 (root) hypervisor0 at mainbus0: Xen version 3.3 vcpu0 at hypervisor0: Intel 686-class, 2800MHz, id 0xf49 xenbus0 at hypervisor0: Xen Virtual Bus Interface xencons0 at hypervisor0: Xen Virtual Console Driver xencons0: using event channel 2 npx0 at hypervisor0: using exception 16 xbd0 at xenbus0 id 0: Xen Virtual Block Device Interface xennet0 at xenbus0 id 0: Xen Virtual Network Interface xennet0: MAC address 00:16:3e:00:01:16 unknown type console at xenbus0 id 0 not configured raidattach: Asked for 8 units Kernelized RAIDframe activated Searching for RAID components... boot device: xbd0 root on xbd0a dumps on xbd0b mountroot: trying lfs... mountroot: trying ffs... unknown type console at xenbus0 id 0 not configured root file system type: ffs unknown type console at xenbus0 id 0 not configured init: copying out path `/sbin/init' 11 Sun Dec 28 14:02:06 JST 2008 Starting file system checks: /dev/rxbd0a: file system is clean; not checking Setting tty flags. Setting sysctl variables: Starting network. Hostname: netbsd5_32 IPv6 mode: host Configuring network interfaces: xennet0. Adding interface aliases:. Building databases: dev, utmp, utmpx done Starting syslogd. Checking for core dump... savecore: dumpdev /dev/console is tty; override kernel Dec 28 14:02:16 netbsd5_32 savecore: dumpdev /dev/console is tty; override kernel Mounting all filesystems... Clearing temporary files. Creating a.out runtime link editor directory cache. Checking quotas: done. /etc/rc: WARNING: No swap space configured! Starting virecover. Starting local daemons:. Updating motd. Starting sshd. postfix/postfix-script: starting the Postfix mail system Starting inetd. Starting cron. Sun Dec 28 14:02:18 JST 2008 NetBSD/i386 (netbsd5_32) (console) login: root Password: Dec 28 14:03:25 netbsd5_32 login: ROOT LOGIN (root) ON console Last login: Sun Dec 28 14:01:25 2008 on console Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 5.0_BETA (XEN3PAE_DOMU) #1: Sat Dec 27 11:56:28 JST 2008 Welcome to NetBSD! This system is running a beta release of the NetBSD operating system, aimed at stabilizing the next formal release. It is close to formal release quality, but may still contain bugs, even serious ones. Please bear this in mind and use the system with care. You are encouraged to test this version as thoroughly as possible. Should you encounter any problem, please report it back to the development team using the send-pr(1) utility (requires a working MTA). If yours is not properly set up, use the web interface at: http://www.NetBSD.org/support/send-pr.html Thank you for helping us test and improve this beta NetBSD release. Terminal type is vt100. We recommend creating a non-root account and using su(1) for root access. netbsd5_32# uname -a NetBSD netbsd5_32 5.0_BETA NetBSD 5.0_BETA (XEN3PAE_DOMU) #1: Sat Dec 27 11:56:28 JST 2008 root@sweety:/export/netbsd-5/obj/i386/export/netbsd-5/src/sys/arch/i386/compile/XEN3PAE_DOMU i386 netbsd5_32# file /sbin/init /sbin/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for NetBSD 5.0, not stripped netbsd5_32#
見ればわかるがちゃんと32bit kernelだし、userlandも32bitとなっている。CPUはホストOSの情報がほぼそのまま渡されるため、以下のようになる。
# cpuctl identify 0 cpu0: Intel (686-class), id 0xf49 cpu0: features 0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR> cpu0: features 0xbfebfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX> cpu0: features 0xbfebfbff<FXSR,SSE,SSE2,SS,HTT,TM,SBF> cpu0: features2 0x651d<SSE3,DTES64,MONITOR,DS-CPL,TM2,CID,CX16,xTPR> cpu0: features3 0x20100000<XD,EM64T> cpu0: "Intel(R) Celeron(R) CPU 2.80GHz" cpu0: I-cache 12K uOp cache 8-way, D-cache 16KB 64B/line 8-way cpu0: L2 cache 0MB 64B/line 4-way cpu0: ITLB 4K/4M: 128 entries cpu0: DTLB 4K/4M: 64 entries cpu0: Initial APIC ID 0 cpu0: Cluster/Package ID 0 cpu0: family 0f model 04 extfamily 00 extmodel 00
上記の2つのDomain-Uを起動したあと、Domain-0でxm listを入力すると以下のようになる。
# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 512 1 r----- 2072.2 NetBSD32_DOMU 12 256 1 -b---- 3.6 NetBSD64_DOMU 7 256 1 -b---- 9.8
Domain-0以外のIDは起動する度に変わるので、毎回異なる。