完全仮想化についてポイントをドキュメントからパクってきた。
適当に訳す。
まず、完全仮想化サポートを行うようコンパイルするのに必要なパッケージ。
dev86ってのかSDL-devel, SDLってやつ。
dev86の方がいいらしい。
debianの場合はdev86パッケージはなく、bin86およびbccをインストールすればいい。
でもdebianのxenパッケージは完全仮想化をサポートするようにコンパイルされているというのでいらないだろう。
Package Description dev86 The dev86 package provides an assembler and linker for real mode 80x86 instructions. You need to have this package installed in order to build the BIOS code which runs in (virtual) real mode. If the dev86 package is not available on the x86 64 distri- bution, you can install the i386 version of it. The dev86 rpm package for various distributions can be found at http://www.rpmfind.net/linux/rpm2html/search.php?query=dev86&submit=Search SDL-devel, SDL Simple DirectMedia Layer (SDL) is another way of virtualizing the un- modified guest console. It provides an X window for the guest console. If the SDL and SDL-devel packages are not installed by default on the build system, they can be obtained from http://www.rpmfind.net/linux/rpm2html/search.php?query=SDL&submit=Search http://www.rpmfind.net/linux/rpm2html/search.php?query=SDL-devel&submit=Search
んで、完全仮想化を行うときに、準仮想化のときに使えないオプション類。
かぶっているやつもあるけどまあ全部みていく。
kernel HVMファームウェアを指定。/usr/lib/xen/boot/hvmloaderあたりにある。 builder ドメイン生成時に用いる。hvmを指定。 acpi ACPIを有効にする(デフォルト有効) apic APICを(ry pae PAEを(ry hap ハードウェアアシステッドページングサポートを有効にする。 AMD-VのネストしたページングやIntel R VTの拡張ページング。 vif MACアドレスやブリッジを定義可能。 type=ioemuを指定するとHVMのNICを完全仮想化するが、指定しないと準仮想化と同じように扱われる。 disk ディスクを定義。 物理デバイスを指定する場合は phy:/dev/hda1,ioemu:hdb1,w みたいな感じで指定。 ioemuを指定しなければ準仮想化の時と同じように扱われる。 cdromの場合は phy:/dev/hdc,hdc:cdrom,r みたいにcdromってくっつければいい。 ioemuを使える以外は基本的に準仮想化と変わらない。 disk = [’file:/var/images/image1.img,ioemu:hda,w’, ’phy:hda1,hdb1,w’, ’file:/var/images/install1.iso,hdc:cdrom,r’] みたいな。 boot bootシーケンスの指定。 a - フロッピー c - HDD d - CD-ROM boot='adc'かboot='dc'あたりが普通か。 device_model 変更するなと書いてあるがdebianにはサンプルがない。 device_model='/usr/lib/xen-3.2-1/bin/qemu-dm' この辺のはず。 sdl SDL libraryを有効にする。default = 0 (無効) vnc VNC libraryを有効にする。default = 1 (有効) vncconsole HVM起動時にVNCビューアを起動する。デフォルト無効。 vncが有効になっていないと無意味。 vncが有効になっていてvncconsoleが無効の場合、 $ vncviewer ドメイン0のIPアドレス:HVMドメインID みたいな感じでみられる。 serial HVMのシリアルの出力をptyにリダイレクトする。 usb USBサポートを有効にする。デフォルト無効。 usbdeviceが設定されていると有効になるらしい。 usbdevice 指定されたデバイスのUSBサポートを有効にする。 mouse, tablet, ID指定の3通りの指定法がある。 なぜかtabletを指定するとWindowsゲストだとマウスがあっさり動くらしい。 Linuxはなんかダメらしい。 ID指定の仕方は HOST:id1:id2 の形式。 id1:id2はlsusbすればでてくる。 localtime 時刻をローカルタイムに設定する。デフォルトはホストからもってくるんかな。 soundhw サウンドカードを指定する。 sb16, es1370, allの三つが指定可能。 full-screen フルスクリーンで起動する。 nographic シリアル出力を行う別の方法。 VNCもSDLも無効になるのでおすすめできない。
Parameter Description kernel The HVM firmware loader, /usr/lib/xen/boot/hvmloader builder The domain build function. The HVM domain uses the ’hvm’ builder. acpi Enable HVM guest ACPI, default=1 (enabled) apic Enable HVM guest APIC, default=1 (enabled) pae Enable HVM guest PAE, default=1 (enabled) hap Enable hardware-assisted paging support, such as AMD-V’s nested paging or Intel R VT’s extended paging. If available, Xen will use hardware-assisted paging instead of shadow paging for this guest’s memory management. vif Optionally defines MAC address and/or bridge for the network inter- faces. Random MACs are assigned if not given. type=ioemu means ioemu is used to virtualize the HVM NIC. If no type is specified, vbd is used, as with paravirtualized guests. disk Defines the disk devices you want the domain to have access to, and what you want them accessible as. If using a physical device as the HVM guest’s disk, each disk entry is of the form phy:UNAME,ioemu:DEV,MODE, where UNAME is the host device file, DEV is the device name the do- main will see, and MODE is r for read-only, w for read-write. ioemu means the disk will use ioemu to virtualize the HVM disk. If not adding ioemu, it uses vbd like paravirtualized guests. If using disk image file, its form should be like file:FILEPATH,ioemu:DEV,MODE Optical devices can be emulated by appending cdrom to the device type ’,hdc:cdrom,r’ If using more than one disk, there should be a comma between each disk entry. For example: disk = [’file:/var/images/image1.img,ioemu:hda,w’, ’phy:hda1,hdb1,w’, ’file:/var/images/install1.iso,hdc:cdrom,r’] boot Boot from floppy (a), hard disk (c) or CD-ROM (d). For example, to boot from CD-ROM and fallback to HD, the entry should be: boot=’dc’ device model The device emulation tool for HVM guests. This parameter should not be changed. sdl Enable SDL library for graphics, default = 0 (disabled) vnc Enable VNC library for graphics, default = 1 (enabled) vncconsole Enable spawning of the vncviewer (only valid when vnc=1), default = 0 (disabled) If vnc=1 and vncconsole=0, user can use vncviewer to manually connect HVM from remote. For example: vncviewer domain0 IP address:HVM domain id serial Enable redirection of HVM serial output to pty device 89 usb Enable USB support without defining a specific USB device. This option defaults to 0 (disabled) unless the option usbdevice is spec- ified in which case this option then defaults to 1 (enabled). usbdevice Enable USB support and also enable support for the given device. Devices that can be specified are mouse (a PS/2 style mouse), tablet (an absolute pointing device) and host:id1:id2 (a physical USB device on the host machine whose ids are id1 and id2). The advantage of tablet is that Windows guests will au- tomatically recognize and support this device so specifying the config line usbdevice=’tablet’ will create a mouse that works transparently with Windows guests under VNC. Linux doesn’t recognize the USB tablet yet so Linux guests under VNC will still need the Summagraphics emulation. Details about mouse emulation are provided in section A.4.3. localtime Set the real time clock to local time [default=0, that is, set to UTC]. soundhw Enable sound card support and specify the hardware to emulate. Values can be sb16, es1370 or all. Default is none. full-screen Start in full screen. nographic Another way to redirect serial output. If enabled, no ’sdl’ or ’vnc’ can work. Not recommended.
んで、1から仮想ディスクを作る。
物理ディスクや物理パーティションを使う場合、まずそれにLinuxを入れてgrubを/dev/sdaなりなんなに突っ込む必要がある。
ディスクイメージファイルを使う場合、まずは空のディスクイメージを作成してそれにLinuxをつっこむ必要がある。
この場合は、二つの方法があり、一つはHVMゲストを使ってインストールメディアからブートして直接イメージにインストールする。
一つはインストール済みのOSをイメージに流し込む。
どちらの場合もブートローダをイメージにインストールする必要がある。
この時点で初耳です。
you need to install Linux OSって書いてるよ。
イメージの作り方は以下のような感じ。
# dd if=/dev/zero of=hd.img bs=1M count=0 seek=1024
この場合1G作られることになるけどまあ必要に応じてcount増やせばOK。
HVMゲストとしてCD-ROMからブートしてディスクイメージにLinuxをインストールする方法は以下のようになる。
disk=[’file:/var/images/your-hd.img,hda,w’, ’,hdc:cdrom,r’ ] boot=’d’
。。。これはひょっとしてHVM用の雛形を使ってるんでしょうか?
まあ、先に。
これがうまくいかない場合は、まず普通にLinuxをホストマシンにインストールする。
/var/gusetosにインストールしたと仮定する。
で、パーティションテーブルを作成する。
# losetup /dev/loop0 hd.img
# fdisk -b 512 -C 4096 -H 16 -S 32 /dev/loop0
press ’n’ to add new partition
press ’p’ to choose primary partition
press ’1’ to set partition number
press “Enter” keys to choose default value of “First Cylinder” parameter.
press “Enter” keys to choose default value of “Last Cylinder” parameter.
press ’w’ to write partition table and exit
# losetup -d /dev/loop0
ファイルシステムを作成して、grubをインストールする。
# ln -s /dev/loop0 /dev/loop
# losetup /dev/loop0 hd.img
# losetup -o 16384 /dev/loop1 hd.img
# mkfs.ext3 /dev/loop1
# mount /dev/loop1 /mnt
# mkdir -p /mnt/boot/grub
# cp /boot/grub/stage* /boot/grub/e2fs stage1 5 /mnt/boot/grub
# umount /mnt
# grub
grub> device (hd0) /dev/loop
grub> root (hd0,0)
grub> setup (hd0)
grub> quit
# rm /dev/loop
# losetup -d /dev/loop0
# losetup -d /dev/loop1
losetupの-o 16384はオフセットの指定だが、これによりイメージファイルのパーティションテーブルをスキップしている。
この値はセクタ*512になる。
/dev/loopが必要なのは、grubはたとえば/dev/sda1は/dev/sdaというディスク全体を示すものがあり、/dev/sda1はその第一パーティションであるという前提で動作するためだ。
次にOSファイルをイメージにコピーする。
lomountが必要とする情報はパーティション情報だけだ。
# lomount -t ext3 -diskimage hd.img -partition 1 /mnt/guest
# cp -ax /var/guestos/{root,dev,var,etc,usr,bin,sbin,lib} /mnt/guest
# mkdir /mnt/guest/{proc,sys,home,tmp}
ゲストイメージの/etc/fstabを編集する。
# vim /mnt/guest/etc/fstab
/dev/hda1 / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs efaults 0 0
イメージをアンマウント。
# umount /mnt/guest
これで出来上がり。
次に、HVMゲストを作る方法。
これだよこれ。
まず、/etc/xen/xmexample.hvmをコピって
disk = [ ’file:/var/images/min-el3-i386.img,hda,w’ ]
のmin-el3-i386.imgをさっき作ったゲストOSのイメージファイルに変える。
。。。。。あ、はい。
Centあたりからぱくってきますよ、わかりましたよ。
どうせdebianにはHVMのサンプルファイルないですよ。
まあ、とりあえず訳してからにしよう。
あとは単にHVMの設定ファイルを指定して作成するだけ。
# xend start
# xm create /etc/xen/hvmguest.hvm
え。
これだけすか。
でもその前がなげー。
その後VNCでマウスがどうとか書いてるけどそれはまあ気になったらまた読む。
とりあえずCentいってくるか。
A.3 Creating virtual disks from scratch A.3.1 Using physical disks If you are using a physical disk or physical disk partition, you need to install a Linux OS on the disk first. Then the boot loader should be installed in the correct place. For example dev/sda for booting from the whole disk, or /dev/sda1 for booting from partition 1. A.3.2 Using disk image files You need to create a large empty disk image file first; then, you need to install a Linux OS onto it. There are two methods you can choose. One is directly installing it using a HVM guest while booting from the OS installation CD-ROM. The other is copying an installed OS into it. The boot loader will also need to be installed. 90 To create the image file: The image size should be big enough to accommodate the entire OS. This example assumes the size is 1G (which is probably too small for most OSes). # dd if=/dev/zero of=hd.img bs=1M count=0 seek=1024 To directly install Linux OS into an image file using a HVM guest: Install Xen and create HVM with the original image file with booting from CD-ROM. Then it is just like a normal Linux OS installation. The HVM configuration file should have a stanza for the CD-ROM as well as a boot device specification: disk=[’file:/var/images/your-hd.img,hda,w’, ’,hdc:cdrom,r’ ] boot=’d’ If this method does not succeed, you can choose the following method of copying an installed Linux OS into an image file. To copy a installed OS into an image file: Directly installing is an easier way to make partitions and install an OS in a disk image file. But if you want to create a specific OS in your disk image, then you will most likely want to use this method. 1. Install a normal Linux OS on the host machine You can choose any way to install Linux, such as using yum to install Red Hat Linux or YAST to install Novell SuSE Linux. The rest of this example assumes the Linux OS is installed in /var/guestos/. 2. Make the partition table The image file will be treated as hard disk, so you should make the partition table in the image file. For example: # losetup /dev/loop0 hd.img # fdisk -b 512 -C 4096 -H 16 -S 32 /dev/loop0 press ’n’ to add new partition press ’p’ to choose primary partition press ’1’ to set partition number press "Enter" keys to choose default value of "First Cylinder" parameter. press "Enter" keys to choose default value of "Last Cylinder" parameter. press ’w’ to write partition table and exit # losetup -d /dev/loop0 3. Make the file system and install grub # ln -s /dev/loop0 /dev/loop # losetup /dev/loop0 hd.img # losetup -o 16384 /dev/loop1 hd.img 91 # mkfs.ext3 /dev/loop1 # mount /dev/loop1 /mnt # mkdir -p /mnt/boot/grub # cp /boot/grub/stage* /boot/grub/e2fs stage1 5 /mnt/boot/grub # umount /mnt # grub grub> device (hd0) /dev/loop grub> root (hd0,0) grub> setup (hd0) grub> quit # rm /dev/loop # losetup -d /dev/loop0 # losetup -d /dev/loop1 The losetup option -o 16384 skips the partition table in the image file. It is the number of sectors times 512. We need /dev/loop because grub is ex- pecting a disk device name, where name represents the entire disk and name1 represents the first partition. 4. Copy the OS files to the image If you have Xen installed, you can easily use lomount instead of losetup and mount when coping files to some partitions. lomount just needs the partition information. # lomount -t ext3 -diskimage hd.img -partition 1 /mnt/guest # cp -ax /var/guestos/{root,dev,var,etc,usr,bin,sbin,lib} /mnt/guest # mkdir /mnt/guest/{proc,sys,home,tmp} 5. Edit the /etc/fstab of the guest image The fstab should look like this: # vim /mnt/guest/etc/fstab /dev/hda1 / ext3 defaults 1 1 none /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 none /proc proc defaults 0 0 none /sys sysfs efaults 0 0 6. umount the image file # umount /mnt/guest Now, the guest OS image hd.img is ready. You can also reference http://free.oszoo.org for quickstart images. But make sure to install the boot loader. 92 A.4 HVM Guests A.4.1 Editing the Xen HVM config file Make a copy of the example HVM configuration file /etc/xen/xmexample.hvm and edit the line that reads disk = [ ’file:/var/images/min-el3-i386.img,hda,w’ ] replacing min-el3-i386.img with the name of the guest OS image file you just made. A.4.2 Creating HVM guests Simply follow the usual method of creating the guest, providing the filename of your HVM configuration file: # xend start # xm create /etc/xen/hvmguest.hvm In the default configuration, VNC is on and SDL is off. Therefore VNC windows will open when HVM guests are created. If you want to use SDL to create HVM guests, set sdl=1 in your HVM configuration file. You can also turn off VNC by setting vnc=0.