學習NetBSD-體驗Xen 2.0(轉)

gugu99發表於2007-08-11
學習NetBSD-體驗Xen 2.0(轉)[@more@]

  參考文章:NetBSD/Xen Howto.詳細

  一.磁碟分割槽介紹(以FreeBSD命令):

  ad0s1   128MB   FAT32   # Grub

ad0s2   20GB   UFS2   # FreeBSD

ad0s3   18GB   FFSv2   # NetBSD

  二.構建Xen-Based系統(Domain0)

  假設NetBSD 3.0已安裝,並同步了pkgsrc及src.

  1.安裝Grub

  # cd /usr/pkgsrc/sysutils/grub

# make install clean clean-depends

  2.把Grub安裝到第一個分割槽,使用Grub引導NetBSD及NetBSD/Xen.

  3.安裝xentools20

  # cd /usr/pkgsrc/sysutils/xentools20

# make install clean clean-depends

  4.安裝Xen 2.0核心

  # cd /usr/pkgsrc/sysutils/xenkernel20

# make install clean clean-depends

  複製Xen 2.0核心到/目錄下:

  # cp /usr/pkg/xen-kernel/xen.gz /

  5.編譯NetBSD/Xen核心,並複製成為/netbsd-XEN0

  # cd /usr/src/sys/arch/i386/conf

# config XEN0

# cd ../compile/XEN0

# make depend

# make

# cp netbsd /netbsd-XEN0
  注:如果想在dom0系統中執行PF,請先行編輯核心配置檔案,開啟相應的選項.

  6.掛上MSDOS分割槽,修改Grub啟動列表.最後menu.lst如下:

  default 0

timeout 10

   

title FreeBSD 6.0

  rootnoverify (hd0,1,a)

  chainloader +1

title NetBSD 3.0

  rootnoverify (hd0,2,a)

  chainloader +1

title NetBSD/Xen

  root (hd0,2)

  kernel (hd0,2,a)/xen.gz dom0_mem=262144

  module (hd0,2,a)/netbsd-XEN0 root=/dev/hda1 ro console=tty0

  dom0_mem=262144代表了domain0的系統記憶體為256MB,module (hd0,2,a)/netbsd-XEN0就是NetBSD/Xen核心.

  7.重啟系統,並選擇"NetBSD/Xen"進入系統.

  # uname -a

NetBSD NetBSD.congli 3.0.0_STABLE NetBSD 3.0.0_STABLE (XEN0) #0: Tue Feb 21 03:33:30 UTC 2006 builds@works.netbsd.org:/home/builds/ab/netbsd-3-0/i386/

200602200000Z-obj/home/builds/ab/netbsd-3-0/src/sys/arch/i386/compile/XEN0 i386

  8.啟動Xen工具守護程式(/usr/pkg/share/examples/rc.d/xend)

  # echo 'xend=YES' >> /etc/rc.conf

# cd /dev && sh MAKEDEV xen

# /usr/pkg/share/examples/rc.d/xend start

  檢查是否成功

  # xm list

Name       Id Mem(MB) CPU State Time(s) Console

Domain-0      0   256   0 r----   58.1   

  到此,已經成功構建並執行在Xen-Based系統(Domain0)中.

  三.安裝DomainU

  1.編譯及安裝XENU核心(/netbsd-XENU)

  # cd /usr/src/sys/arch/i386/conf

# config XENU

# cd ../compile/XENU

# make depends

# make

# cp netbsd /netbsd-XENU0

  2.編譯及安裝INSTALL_XENU核心(/netbsd-INSTALL_XENU)

  # cd /usr/src/sys/arch/i386/conf

# config INSTALL_XENU

# cd ../compile/INSTALL_XENU

# make depends

# make

# cp netbsd /netbsd-INSTALL_XENU

  注:不知道是什麼原因,自己編譯的netbsd-INSTALL_XENU在安裝時出下面錯誤而不能安裝,

  但從NetBSD網站上下載的netbsd-INSTALL_XENU卻能夠安裝.下載地址:

  ftp://ftp.netbsd.org/pub/NetBSD-daily/netbsd-3-0/200602200000Z/i386/binary/kernel.

  其實在這裡可以下載上文所提到的三個核心檔案,包括netbsd-XEN0,netbsd-INSTALL_XENU,netbsd-XENU.

  錯誤資訊,提示不能掛載/裝置:

  xbd: using event channel 5

xbd0 at hypervisor0: Xen Virtual Block Device 2048 MB

boot device: xbd0

root on md0a dumps on md0b

no file system for md0 (dev 0x1100)

cannot mount root, error = 79

root device (default md0a):

  3.建立磁碟映象檔案,如果直接安裝到硬碟的一個分割槽上則可以跳過這一步.

  # mkdir /home/xen

# cd /home/xen

# dd if=/dev/zero of=nbsd.img bs=1024k count=2048

  建立一個2GB大小的檔案.並把NetBSD 3.0的安裝ISO(i386cd.iso)檔案複製到/home/xen下面.

  4.使用xm工具建立DomainU,xm可以直接指定引數,或從配置檔案讀取,詳細看幫忙

  # xm help CMD (如:xm help create) 

  下面是一個簡單的配置檔案(/home/xen/nbsd):

  # -*- mode: python; -*-

#==============================================================

# Python defaults setup for 'xm create'.

# Edit this file to reflect the configuration of your system.

#==============================================================

#--------------------------------------------------------------

# Kernel image file. This kernel will be loaded in the new domain.

# DomainU執行時所需要的核心檔案

kernel = "/netbsd-XENU"

# DomainU安裝時所需的核心檔案

#kernel = "/netbsd-INSTALL_XENU"

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

memory = 512

# 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 = "nbsd"

# 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.

nics = 1

# 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.

#

# VDEV doesn't really matter for a NetBSD guest OS, but it does for Linux.

# Worse, the device has to exists in /dev/ of domain0, because xm will

# try to stat() it. This means that in order to load a Linux guest OS

# from a NetBSD domain0, you'll have to create /dev/hda1, /dev/hda2, ...

# on domain0, with the major/minor from Linux :(

#disk = [ 'phy:/dev/wd0e,wd0d,w' ]

disk = [ 'file:/home/xen/i386cd.iso,cd0a,r', 'file:/home/xen/nbsd.img,wd0d,w' ]

#--------------------------------------------------------------

# Set the kernel command line for the new domain.

# Set root device. This one does matter for NetBSD

root = "/dev/wd0d"

# extra parameters passed to the kernel

#extra = ""

#--------------------------------------------------------------

# Set according to whether you want the domain restarted when it exits.

# The default is False.

#autorestart = True

# end of nbsd config file ====================================================

  因為現在是安裝DomainU階段,所以需要把配置檔案(/home/xen/nbsd)改一下:

  #kernel = "/netbsd-XENU"

kernel = "/netbsd-INSTALL_XENU"

  安裝DomainU:

  # xm create /home/xen/nbsd -c

  接下來就跟正常安裝NetBSD 3.0沒有多大區別.安裝完之後,需要halt,再改一下配置檔案(/home/xen/nbsd),使用netbsd-XENU來啟動domainU:

  kernel = "/netbsd-XENU"

#kernel = "/netbsd-INSTALL_XENU"

  最後執行 xm list,

  Name       Id Mem(MB) CPU State Time(s) Console

Domain-0      0   256  0 r----  1569.6

nbsd        4   511  0 -b---   0.2  9604

  四.DomainU的網路設定

  當domU啟動時,會在dom0系統中建立一個虛擬網路介面(vxif?.?),該虛擬介面跟domU系統的網路介面(xennet?)橋接,只需要把vxif?.?及xennet?設定同一網段,domU的閘道器指向vxif?.?,然後在dom0系統中做NAT.這樣domU就可以訪問外網.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-944323/,如需轉載,請註明出處,否則將追究法律責任。

相關文章