学习NetBSD-体验Xen 2.0(转)

学习NetBSD-体验Xen 2.0(转)[@more@]

  参考文章:NetBSD/Xen Howto.详细http://www.netbsd.org/Ports/xen/howto.html

  一.磁盘分区介绍(以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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10748419/viewspace-944323/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值