How to set up a guest OS using xen3

NetBSD的安装、升级、更新等日常问题请在这里讨论。

版主: lionux

回复
头像
lionux
锌 Zn
帖子: 457
注册时间: 2010-02-04 11:09

How to set up a guest OS using xen3

帖子 lionux » 2010-09-25 8:44

转自NetBSD wiki http://wiki-static.aydogan.net/How_to_s ... using_xen3
Requirements

Xen3 is supported from NetBSD-4.0 onward. If you plan on using NetBSD-CURRENT, please read the article How to build NetBSD-current to do so. Guest operating systems can run from their own partitions, or from image files in the main (DOM0) install.

This tutorial describes how to:

* Install and configure NetBSD as a DOM0
* Install and run a NetBSD as a DOMU
* Install and run a Windows XP system as as DOMU
* Install and run a Debian system as a DOMU

Installing Xen tools and kernels
Xen tools

To run and administer xen domains, we need the xentools3 or xentools33 packages which are available in pkgsrc.

Xen 3.1 packages are under sysutils/xentools3 for traditional xentools, and sysutils/xentools3-hvm for the additional HVM support to run un-modified OSes such as Windows XP.

Xen 3.3 packages are under sysutils/xentools33. Unlike Xen 3.1, no extra package is required for HVM support. Note, it is not possible to install Xen 3.1 and Xen 3.3 packages at the same time. They conflict with each other.

HVM stands for Hardware Virtualization Managed. The benefit of hardware virtualization is that you can run OSes that don't know they are being virutalized like Windows XP, for example. However, you must have a CPU which supports this. Intel CPUs must have the 'VT' instruction. AMD CPUs will have the 'SVM' instruction. You can find out if your CPU supports HVM by taking a look at this page:

http://wiki.xensource.com/xenwiki/HVM_C ... Processors

In NetBSD 5.0 there's a new cpuctl command. This is an example output of an AMD CPU:
# cpuctl identify 0
cpu0: AMD Unknown K8 (Athlon) (686-class), 2210.22 MHz, id 0x60f82
cpu0: features 0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
cpu0: features 0x178bfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX>
cpu0: features 0x178bfbff<FXSR,SSE,SSE2,HTT>
cpu0: features2 0x2001<SSE3,CX16>
cpu0: features3 0xebd3fbff<SCALL/RET,NOX,MXX,FFXSR,RDTSCP,LONG,3DNOW2,3DNOW>
cpu0: features4 0x11f<LAHF,CMPLEGACY,SVM,EAPIC,ALTMOVCR0,3DNOWPREFETCH>
cpu0: "AMD Turion(tm) 64 X2 Mobile Technology TL-64"
cpu0: I-cache 64KB 64B/line 2-way, D-cache 64KB 64B/line 2-waycpu0: L2 cache 1MB 64B/line 16-way
cpu0: ITLB 32 4KB entries fully associative, 8 4MB entries fully associative
cpu0: DTLB 32 4KB entries fully associative, 8 4MB entries fully associativecpu0: Initial APIC ID 0
cpu0: AMD Power Management features: 0x7f<TS,FID,VID,TTP,HTC,STC,100>
cpu0: family 0f model 08 extfamily 00 extmodel 06
Note the SVM feature flag in the features4 line indicating that HVM support is present on this CPU. However, this feature may be disabled in the BIOS. In this case since NetBSD 5.0 there will show up this dmesg line on AMD CPUs only:
cpu0: SVM disabled by the BIOS

Xen 3.1 (the xentools3-hvm package will automatically bring in the base xentools3):
# cd /usr/pkgsrc/sysutils/xentools3-hvm
# make install
Xen 3.3:
# cd /usr/pkgsrc/sysutils/xentools33
# make install
Xen kernel

Next, we will get the xen hypervisor kernel itself. For NetBSD 4.x and 5.x the i386 port does not support 'PAE' kernels and must run the Xen 3.1 package. This restriction has been removed in -current and is not relevant for the amd64 port.

For Xen 3.1, in pkgsrc this is sysutils/xenkernel3, for Xen 3.3, this is sysutils/xenkernel33:
# cd /usr/pkgsrc/sysutils/xenkernel3
# make install
And copy it into / directory, like this:
# cp /usr/pkg/xen3-kernel/xen.gz /
Finally, decompress it so that all versions of GRUB can read it:
# gunzip /xen.gz
Xen DOM0 kernel

Lastly, we need a XEN-enabled kernel for our DOM0 domain. There are two possibilities: downloading the binary version, or building it from source.
Downloading the binary version

From NetBSD-4.0 onward, NetBSD supports Xen, and provides some XEN-enabled kernel directly from [1], in each binary/kernel directory associated with a particular release.

For example, with NetBSD-4.0, You can grab one from (ftp.NetBSD.org/pub/NetBSD/NetBSD-4.0/i386/binary/kernel/netbsd-XEN3_DOM0.gz [2]):
The netbsd-XEN3_DOM0.gz file contains a gzipped version of the kernel. Just copy and move it into the root directory like this:
# cp netbsd-XEN3_DOM0.gz /
Now decompress it to avoid any issues GRUB or Xen might have with gzipped kernels
# gunzip /netbsd-XEN3_DOM0.gz
Building it from source

Building a kernel from source is out of the scope of this section. Please consult How to build a kernel from NetBSD's FAQ for more details.

Once building is done, you can find them in /usr/src/obj/_releasedir_/i386/binary/kernel/. Identically to binary version, copy or move netbsd-XEN3_DOM0 in the root directory /.
Selecting a bootloader

In NetBSD 5.0 the native boot loader, /boot, can load Xen directly. For earlier versions of NetBSD you will need to use Grub. The NetBSD 5.0 bootloader can be easily dropped into a NetBSD 4.x system by coping them into /boot and running installboot(8) properly.
Updating /boot

For full details refer to installboot(8), but for a standard configuration with VGA console and an IDE or SATA drive with an FFSv1 root file system use the following:
# cp /usr/mdec/boot /boot
# installboot -v -o timeout=5 /dev/rwd0a /usr/mdec/bootxx_ffsv1
Updating /boot.cfg

NetBSD 5.0 or later will already have a /boot.cfg file with a basic configuration. Enabling Xen support only requires one additional line in this case. If you're upgrading from an earlier version or do not have an existing /boot.cfg use the following example:
banner=Welcome to NetBSD
banner==================
banner=
banner=Please choose an option from the following menu:
menu=Boot normally:boot netbsd
menu=Boot single-user:boot netbsd -s
menu=Boot backup kernel:boot onetbsd
menu=Drop to boot prompt:prompt
menu=Boot Xen with 256MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
menu=Boot Xen with 256MB for dom0 (serial):load /netbsd-XEN3_DOM0 console=com0;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M console=com1 com1=115200,8n1
menu=Boot Xen with dom0 in single-user mode:load /netbsd-XEN3_DOM0 -s;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
timeout=5
default=1
Make sure you update the "load /netbsd-XEN3_DOM0" and the "dom0_mem=256M" arguments to match your setup. On next boot select the 'Boot Xen with 256MB for dom0' option and make sure you see Xen kernel messages and the normal NetBSD kernel messages. Once you're satisfied it is working you can change the "default=1" line to "default=5" to automatically boot Xen on reboot.
Setting up Grub

Before installing and configuring XEN3, we need to install grub, the bootloader required to boot our XEN-enabled system.

To install it, use its package provided in pkgsrc (sysutils/grub):
# cd /usr/pkgsrc/sysutils/grub
# make install
Building grub may take a while.

When installation is finished, you can proceed to grub's configuration in the /grub directory.
GRUB configuration

First, create /grub (if it is not present), and copy paste the menu.lst file below used by grub to read its configuration:
# mkdir /grub
# vi /grub/menu.lst
This typical /grub/menu.lst file should have following content:
#Grub config file for NetBSD/xen. Copy as /grub/menu.lst and run
# grub-install /dev/rwd0d (assuming your boot device is wd0).
#
# The default entry to load will be the first one
default=0

# boot after 10s the default entry if the user didn't hit keyboard
timeout=10

# Same as above, but using VGA console
# We can use console=tty0 (Linux syntax) or console=pc (NetBSD syntax)
title Xen 3.0 / NetBSD (hda0, vga)
root(hd0,0)
kernel (hd0,a)/xen dom0_mem=514624
module (hd0,a)/netbsd-XEN3_DOM0 bootdev=/dev/wd0a ro console=tty0

#Load a regular NetBSD/i386 kernel. Can be useful if you end up with a
#nonworking /xen.gz
title NetBSD 4.0
root (hd0,a)
kernel --type=netbsd /netbsd

#Load the NetBSD bootloader, letting it load the NetBSD/i386 kernel.
#May be better than the above, as grub can't pass all required infos
#to the NetBSD/i386 kernel (e.g. console, root device, ...)
title NetBSD via chain
root (hd0,a)
chainloader +1

## end of grub config file.
Notice that the statement dom0_mem is allocating half a gig to Xen. If you have a box with 4Gb of RAM you probably want to change that to something larger. A smaller number might be wise on systems with less RAM, etc...
Setting up DOM0
Creating xen devices

To create all xen devices, change to /dev and run ./MAKEDEV xen
cd /dev
./MAKEDEV xen
This should create the devices xencons, xenevt and xsd_kva. If any of these are missing you may not have updated to CURRENT using the latest sources and you will have to create the missing device files.
Configuring the bridge interface

The bridge(4) interface is used to provide network access to DOMUs.

To use one, edit (or create) the file /etc/ifconfig.bridge0 and insert following lines to:
create
!brconfig $int add bge0 stp bge0 up
Where 'bge0' should be changed to the name of the interface you want to use with your guest operating systems. use ifconfig(8) to get more details about your actual interfaces.
Rebooting into DOM0

Time to reboot:
# shutdown -r now
If all has gone well, you should have booted into the XEN3_DOM0 kernel. Check this with uname(1):
# uname -v
NetBSD 4.0 (XEN3_DOM0) #0: Sun Dec 16 01:20:31 PST 2007
builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/XEN3_DOM0
You should have XEN3 DOM0 mentioned somewhere.
Configuring rc scripts

Copy or symlink xend, xenbackendd and xendomains from /usr/pkg/share/examples/rc.d to /etc/rc.d.
# cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/
# cp /usr/pkg/share/examples/rc.d/xenbackendd /etc/rc.d/
# cp /usr/pkg/share/examples/rc.d/xendomains /etc/rc.d/
Edit /etc/rc.conf and add the following lines:
xend=YES
xenbackendd=YES
xendomains="dom1"
Later on, when you have created a configuration file for 'dom1', the xendomains variable specified above will trigger 'dom1' to be started when the system is booted. At this point no configuration exists for dom1, therefore it does nothing at this point. If you choose to name your configuration file something else, adapt the name accordingly.

To avoid rebooting a second, start all three services:
# /etc/rc.d/xend start
# /etc/rc.d/xenbackendd start
# /etc/rc.d/xendomains start
Run ifconfig -a to ensure the bridge interface is present and issue a ps ax | grep xen to ensure you have a similar output.
12 ? DK 0:00.00 [xenwatch]
13 ? DK 0:00.00 [xenbus]
411 ? I 0:00.24 xenstored --pid-file=/var/run/xenstore.pid
594 ? IWa 0:00.26 xenconsoled
629 ? IW 0:00.00 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
631 ? IWsa 0:00.02 /usr/pkg/sbin/xenbackendd
639 ? IWa 0:00.52 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
The DOM0 configuration is now done. We will proceed to configuring DOMU domains.
Configuring DOMU
Configuring and installing a NetBSD DOMU

Create (or modify) /usr/pkg/etc/xen/dom1 and include this:
kernel = "/usr/src/obj/releasedir/i386/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz"
#kernel = "/netbsd-XEN3_DOMU"
memory = 64
name = "dom1"
#vcpus = 1
disk = [ 'phy:/dev/wd0g,0x03,w','file:/usr/src/obj/releasedir/i386/installation/cdrom/netbsd-i386.iso,0x04,r' ]
vif = [ 'bridge=bridge0' ]
root = "/dev/wd0d"
This configuration boots into the NetBSD sysinst program and allows you to install a NetBSD DOMU using the normal sysinst method. This configuration uses a DOMU_INSTALL kernel and an ISO image provided by a successful 'build release' and 'build iso-image'. You may be able to locate a valid Xen3 DOMU_INSTALL kernel from ftp://ftp.netbsd.org/pub/NetBSD-daily/ but if not, building a release is your best bet.

In this configuration file, /dev/wd0g is the reserved partition for the guest operating system. This should be changed to the partition you reserved prior to following the instructions within this document.

If you would like to use a physical CDROM instead of an ISO image, change the disk line to:
disk = [ 'phy:/dev/wd0g,0x03,w','phy:/dev/cd0a,0x04,r' ]
Now boot into sysinst using the command:
xm create dom1 -c
The reserved partition will appear as /dev/xbd0. Proceed as you would with a normal NetBSD installation using xbd0 as the target drive and xbd1 as the CDROM.

When you have finished, run shutdown -hp now to dom1.

Now edit /usr/pkg/etc/xen/dom1. Comment the INSTALL kernel and uncomment the DOMU kernel.

You should now have a working NetBSD DOMU (dom1). Boot into dom1 again with the command:
xm create dom1 -c
and ensure the file, /etc/ttys contains only this line or has all other lines commented:
console "/usr/libexec/getty Pc" vt100 on secure
and the file /etc/wscons.conf is completely empty or has all lines commented out. These last two steps ensure no errors should be present on boot. Setting wscons=NO in /etc/rc.conf may effectively do the same thing.

From here, configure /etc/rc.conf and all runtime configuration files as you would normally. The network interface name should be xennet0. Use this name when configuring an IP address.

More information can be obtained by referencing the Xen user guide and the official NetBSD Xen Howto. Questions can be addressed to the [email protected] mailling list.
Configuring and installing a Windows XP DOMU

This requires an HVM capable processor and xentools (see sections above).

This assumes you have a copy of the Windows install CD in /home/xen/winxp.iso, and wish to create a file /home/xen/winxp.img to hold the install. First create a blank file to hold the install. This assumes a size of 4GB (4096M). If you want a different size adjust the numbers to match:
# dd if=/dev/zero of=/home/xen/winxp.img bs=1m count=4096
Create /usr/pkg/etc/xen/win01:
kernel = '/usr/pkg/lib/xen/boot/hvmloader'
builder = 'hvm'
memory = '400'
device_model='/usr/pkg/libexec/qemu-dm'

disk = [ 'file:/home/xen/winxp.img,ioemu:hda,w',
'file:/home/xen/winxp.iso,ioemu:hdb:cdrom,r', ]

# Hostname
name = "win01"

vif = [ 'type=ioemu, bridge=bridge0' ]

boot= 'd'
vnc = 1
usbdevice = 'tablet' # Helps with mouse pointer positioning
You may want to modify the amount of memory and pathnames.

Ensure you have a vncviewer installed, such as net/tightvncviewer or net/vncviewer from pkgsrc.

Then start the XENU and connect to it via VNC.
# xm create /usr/pkg/etc/xen/win01
# vncviewer :0
This will boot the Windows ISO image and let you install Windows as normal. As Windows reboots during install you may need to restart vncviewer.

After install change the boot d to boot c to have the system boot directly from the disk image.
Configuring and installing a GNU/Linux DOMU

We will do this in two steps:

* install a GNU/Linux system, from a livecd or any installation media
* configure the DOM0 so that it can create and start the Linux DOMU.

Installing a Linux distribution (soon-to-be DOMU)

Before proceeding with DOMU configuration, we will install our favorite GNU/Linux distribution on the computer.

In order to do it, we need at least two partitions (only one, if you do not consider the swap). These partitions must reside outside of the NetBSD slice, and may be either of primary or extended type. Of course, you can use more than two, but adapt your labels and partitions accordingly.

We do not cover the partition/slices manipulations through fdisk(8) and disklabel(8), as it depends strongly on how you manage your hard drive's space.

For this tutorial, we will use this partitioning:
# fdisk /dev/wd0d
fdisk: removing corrupt bootsel information
fdisk: Cannot determine the number of heads
Disk: /dev/wd0d
NetBSD disklabel disk geometry:
cylinders: 486344, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 490234752

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

Partition table:
0: Linux native (sysid 131)
start 63, size 20482812 (10001 MB, Cyls 0-1274)
PBR is not bootable: All bytes are identical (0x00)
1: Linux swap or Prime or Solaris (sysid 130)
start 20482875, size 1959930 (957 MB, Cyls 1275-1396)
PBR is not bootable: All bytes are identical (0x00)
2: NetBSD (sysid 169)
start 61464690, size 428770062 (209360 MB, Cyls 3826-30515/178/63), Active
3: <UNUSED>
Drive serial number: -286527765 (0xeeebeeeb)
Here, you notice that we decide to use two primary partitions for our future Linux DOMU:

* partition 0 (for the root directory /)
* partition 1 (for the swap)

Labels:
16 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: 30720816 61464690 4.2BSD 2048 16384 0 # (Cyl. 60976*- 91453*)
b: 1049328 92185506 swap # (Cyl. 91453*- 92494*)
c: 428770062 61464690 unused 0 0 # (Cyl. 60976*- 486343)
d: 490234752 0 unused 0 0 # (Cyl. 0 - 486343)
e: 20480000 93234834 4.2BSD 0 0 0 # (Cyl. 92494*- 112812*)
f: 20480000 113714834 4.2BSD 0 0 0 # (Cyl. 112812*- 133129*)
g: 20480000 134194834 4.2BSD 0 0 0 # (Cyl. 133129*- 153447*)
h: 335559918 154674834 4.2BSD 0 0 0 # (Cyl. 153447*- 486343)
i: 20482812 63 Linux Ext2 0 0 # (Cyl. 0*- 20320*)
j: 1959930 20482875 swap # (Cyl. 20320*- 22264*)
Bear in mind that we added two labels here, namely i and j, which maps respectively to partition 0 and partition 1 of the disk. We will use these labels later for DOMU configuration.

Now that we have partitioned the disk, proceed with installing your Linux distribution. We will not cover that part in this tutorial. You can either install it from an installation media (a cdrom from example), or copy files from an already installed distribution on your computer.

Tip: to manipulate ext2/3 filesystems (the traditional fs under Linux) from NetBSD, you can use sysutils/e2fsprogs from pkgsrc:
# cd /usr/pkgsrc/sysutils/e2fsprogs
# make install
And then use e2fsck, mke2fs and mount_ext2fs(8) directly from NetBSD.
Getting XEN aware Linux kernels

Once installation is done, reboot your computer and return to our Xen-NetBSD system.

To boot our Linux DOMU, we will need a Linux kernel supporting the XENU virtualisation. Depending on your Linux distribution, you can grab one from its repository (it is up to you to find it through aptitude, yum or whatever package manager you use), or get one from the Xen binary distribution.

To get a XENU Linux kernel from Xen binary distribution, get it directly from Xen website download page. Download the tarball and extract the vmlinuz-*-xen from it. In our case, with a 2.6.18 Linux kernel:
# ftp -a http://bits.xensource.com/oss-xen/relea ... x86_32.tgz
# cd /tmp
# tar -xzf xen-3.1.0-install-x86_32.tgz dist/install/boot/vmlinuz-2.6.18-xen
vmlinuz-2.6.18-xen is the kernel that Xen will use to start the DOMU. Move it to any directory you like (just remember it when configuring the kernel entry in the DOMU configuration file):
# mv dist/install/boot/vmlinuz-2.6.18-xen /vmlinuz-XEN3-DOMU
Configuring DOMU

Configuring the Linux DOMU is a bit different than a NetBSD one; some options tend to differ.

Edit (or create) the configuration file domu-linux, in /usr/pkg/etc/xen/:
# vi /usr/pkg/etc/xen/domu-linux
Here's a typical config file for a Linux DOMU:
#----------------------------------------------------------------------------
# Kernel image file. This kernel will be loaded in the new domain.
kernel = "/vmlinuz-XEN3-DOMU"

# Memory allocation (in megabytes) for the new domain.
memory = 256

# A handy name for your new domain. This will appear in 'xm list',
# and you can use this as parameters for xm in place of the domain
# number. All domains must have different names.
#
name = "domu-linux"

# Which CPU to start domain on (only relevant for SMP hardware). CPUs
# numbered starting from ``0''.
#
cpu = "^1" # leave to Xen to pick

#----------------------------------------------------------------------------
# Define network interfaces for the new domain.

# Number of network interfaces (must be at least 1). Default is 1.
vif = [ '' ]

# Define MAC and/or bridge for the network interfaces.
#
# The MAC address specified in ``mac'' is the one used for the interface
# in the new domain. The interface in domain0 will use this address XOR'd
# with 00:00:00:01:00:00 (i.e. aa:00:00:51:02:f0 in our example). Random
# MACs are assigned if not given.
#
# ``bridge'' is a required parameter, which will be passed to the
# vif-script called by xend(8) when a new domain is created to configure
# the new xvif interface in domain0.
#
# In this example, the xvif is added to bridge0, which should have been
# set up prior to the new domain being created -- either in the
# ``network'' script or using a /etc/ifconfig.bridge0 file.
#
vif = [ 'mac=aa:00:00:50:02:f0, bridge=bridge0' ]

#----------------------------------------------------------------------------
# Define the disk devices you want the domain to have access to, and
# what you want them accessible as.
#
# Each disk entry is of the form:
#
# phy:DEV,VDEV,MODE
#
# where DEV is the device, VDEV is the device name the domain will see,
# and MODE is r for read-only, w for read-write. You can also create
# file-backed domains using disk entries of the form:
#
# file:PATH,VDEV,MODE
#
# where PATH is the path to the file used as the virtual disk, and VDEV
# and MODE have the same meaning as for ``phy'' devices.
#
# /dev/wd0i will be seen as "hda1" under DOMU (the root partition)
# /dev/wd0j will be seen as "hda2" under DOMU (the swap)
#
disk = [ 'phy:/dev/wd0i,hda1,w','phy:/dev/wd0j,hda2,w' ]

#----------------------------------------------------------------------------
# Set the kernel command line for the new domain.

# Set root device.
root = "/dev/hda1"
Now, you should be able to start your first Linux DOMU!
# xm create -c /usr/pkg/etc/xen/domu-linux
Possible caveats

If you intend to have more than one box configured with the above configuration on the same network, you will most likely have to specify a unique MAC address per guest OS, otherwise it is likely you will have a conflict. I'm not sure if the MAC assignment is random, incremental or if Xen is able to check for the existence of the proposed MAC address, so specifying the MAC address is recommended.

Here is a method to assign a MAC address to a newly created Xen Domu. First as described before, use the following vif parameter in your config file :
vif = [ 'bridge=bridge0' ]
Then, run the Xen DomU and, once logged run the following command :
# ifconfig xennet0

Output Sample :

xennet0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=2800<TCP4CSUM_Tx,UDP4CSUM_Tx>
enabled=0
address: 00:16:3e:2e:32:5f
inet 192.168.4.81 netmask 0xffffff00 broadcast 192.168.4.255
inet6 fe80::216:3eff:fe2e:325f%xennet0 prefixlen 64 scopeid 0x2

A MAC address is automaticaly generated, use it in your config file with the following syntax :
vif = [ 'mac=00:16:3e:2e:32:5f, bridge=bridge0' ]
And now you can restart the Xen DomU.

Please, note that the MAC Address MUST start with "00:16:3e".[HTML][/HTML]

头像
leo
帖子: 2465
注册时间: 2010-01-21 3:27

怎样在NetBSD上用Xen3设置guest OS

帖子 leo » 2010-12-28 9:55

刚把lionux找到的这篇文章翻译了一下,希望对大家有帮助。不过和NetBSD主页上的Howto一样,这也是一篇没有具体说明NetBSD版本日期的文章,请大家参考时根据自己的情况。
转自NetBSD wiki
http://wiki-static.aydogan.net/How_to_s ... quirements

以下是原文翻译:
==================================================
从NetBSD 4.0开始已经支持了Xen3。如果你想使用 NetBSD-CURRENT, 请参考文章《How to build NetBSD-current》。Guest操作系统可以运行在它们自己的分区上, 也可以在main (DOM0) 上安装的镜像文件上运行。

本指南描述了怎样:
* 将NetBSD安装和配置为DOM0
* 将NetBSD作为DOMU
* 将Windows XP系统做为DOMU
* 将Debian系统做为DOMU


安装Xen工具和内核

Xen tools
要运行和管理xen的domains, 我们需要pkgsrc里面准备好的xentools3或者xentools33 软件包。
传统的xen工具Xen 3.1 的packages在 sysutils/xentools3 目录下, 而 sysutils/xentools3-hvm 则是为了额外提供HVM支持以便运行那些未修改的操作系统,例如Windows XP。

Xen 3.3的packages在 sysutils/xentools33 目录下。 不像 Xen 3.1, 它不需要额外的 package 来支持HVM特性。注意, 不能同时安装 Xen 3.1 和 Xen 3.3 的packages。它们相互有冲突。
HVM允许硬件虚拟化管理。 硬件虚拟化的优势是你可以在虚拟平台的运行一些操作系统,例如Windows XP,而这些操作系统并不知道自己运行在虚拟平台上。不过, 你必须有一颗支持此特性的CPU。Intel的CPU必须具有 'VT' 构架。AMD的CPU必须具有 'SVM' 构架。你可以到下列页面了解一下你的CPU是否支持此特性:
http://wiki.xensource.com/xenwiki/HVM_C ... Processors

在NetBSD 5.0里,有一个新的cpuctl命令。下面是一个AMD CPU的输入结果:

代码: 全选

# [color=royalblue]cpuctl identify 0[/color]
cpu0: AMD Unknown K8 (Athlon) (686-class), 2210.22 MHz, id 0x60f82
cpu0: features 0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
cpu0: features 0x178bfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX>
cpu0: features 0x178bfbff<FXSR,SSE,SSE2,HTT>
cpu0: features2 0x2001<SSE3,CX16>
cpu0: features3 0xebd3fbff<SCALL/RET,NOX,MXX,FFXSR,RDTSCP,LONG,3DNOW2,3DNOW>
cpu0: features4 0x11f<LAHF,CMPLEGACY,[color=red][B]SVM[/B][/color],EAPIC,ALTMOVCR0,3DNOWPREFETCH>
cpu0: "AMD Turion(tm) 64 X2 Mobile Technology TL-64"
cpu0: I-cache 64KB 64B/line 2-way, D-cache 64KB 64B/line 2-waycpu0: L2 cache 1MB 64B/line 16-way
cpu0: ITLB 32 4KB entries fully associative, 8 4MB entries fully associative
cpu0: DTLB 32 4KB entries fully associative, 8 4MB entries fully associativecpu0: Initial APIC ID 0
cpu0: AMD Power Management features: 0x7f<TS,FID,VID,TTP,HTC,STC,100>
cpu0: family 0f model 08 extfamily 00 extmodel 06

注意,上面features4里的SVM标志(红色字体)表明这颗CPU支持HVM特性。不过, 有时该特性选项也许会在BIOS里面被禁用了。这种情况下NetBSD 5.0只会在dmesg里面显示这样的CPU信息:

代码: 全选

cpu0: SVM disabled by the BIOS


Xen 3.1 (the xentools3-hvm package will automatically bring in the base xentools3):
(leo:上面括号内的内容感觉和前面的描述矛盾,故不翻译,请读者自行判别。)

代码: 全选

# cd /usr/pkgsrc/sysutils/xentools3-hvm
# make install

Xen 3.3:

代码: 全选

# cd /usr/pkgsrc/sysutils/xentools33
# make install
(leo:前面已经说了,这两个不兼容,作者将这两者放在一起也许只是要说明两者的具体位置....... )

Xen kernel
接下来就是要安装xen的管理内核了。NetBSD 4.x 和 5.x 在i386平台上不支持 'PAE' 内核(leo:这个说法也过时了,根据NetBSD主页上的Xen的change log,目前在当前版也已经支持'PAE' 内核了。),而只能运行Xen 3.1的package,这个限制在当前版中已经没有了,在AMD64平台上无此限制。
Xen 3.1在pkgsrc里的位置是 sysutils/xenkernel3, 而 Xen 3.3在 sysutils/xenkernel33:

代码: 全选

# cd /usr/pkgsrc/sysutils/xenkernel3
# make install
然后将其拷贝至”/“目录:

代码: 全选

# cp /usr/pkg/xen3-kernel/xen.gz /
最后, 解压缩它以便所有版本的GRUB都可以识别:

代码: 全选

# gunzip /xen.gz

Xen DOM0 Kernel
最终, 我们需要一个启用了XEN支持的内核作为我们的DOM0 domain。有两个可行方案: 下载二进制版本, 或者从源代码构建它。

下载二进制版本
从NetBSD-4.0开始, NetBSD支持Xen, 并且直接提供了一些支持XEN的内核, 在每个发行版本的“ binary/kernel”目录。
例如, 对NetBSD-4.0来说, 这就是ftp.NetBSD.org/pub/NetBSD/NetBSD-4.0/i386/binary/kernel/netbsd-XEN3_DOM0.gz 一个:

代码: 全选

# ftp -a [URL]ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-4.0/i386/binary/kernel/netbsd-XEN3_DOM0.gz[/URL]

这个netbsd-XEN3_DOM0.gz文件包含了一个gzip压缩的内核。你只需将其拷贝并移动到根目录。像这样:

代码: 全选

# cp netbsd-XEN3_DOM0.gz /
现在我们解压缩这个内核,这样可以避免GRUB或者Xen对这个压缩内核有识别问题

代码: 全选

# gunzip /netbsd-XEN3_DOM0.gz

从源代码构建
从源代码构建内核不在本小结的讨论范围之内。请参考NetBSD FAQ的这里 How to build a kernel
一旦你完成了内核的构建, 你可以在 /usr/src/obj/_releasedir_/i386/binary/kernel/ 目录下找到它们。和二进制版本一样, 将 netbsd-XEN3_DOM0 拷贝并移动到 / 目录下。

选择一个启动引导程序
在NetBSD 5.0的本地启动引导程序, /boot, 就可以直接引导Xen。如果你用的是早期的NetBSD版本,你就需要用Grub来引导了。NetBSD 5.0的启动引导程序可以被轻松地移植到一个NetBSD 4.x 的系统上,只要将它们拷贝到 /boot ,然后运行 installboot(8)

更新 /boot
更详尽的信息请参考 installboot(8), 不过对一个标准的带有VGA控制台和一个IDE或者SATA驱动器以及一个FFSv1格式的root文件系统来说使用如下的命令就可以了:

代码: 全选

# cp /usr/mdec/boot /boot
# installboot -v -o timeout=5 /dev/rwd0a /usr/mdec/bootxx_ffsv1

更新 /boot.cfg
NetBSD 5.0或更新的版本已经有一个基本配置的 /boot.cfg 文件了。此时要启用Xen支持只需要增加一行。如果你的系统是从一个早期的版本升级过来的,或者没有 /boot.cfg文件,请使用下面的例子:

代码: 全选

banner=Welcome to NetBSD
banner==================
banner=
banner=Please choose an option from the following menu:
menu=Boot normally:boot netbsd
menu=Boot single-user:boot netbsd -s
menu=Boot backup kernel:boot onetbsd
menu=Drop to boot promptrompt
menu=Boot Xen with 256MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
menu=Boot Xen with 256MB for dom0 (serial):load /netbsd-XEN3_DOM0 console=com0;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M console=com1 com1=115200,8n1
menu=Boot Xen with dom0 in single-user mode:load /netbsd-XEN3_DOM0 -s;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
timeout=5
default=1

请确认你按照实际情况来对这里的 "load /netbsd-XEN3_DOM0" 和 "dom0_mem=256M" 参数进行更新设置。确保在选择下一个 'Boot Xen with 256MB for dom0' 时你可以看到Xen的内核信息和正常的NetBSD内核信息。一旦你对它满意,你可以将这里的 "default=1" 这行修改为 "default=5" ,这样可以重新启动后自动引导Xen。

设置Grub
在安装和配置XEN3之前, 我们需要安装grub, 启用Xen系统所需的启动引导程序。
要安装它, 可以在pkgsrc里 (sysutils/grub):

代码: 全选

# cd /usr/pkgsrc/sysutils/grub
# make install
构建grub可能需要一些时间。
当安装结束后, 你就可以配置grub了,配置文件在 /grub 目录下。

GRUB配置
首先, 创建目录 /grub (如果其不存在), 然后复制粘贴下面grub的配置文件的menu.lst:

代码: 全选

# mkdir /grub
# vi /grub/menu.lst
通常 /grub/menu.lst 文件应该包含下列内容:

代码: 全选

#Grub config file for NetBSD/xen. Copy as /grub/menu.lst and run
# grub-install /dev/rwd0d (assuming your boot device is wd0).
#
# The default entry to load will be the first one
default=0
 
# boot after 10s the default entry if the user didn't hit keyboard
timeout=10
 
# Same as above, but using VGA console
# We can use console=tty0 (Linux syntax) or console=pc (NetBSD syntax)
title Xen 3.0 / NetBSD (hda0, vga)
root(hd0,0)
kernel (hd0,a)/xen dom0_mem=514624
module (hd0,a)/netbsd-XEN3_DOM0 bootdev=/dev/wd0a ro console=tty0 
 
#Load a regular NetBSD/i386 kernel. Can be useful if you end up with a
#nonworking /xen.gz
title NetBSD 4.0
root (hd0,a)
kernel --type=netbsd /netbsd
 
#Load the NetBSD bootloader, letting it load the NetBSD/i386 kernel.
#May be better than the above, as grub can't pass all required infos
#to the NetBSD/i386 kernel (e.g. console, root device, ...)
title NetBSD via chain
root (hd0,a)
chainloader +1
 
## end of grub config file.
请注意这里定义的 dom0_mem,它分配了500M给Xen,如果你有一台4G内容的计算机,你可能会考虑多给Xen分配一些内存。而一台配备内容较小的计算机则可能要少分配一些...

设置DOM0
创建xen设备
要创建所有的xen设备, 切换到 /dev 目录,然后运行 ./MAKEDEV xen

代码: 全选

# cd /dev
# ./MAKEDEV xen
这会创建这些设备, xencons, xenevt 和 xsd_kva。如果你缺少这些设备里的某项,可能是你没有从最新的源代码升级到当前版,那么你就不得不创建这些缺少的设备。
(leo: 我安装完NetBSD i386 5.1的发行版后并未升级到当前版或更新为稳定版,但是这三个文件已经有了,看来如果你使用5.1的发行版,安装xen时不需要先升级为当前版了。

代码: 全选

[color=royalblue]crw-------   1 root  wheel     143,       0 Dec 26 06:58 xencons[/color]
[color=royalblue]crw-------   1 root  wheel     141,       0 Dec 26 06:58 xenevt[/color]
[color=royalblue]crw-------   1 root  wheel     141,       1 Dec 26 06:58 xsd_kva[/color]
)

配置 bridge interface
这里的 bridge(4) interface 用来提供访问DOMU的网络。
要使用的话, 编辑 (或创建) 文件 /etc/ifconfig.bridge0 并且插入下列行:

代码: 全选

create
!brconfig $int add bge0 stp bge0 up
这里的 'bge0' 应该修改为guest操作系统所使用的接口名称。你可以使用ifconfig(8)来获得自己实际接口的详细信息。

重新启动进DOM0
现在是重新启动的时间了:

代码: 全选

# shutdown -r now
如果一切正常, 你的计算机已经用 XEN3_DOM0 内核启动了。你可以用uname(1)来检查一下:

代码: 全选

# uname -v
NetBSD 4.0 (XEN3_DOM0) #0: Sun Dec 16 01:20:31 PST 2007
builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/XEN3_DOM0
你的启动信息里应该包含有 XEN3 DOM0 这样的文字。

配置 rc scripts
从 /usr/pkg/share/examples/rc.d 一下将xend, xenbackendd以及xendomains拷贝或symlink到/etc/rc.d.

代码: 全选

# cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/
# cp /usr/pkg/share/examples/rc.d/xenbackendd /etc/rc.d/
# cp /usr/pkg/share/examples/rc.d/xendomains /etc/rc.d/
编辑 /etc/rc.conf 并添加下列行:

代码: 全选

xend=YES
xenbackendd=YES
xendomains="dom1"
接下来, 当你已经为'dom1'创建了一个配置文件, 上面指定的 xendomains 变量将在系统启动时触发(引导)'dom1'。现在还没有配置dom1, 所以它现在什么也干不了。如果你的配置文件里是其它名字, 请根据自己的实际情况配置。
为了避免再一次启动系统, 你需要启动三个服务:

代码: 全选

# /etc/rc.d/xend start
# /etc/rc.d/xenbackendd start
# /etc/rc.d/xendomains start
运行ifconfig -a以确保已经提供了bridge接口,然后运行 ps ax | grep xen 以确保你有类似的输出。

代码: 全选

12 ? DK 0:00.00 [xenwatch]
13 ? DK 0:00.00 [xenbus]
411 ? I 0:00.24 xenstored --pid-file=/var/run/xenstore.pid
594 ? IWa 0:00.26 xenconsoled
629 ? IW 0:00.00 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
631 ? IWsa 0:00.02 /usr/pkg/sbin/xenbackendd
639 ? IWa 0:00.52 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
DOM0 的配置已经结束了。我们将配置DOMU domains.

配置DOMU
配置和安装一个NetBSD的DOMU
创建 (或编辑) /usr/pkg/etc/xen/dom1 并包含如下内容:

代码: 全选

kernel = "/usr/src/obj/releasedir/i386/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz"
#kernel = "/netbsd-XEN3_DOMU"
memory = 64
name = "dom1"
#vcpus = 1
disk = [ 'phy:/dev/wd0g,0x03,w','file:/usr/src/obj/releasedir/i386/installation/cdrom/netbsd-i386.iso,0x04,r' ]
vif = [ 'bridge=bridge0' ]
root = "/dev/wd0d"
这个配置使系统启动后进入NetBSD的sysinst程序,并允许你用正常的sysinit方式安装一个NetBSD的DOMU。这个配置用一个 DOMU_INSTALL 内核以及由一个成功的'build release' 和 'build iso-image' 步骤生成的ISO镜像文件。你可以从ftp://ftp.netbsd.org/pub/NetBSD-daily/ 获取一个有效的 Xen3 DOMU_INSTALL 内核, 如果你不想这样做,最好的选择就是做构建一个发行版。
在这个配置文件里, /dev/wd0g 是为guest操作系统提供的保留分区。这应该参考下面的说明替换为自己适合的分区。
如果你想用一个真实的CDROM来代替ISO镜像文件, 将disk这行修改为:

代码: 全选

disk = [ 'phy:/dev/wd0g,0x03,w','phy:/dev/cd0a,0x04,r' ]
现在用下面的命令启动进sysinst:

代码: 全选

xm create dom1 -c
保留的分区会显示为 /dev/xbd0。安装过程就像平时正常执行NetBSD安装一样,将xbd0作为目标驱动器,xbd1作为CDROM。
当完成安装后, 运行 shutdown -hp now 来启动至 dom1。
现在编辑 /usr/pkg/etc/xen/dom1。注释掉 INSTALL 内核并且去掉 DOMU 内核前面的注释。
你现在应该有一个工作正常的 NetBSD DOMU (dom1)了。用下面的命令再次启动进dom1 :

代码: 全选

xm create dom1 -c
并且确保文件 /etc/ttys 里只包含下面这一行内容,或者其它行是注释掉的:

代码: 全选

console "/usr/libexec/getty Pc" vt100 on secure
而文件 /etc/wscons.conf 是空文件或者所有行都已经注释掉了。最后两个步骤是确保在启动时没有错误信息。在 /etc/rc.conf 里设置 wscons=NO 也许效果一样。
从现在开始, 常规地进行 /etc/rc.conf 和其它运行配置文件。网络接口名称应该是xennet0。当你配置一个IP地址时请使用这个名称。
更多的信息可以从Xen用户指南上或获取,或者官方的 NetBSD Xen Howto。如果有什么疑问可以通过邮件列表 [email protected] 提问。

配置和安装一个Windows XP的DOMU
这需要一颗支持HVM的处理器和xentools (上面小节说过的)。
这里假设你有一张Windows安装光盘镜像在 /home/xen/winxp.iso, 并且希望创建一个文件 /home/xen/winxp.img 来容纳安装过程。首先创建一个空白文件来容纳安装过程。这里假设文件大小是4GB (4096M)。你可以根据自己的情况调整:

代码: 全选

# dd if=/dev/zero of=/home/xen/winxp.img bs=1m count=4096
创建 /usr/pkg/etc/xen/win01:

代码: 全选

kernel = '/usr/pkg/lib/xen/boot/hvmloader'
builder = 'hvm'
memory = '400'
device_model='/usr/pkg/libexec/qemu-dm'
 
disk = [ 'file:/home/xen/winxp.img,ioemu:hda,w',
'file:/home/xen/winxp.iso,ioemu:hdb:cdrom,r', ]
 
# Hostname
name = "win01"
 
vif = [ 'type=ioemu, bridge=bridge0' ]
 
boot= 'd'
vnc = 1
usbdevice = 'tablet' # Helps with mouse pointer positioning
你可能像修改内存大小和路径名称。
确保你已经安装了vncviewer, 例如pkgsrec里的 net/tightvncviewer 或者 net/vncviewer。 然后启动 XENU 并且通过VNC连接它。

代码: 全选

# xm create /usr/pkg/etc/xen/win01
# vncviewer :0
这将启动Windows ISO镜像并且允许你正常地安装Windows。当windows安装过程中重新启动时你需要重新启动vncviewer。

安装完成后,将 boot d 修改为 boot c 以便直接从Windows的disk image启动。

配置和安装一个 GNU/Linux 的DOMU
我们将通过两个步骤:
* 通过一张livecd或者任何安装介质来安装一个 GNU/Linux 系统
* 配置DOM0以便它可以创建和启动Linux的DOMU.

安装一个Linux发行版 (马上将成为DOMU)

在进行DOMU配置前, 我们将把选择的 GNU/Linux 发行版安装到这台计算机上。

要满足这个条件,我们至少需要两个分区 (如果你不考虑交换只有一个也可以)。这些分区必须位于NetBSD的slice之外, 有可能是基本分区也可能是扩展分区类型。当然,你可以考虑两个以上的分区,但是要根据你的labels和partitions来调整。

我们这里不讨论怎样通过fdisk(8)和disklabel(8)来划分partition/slices, 因为怎样规划磁盘空间完全因人而异。
本教程里, 我们使用这样的分区方式:

代码: 全选

# fdisk /dev/wd0d 
fdisk: removing corrupt bootsel information
fdisk: Cannot determine the number of heads
Disk: /dev/wd0d
NetBSD disklabel disk geometry:
cylinders: 486344, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 490234752
 
BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 490234752
 
Partition table:
0: Linux native (sysid 131)
start 63, size 20482812 (10001 MB, Cyls 0-1274)
PBR is not bootable: All bytes are identical (0x00)
1: Linux swap or Prime or Solaris (sysid 130)
start 20482875, size 1959930 (957 MB, Cyls 1275-1396)
PBR is not bootable: All bytes are identical (0x00)
2: NetBSD (sysid 169)
start 61464690, size 428770062 (209360 MB, Cyls 3826-30515/178/63), Active
3: <UNUSED>
Drive serial number: -286527765 (0xeeebeeeb)

这里请注意, 我们将为未来的Linux DOMU使用两个primary partitions:

* partition 0 (for the root directory /)
* partition 1 (for the swap)

Labels:

代码: 全选

16 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: 30720816 61464690 4.2BSD 2048 16384 0 # (Cyl. 60976*- 91453*)
b: 1049328 92185506 swap # (Cyl. 91453*- 92494*)
c: 428770062 61464690 unused 0 0 # (Cyl. 60976*- 486343)
d: 490234752 0 unused 0 0 # (Cyl. 0 - 486343)
e: 20480000 93234834 4.2BSD 0 0 0 # (Cyl. 92494*- 112812*)
f: 20480000 113714834 4.2BSD 0 0 0 # (Cyl. 112812*- 133129*)
g: 20480000 134194834 4.2BSD 0 0 0 # (Cyl. 133129*- 153447*)
h: 335559918 154674834 4.2BSD 0 0 0 # (Cyl. 153447*- 486343)
i: 20482812 63 Linux Ext2 0 0 # (Cyl. 0*- 20320*)
j: 1959930 20482875 swap # (Cyl. 20320*- 22264*)
记住,这里我们添加了两个labels, 名为 i 和 j, 它们分别映射到该磁盘上的 partition 0 和 partition 1 。 我们将在后面的DOUM配置时使用这些labels。
现在我们已经为安装Linux发行版划分了磁盘分区。本教程不对这部分进行讨论。你可以从一个安装介质 (例如,从一个cdrom), 或者从一台已近安装了发行版的计算机上拷贝文件。
提示: 要从NetBSD操控 ext2/3 文件系统 (Linux下传统的文件系统) , 你可以使用pkgsrc里的 sysutils/e2fsprogs :

代码: 全选

# cd /usr/pkgsrc/sysutils/e2fsprogs
# make install
然后用e2fsck, mke2fs 和 mount_ext2fs(8) 就可以直接从NetBSD上操作Linux文件系统了。

让XEN知道Linux内核
一旦完成安装, 重新启动你的计算机并且返回Xen-NetBSD系统。
要启动Linux DOMU, 我们需要一个支持XENU虚拟化的Linux内核。这要看你的Linux发行版, 你可以从该发行版的仓库获得它 (你可以通过aptitude, yum或随便使用哪种packages管理器), 或者从Xen的二进制分发里获取一个。

要从Xen的二进制分发里获取一个XENU的Linux内核, 你可以直接从Xen主页上的download page获取。下载这个tarball并且提取里面的vmlinuz-*-xen。本例的情况是用一个 2.6.18 Linux 的内核:

代码: 全选

# ftp -a [URL]http://bits.xensource.com/oss-xen/release/3.1.0/bin.tgz/xen-3.1.0-install-x86_32.tgz[/URL]
# cd /tmp
# tar -xzf xen-3.1.0-install-x86_32.tgz dist/install/boot/vmlinuz-2.6.18-xen
vmlinuz-2.6.18-xen 一个Xen准备用来启动DOMU的内核。将其移动到任何你喜欢的目录下 (你需要在DOMU的配置文件里设置这个内核,所以你要记住这个位置):

代码: 全选

# mv dist/install/boot/vmlinuz-2.6.18-xen /vmlinuz-XEN3-DOMU

配置DOMU
配置Linux的DOMU与配置NetBSD的DOMU略有不同; 有些选项是存在差异。

/usr/pkg/etc/xen/ 里编辑(或创建) 配置文件 domu-linux:

代码: 全选

# vi /usr/pkg/etc/xen/domu-linux
下面是一份典型的Linux DOMU配置文件:

代码: 全选

#----------------------------------------------------------------------------
# Kernel image file. This kernel will be loaded in the new domain.
kernel = "/vmlinuz-XEN3-DOMU"
 
# Memory allocation (in megabytes) for the new domain.
memory = 256
 
# A handy name for your new domain. This will appear in 'xm list',
# and you can use this as parameters for xm in place of the domain
# number. All domains must have different names.
#
name = "domu-linux"
 
# Which CPU to start domain on (only relevant for SMP hardware). CPUs
# numbered starting from ``0''.
#
cpu = "^1" # leave to Xen to pick
 
#----------------------------------------------------------------------------
# Define network interfaces for the new domain.
 
# Number of network interfaces (must be at least 1). Default is 1.
vif = [ '' ]
 
# Define MAC and/or bridge for the network interfaces.
#
# The MAC address specified in ``mac'' is the one used for the interface
# in the new domain. The interface in domain0 will use this address XOR'd
# with 00:00:00:01:00:00 (i.e. aa:00:00:51:02:f0 in our example). Random
# MACs are assigned if not given.
#
# ``bridge'' is a required parameter, which will be passed to the
# vif-script called by xend(8) when a new domain is created to configure
# the new xvif interface in domain0.
#
# In this example, the xvif is added to bridge0, which should have been
# set up prior to the new domain being created -- either in the
# ``network'' script or using a /etc/ifconfig.bridge0 file.
#
vif = [ 'mac=aa:00:00:50:02:f0, bridge=bridge0' ]
 
#----------------------------------------------------------------------------
# Define the disk devices you want the domain to have access to, and
# what you want them accessible as.
#
# Each disk entry is of the form:
#
# phyEV,VDEV,MODE
#
# where DEV is the device, VDEV is the device name the domain will see,
# and MODE is r for read-only, w for read-write. You can also create
# file-backed domains using disk entries of the form:
#
# file:PATH,VDEV,MODE
#
# where PATH is the path to the file used as the virtual disk, and VDEV
# and MODE have the same meaning as for ``phy'' devices.
#
# /dev/wd0i will be seen as "hda1" under DOMU (the root partition)
# /dev/wd0j will be seen as "hda2" under DOMU (the swap)
#
disk = [ 'phy:/dev/wd0i,hda1,w','phy:/dev/wd0j,hda2,w' ]
 
#----------------------------------------------------------------------------
# Set the kernel command line for the new domain.
 
# Set root device.
root = "/dev/hda1"
现在你应该可以启动你的第一个Linux DOMU了!

代码: 全选

# xm create -c /usr/pkg/etc/xen/domu-linux

注意事项
如果你想在同一个网段用上面的配置设置一台以上的guest操作系统, 你必须为每个guest操作系统制定一个唯一的MAC地址,否则可能会有冲突。我不知道MAC地址的分配是否是随机的,递增的或者Xen能否检查出提交的MAC地址, 所以这里推荐你采用指定MAC地址的方法。
这有一个为刚创建的Xen Domu指定MAC地址的方法。首先,像前面的描述那样, 在配置文件中使用下面所示的 vif 参数:

代码: 全选

vif = [ 'bridge=bridge0' ]
然后, 运行Xen DomU, 接着,登录后运行如下命令:

代码: 全选

# ifconfig xennet0
输出的结果类似于: 
[code]xennet0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=2800<TCP4CSUM_Tx,UDP4CSUM_Tx>
enabled=0
address: 00:16:3e:2e:32:5f
inet 192.168.4.81 netmask 0xffffff00 broadcast 192.168.4.255
inet6 fe80::216:3eff:fe2e:325f%xennet0 prefixlen 64 scopeid 0x2
一个MAC地址被自动的生成了, 用如下的语法在配置文件中应用它:

代码: 全选

vif = [ 'mac=00:16:3e:2e:32:5f, bridge=bridge0' ]
接下来你可以重新启动你的Xen DomU了。

请注意, 这里的MAC地址必须以"00:16:3e"做为起始。

头像
leo
帖子: 2465
注册时间: 2010-01-21 3:27

实测Xen安装winxp的Domu

帖子 leo » 2010-12-29 9:15

实际测试环境,NetBSD 5.1 i386 Release,4G内存,CPU Intel Q6600,在bios里开启了HVM支持,安装了pkgin软件包管理软件,尽管目前5.1的packages还没有出来,不过系统会自动安装5.02的packages,大家将就一下吧,此外windows的虚拟文件系统文件xp.gobsd的大小设置为20G,直接用Windows安装光盘操作,没有使用DM,PQ,PE 等MS下磁盘分区工具。经测试安装成功,目前的问题是声卡驱动没有,显示最大分辨率只能是1280x1024,在此分辨率下颜色深度只能是16位。而且xen也不推荐直接让guest对PCI设备操作,这样可能会引起主系统或者guest系统崩溃。下面的记录里省略了PKG环境设置和安装pkgin的过程,请大家自行参看以前的帖子。

安装xentools3

代码: 全选

dhcppc1# [color=blue]pkgin in xentools3[/color]
calculating dependencies for xentools3...
nothing to upgrade.
7 packages to be installed: readline-6.1 libffi-3.0.9 python26-2.6.6nb2 py26-xml-0.8.4nb3 py26-readline-0nb4 py26-curses-0nb4 xentools3-3.1.4nb6 (15M to download, 61M to install)
proceed ? [y/N] [color=blue]y[/color]
downloading packages...
downloading readline-6.1.tgz: 100%
downloading libffi-3.0.9.tgz: 100%
downloading python26-2.6.6nb2.tgz: 100%
downloading py26-xml-0.8.4nb3.tgz: 100%
downloading py26-readline-0nb4.tgz: 100%
downloading py26-curses-0nb4.tgz: 100%
downloading xentools3-3.1.4nb6.tgz: 100%
installing packages...
installing readline-6.1...
pkg_add: Warning: package `readline-6.1' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing libffi-3.0.9...
pkg_add: Warning: package `libffi-3.0.9' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing python26-2.6.6nb2...
pkg_add: Warning: package `python26-2.6.6nb2' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing py26-xml-0.8.4nb3...
pkg_add: Warning: package `py26-xml-0.8.4nb3' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing py26-readline-0nb4...
pkg_add: Warning: package `py26-readline-0nb4' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing py26-curses-0nb4...
pkg_add: Warning: package `py26-curses-0nb4' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
installing xentools3-3.1.4nb6...
pkg_add: Warning: package `xentools3-3.1.4nb6' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
xentools3-3.1.4nb6: copying /usr/pkg/share/examples/xen/block to /usr/pkg/etc/xen/scripts/block
xentools3-3.1.4nb6: copying /usr/pkg/share/examples/xen/vif-bridge to /usr/pkg/etc/xen/scripts/vif-bridge
xentools3-3.1.4nb6: copying /usr/pkg/share/examples/xen/vif-ip to /usr/pkg/etc/xen/scripts/vif-ip
xentools3-3.1.4nb6: copying /usr/pkg/share/examples/xen/xend-config.sxp to /usr/pkg/etc/xen/xend-config.sxp
===========================================================================
The following files should be created for xentools3-3.1.4nb6:
        /etc/rc.d/xendomains (m=0755)
            [/usr/pkg/share/examples/rc.d/xendomains]
        /etc/rc.d/xend (m=0755)
            [/usr/pkg/share/examples/rc.d/xend]
        /etc/rc.d/xenbackendd (m=0755)
            [/usr/pkg/share/examples/rc.d/xenbackendd]
===========================================================================
===========================================================================
$NetBSD: MESSAGE.NetBSD,v 1.2 2007/10/07 12:59:15 kano Exp $
Please ensure that the Xen-specific devices needed by xend(8) exist:
        cd /dev && sh MAKEDEV xen
There are example configuration files for setting up a guest domain in:
        /usr/pkg/share/examples/xen/
Please also refer to the the "NetBSD/xen How-To" for more information on
creating a Xen setup:
        [URL]http://www.netbsd.org/ports/xen/howto.html[/URL]
===========================================================================
processing local summary...
updating database: 100%
marking xentools3-3.1.4nb6 as non auto-removable
dhcppc1#
然后根据提示复制rc脚本:

代码: 全选

dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/xendomains /etc/rc.d/xendomains[/color]
dhcppc1# [color=blue]chmod 755 /etc/rc.d/xendomains[/color]
dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/xend[/color]
dhcppc1# [color=blue]chmod 755 /etc/rc.d/xend[/color]
dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/xenbackendd /etc/rc.d/xenbackendd[/color]
dhcppc1# [color=blue]chmod 775 /etc/rc.d/xenbackendd[/color]
生成xen设备

代码: 全选

dhcppc1# [color=blue]cd /dev && sh MAKEDEV xen[/color]
安装xentools3-hvm

代码: 全选

dhcppc1# [color=blue]pkgin in xentools3-hvm[/color]
根据提示:

代码: 全选

dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/dbus /etc/rc.d/dbus[/color]
dhcppc1# [color=blue]chmod 755 /etc/rc.d/dbus[/color]
dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/hal /etc/rc.d/hal[/color]
dhcppc1# [color=blue]chmod 755 /etc/rc.d/hal[/color]
dhcppc1# [color=blue]cp /usr/pkg/share/examples/rc.d/nasd /etc/rc.d/nasd[/color]
dhcppc1# [color=blue]chmod 755 /etc/rc.d/nasd[/color]
安装Xen kernel

代码: 全选

dhcppc1# [color=blue]pkgin in xenkernel3-3.1.4nb4[/color]
calculating dependencies for xenkernel3-3.1.4nb4...
nothing to upgrade.
1 packages to be installed: xenkernel3-3.1.4nb4 (1208K to download, 1209K to install)
proceed ? [y/N] [color=blue]y[/color]
downloading packages...
downloading xenkernel3-3.1.4nb4.tgz: 100%
installing packages...
installing xenkernel3-3.1.4nb4...
pkg_add: Warning: package `xenkernel3-3.1.4nb4' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
processing local summary...
updating database: 100%
marking xenkernel3-3.1.4nb4 as non auto-removable
dhcppc1#
安装完成后将Xen内核拷贝到 / 下并解压缩:

代码: 全选

dhcppc1# [color=blue]cp /usr/pkg/xen3-kernel/xen.gz /[/color]
dhcppc1# [color=blue]gunzip /xen.gz[/color]
设置Xen DOM0内核,你可以直接编译,我实在是懒得编译了,直接下载一个现成的并解压缩到 / 下。

代码: 全选

dhcppc1# [color=blue]ftp -a ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-5.1/i386/binary/kernel/netbsd-XEN3_DOM0.gz[/color]
dhcppc1# [color=blue]cp netbsd-XEN3_DOM0.gz /[/color]
dhcppc1# [color=blue]gunzip /netbsd-XEN3_DOM0.gz[/color]
由于我用的是NetBSD 5.1的版本, / 下已经有启动引导程序boot了,所以我们不需要安装grub.
接下来是
配置 /boot.cfg
下面是我的文件,读者根据自己的情况调整:

代码: 全选

menu=Boot normally:boot netbsd
menu=Boot single user:boot netbsd -s
menu=Disable ACPI:boot netbsd -2
menu=Disable ACPI and SMP:boot netbsd -12
menu=Drop to boot prompt:prompt
menu=Boot Xen with 256MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /xen dom0_mem=1024M
default=1
timeout=5
配置 bridge interface
这里的 bridge(4) interface 用来提供访问DOMU的网络。
要使用的话, 编辑 (或创建) 文件 /etc/ifconfig.bridge0 并且插入下列行:

代码: 全选

create
!brconfig $int add wm0 stp wm0 up
这里的 'wm0' 应该修改为guest操作系统所使用的接口名称。你可以使用ifconfig(8)来获得自己实际接口的详细信息。

修改 /etc/rc.conf, 添加如下内容

代码: 全选

dbus=yes
hal=yes
nasd=yes
xend=yes
xenbackendd=yes
xendomains="dom1"
配置和安装一个Windows XP的DOMU
我是制作了一个windows xp的光盘镜像,将原版的xp光盘放入光驱,然后:

代码: 全选

dd if=/dev/cd0d of=/home/xp.iso bs=2048
注意: 在NetBSD 5.1 AMD64系统下运行此命令时,有时会出现镜像制作过程中光驱锁死且机器自动重新启动的现象,此时的镜像是不完整的,怀疑NetBSD的对我的光驱识别或驱动有问题,如果你也碰到类似的现象请自行参考手册用更稳定的软件进行镜像制作。
windows xp光盘镜像在 /home目录下,名为xp.iso。
因为/home目录空间比较大,我准备将winxp的DOMU安装在那里,假设我们用文件xp.gobsd来装载xp的DOMU,并为xp保留20G的空间。

代码: 全选

dd if=/dev/zero of=/home/xp.gobsd bs=1m count=20480
生成这个20G的文件在虚拟机上花费了5分钟时间,真机上整整8分钟时间。

下面是在 /home 目录下创建一个winxp的配置文件winxp.config:

代码: 全选

kernel = '/usr/pkg/lib/xen/boot/hvmloader'
builder = 'hvm'
memory = '400'
device_model='/usr/pkg/libexec/qemu-dm'
 
disk = [ 'file:/home/xp.gobsd,ioemu:hda,w',
'file:/home/xp.iso,ioemu:hdb:cdrom,r', ]
 
# Hostname
name = "winxp"
 
vif = [ 'type=ioemu, bridge=bridge0' ]
 
boot= 'd'
vnc = 1
usbdevice = 'tablet' # Helps with mouse pointer positioning
安装vncviewer

代码: 全选

dhcppc1# [color=blue]pkgin in vncviewer[/color]
calculating dependencies for vncviewer...
nothing to upgrade.
1 packages to be installed: vncviewer-4.1.2nb2 (119K to download, 279K to install)
proceed ? [y/N] [color=blue]y[/color]downloading packages...
downloading vncviewer-4.1.2nb2.tgz: 100%
installing packages...
installing vncviewer-4.1.2nb2...
pkg_add: Warning: package `vncviewer-4.1.2nb2' was built for a platform:
pkg_add: NetBSD/i386 5.0.2 (pkg) vs. NetBSD/i386 5.1 (this host)
processing local summary...
updating database: 100%
marking vncviewer-4.1.2nb2 as non auto-removable
dhcppc1#
启动 XENU 并且通过VNC连接它。

代码: 全选

dhcppc1# xm create /home/winxp.config
dhcppc1# vncviewer :0
目前的问题:
声卡驱动有问题,无声,和主系统的firefox冲突。
显示最高只能到1280X1024
还没有进行其它的测试。
附件
1-1.png

回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客