当前位置:操作系统 > Unix/Linux >>

学习NetBSD-体验Xen2.0

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

  一.磁盘分区介绍(以FreeBSD命令):

  ad0s1

  128MB

  FAT32

  # Grubad0s2

  20GB

  UFS2

  # FreeBSDad0s3

  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 0timeout 10

  title FreeBSD 6.0

  rootnoverify (hd0,1,a)

  chainloader +1title NetBSD 3.0

  rootnoverify (hd0,2,a)

  chainloader +1title 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 -aNetBSD 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 listName

  Id

  Mem(MB)

  CPU

  State

  Time(s)

  ConsoleDomain-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 5xbd0 at hypervisor0: Xen Virtual Block Device 2048 MBboot device: xbd0root on md0a dumps on md0bno file system for md0 (dev 0x1100)cannot mount root, error = 79root 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 inte易做图ces for the new domain.# Number of network inte易做图ces (must be at least 1). Default is 1.nics = 1# Define MAC and/or bridge for the network inte易做图ces.## The MAC address specified in ``mac'' is the one used for the inte易做图ce# in the new domain. The inte易做图ce 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 inte易做图ce 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 NetBSDroot = "/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 ==========
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,