热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Linux系统中通过Xen虚拟机运行FreeBSD

Xen?hypervisor是一个开放源代码的并行虚拟化产品,并由商业的XenSource公司提供支持。在这种系统中,客户操作系统称为domU域,而宿主系统则称为dom0。在Linux上运行FreeBSD虚拟机实例的第一步,是安装用于Linuxdom0的Xen。在这个例子中

Xen? hypervisor 是一个开放源代码的并行虚拟化产品, 并由商业的 XenSource 公司提供支持。 在这种系统中,客户操作系统称为 domU 域, 而宿主系统则称为 dom0。 在 Linux 上运行 FreeBSD 虚拟机实例的第一步, 是安装用于 Linux dom0 的 Xen。 在这个例子中, 宿主系统采用的发行版本是 Slackware Linux
在 Linux dom0 上安装 Xen 3

1.从 XenSource 下载 Xen 3.0

从 http://www.xensource.com/  下载 xen-3.0.4_1-src.tgz。

2.解压缩源代码包
# cd xen-3.0.4_1-src
# KERNELS=”linux-2.6-xen0 linux-2.6-xenU” make world
# make install

注意: 为 dom0 重新编译内核:
# cd xen-3.0.4_1-src/linux-2.6.16.33-xen0
# make menuconfig
# make
# make install
对于较早版本的 Xen,可能需要指定 make ARCH=xen menuconfig

3.在 Grub 的 menu.lst 中增加一个对应的菜单项
编辑 /boot/grub/menu.lst 并在其中增加下列配置:
title Xen-3.0.4
root (hd0,0)
kernel /boot/xen-3.0.4-1.gz dom0_mem=262144
module /boot/vmlinuz-2.6.16.33-xen0 root=/dev/hda1 ro

4.重新启动计算机并进入 Xen
首先, 编辑 /etc/xen/xend-config.sxp,并在其中增加下列配置:
(network-script ‘network-bridge netdev=eth0′)
接下来就可以运行 Xen 了:
# /etc/init.d/xend start
# /etc/init.d/xendomains start

现在 dom0 已经开始运行:
# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 256 1 r—? 54452.9
22.2.2.2 FreeBSD 7-CURRENT domU
从 http://www.fsmware.com/  下载用于 Xen 3.0 的 FreeBSD domU 内核。
?kernel-current
?mdroot-7.0.bz2
?xmexample1.bsd

将配置文件 xmexample1.bsd 放到 /etc/xen/ 并修改与内核及磁盘映像位置有关的配置项。下面是一个示范的例子:
kernel = “/opt/kernel-current”
memory = 256
name = “freebsd”
vif = [ '' ]
disk = [ 'file:/opt/mdroot-7.0,hda1,w' ]
#on_crash = ‘preserve’
extra = “boot_verbose”
extra += “,boot_single”
extra += “,kern.hz=100″
extra += “,vfs.root.mountfrom=ufs:/dev/xbd769a”

其中, mdroot-7.0.bz2 应是未压缩的。

接下来, 您需要修改 kernel-current 中的 __xen_guest 小节, 并加入 Xen 3.0.3 所需要的 VIRT_BASE:
# objcopy kernel-current -R __xen_guest
# perl -e ‘print “LOADER=generic,GUEST_OS=freebsd,GUEST_VER=7.0,XEN_VER=xen-3.0,BSD_SYMTAB,VIRT_BASE=0xC0000000\x00″‘ > tmp
# objcopy kernel-current ?add-section __xen_guest=tmp
# objdump -j __xen_guest -s kernel-current
kernel-current: file format elf32-i386
Contents of section __xen_guest:
0000 4c4f4144 45523d67 656e6572 69632c47 LOADER=generic,G
0010 55455354 5f4f533d 66726565 6273642c UEST_OS=freebsd,
0020 47554553 545f5645 523d372e 302c5845 GUEST_VER=7.0,XE
0030 4e5f5645 523d7865 6e2d332e 302c4253 N_VER=xen-3.0,BS
0040 445f5359 4d544142 2c564952 545f4241 D_SYMTAB,VIRT_BA
0050 53453d30 78433030 30303030 3000 SE=0xC0000000.

现在可以创建并运行 domU 了:
# xm create /etc/xen/xmexample1.bsd -c
Using config file “/etc/xen/xmexample1.bsd”.
Started domain freebsd
WARNING: loader(8) metadata is missing!
Copyright (c) 1992-2006 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD 7.0-CURRENT #113: Wed Jan 4 06:25:43 UTC 2006
kmacy@freebsd7.gateway.2wire.net:/usr/home/kmacy/p4/freebsd7_xen3/src/sys/i386-xen/compile/XENCONF
WARNING: DIAGNOSTIC option enabled, expect reduced performance.
Xen reported: 1796.927 MHz processor.
Timecounter “ixen” frequency 1796927000 Hz quality 0
CPU: Intel(R) Pentium(R) 4 CPU 1.80GHz (1796.93-MHz 686-class CPU)
Origin = “GenuineIntel” Id = 0xf29 Stepping = 9
Features=0xbfebfbff DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
Features2=0×4400>
real memory = 265244672 (252 MB)
avail memory = 255963136 (244 MB)
xc0: on motherboard
cpu0 on motherboard
Timecounters tick every 10.000 msec
[XEN] Initialising virtual ethernet driver.
xn0: Ethernet address: 00:16:3e:6b:de:3a
[XEN]
Trying to mount root from ufs:/dev/xbd769a
WARNING: / was not properly dismounted
Loading configuration files.
No suitable dump device was found.
Entropy harvesting: interrupts ethernet point_to_point kickstart.
Starting file system checks:
/dev/xbd769a: 18859 files, 140370 used, 113473 free (10769 frags, 12838 blocks, 4.2% fragmentation)
Setting hostname: demo.freebsd.org.
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0×2
inet 127.0.0.1 netmask 0xff000000
Additional routing options:.
Mounting NFS file systems:.
Starting syslogd.
/etc/rc: WARNING: Dump device does not exist. Savecore not run.
ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/X11R6/lib /usr/local/lib
a.out ldconfig path: /usr/lib/aout /usr/lib/compat/aout /usr/X11R6/lib/aout
Starting usbd.
usb: Kernel module not available: No such file or directory
Starting local daemons:.
Updating motd.
Starting sshd.
Initial i386 initialization:.
Additional ABI support: linux.
Starting cron.
Local package initialization:.
Additional TCP options:.
Starting background file system checks in 60 seconds.
Sun Apr 1 02:11:43 UTC 2007
FreeBSD/i386 (demo.freebsd.org) (xc0)
login:

现在 domU 应该能运行 FreeBSD 7.0-CURRENT 内核了:
# uname -a
FreeBSD demo.freebsd.org 7.0-CURRENT FreeBSD 7.0-CURRENT #113: Wed Jan 4 06:25:43 UTC 2006
kmacy@freebsd7.gateway.2wire.net:/usr/home/kmacy/p4/freebsd7_xen3/src/sys/i386-xen/compile/XENCONF i386

接下来可以在 domU 中配置网络了。 FreeBSD domU 会使用一种称做 xn0 的专用网络接口:
# ifconfig xn0 10.10.10.200 netmask 255.0.0.0
# ifconfig
xn0: flags=843 mtu 1500
inet 10.10.10.200 netmask 0xff000000 broadcast 10.255.255.255
ether 00:16:3e:6b:de:3a
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0×2
inet 127.0.0.1 netmask 0xff000000

在 dom0 Slackware 上 会出现一些 Xen 专用的网络接口:
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:07:E9:A0:02:C2
inet addr:10.10.10.130 Bcast:0.0.0.0 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:815 errors:0 dropped:0 overruns:0 frame:0
TX packets:1400 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:204857 (200.0 KiB) TX bytes:129915 (126.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:99 errors:0 dropped:0 overruns:0 frame:0
TX packets:99 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:9744 (9.5 KiB) TX bytes:9744 (9.5 KiB)
peth0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:1853349 errors:0 dropped:0 overruns:0 frame:0
TX packets:952923 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2432115831 (2.2 GiB) TX bytes:86528526 (82.5 MiB)
Base address:0xc000 Memory:ef020000-ef040000
vif0.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:1400 errors:0 dropped:0 overruns:0 frame:0
TX packets:815 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:129915 (126.8 KiB) TX bytes:204857 (200.0 KiB)
vif1.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:157 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:140 (140.0 b) TX bytes:158 (158.0 b)
xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:112 (112.0 b) TX bytes:0 (0.0 b)
# brctl show
bridge name bridge id STP enabled interfaces
xenbr1 8000.feffffffffff no vif0.1
peth0
vif1.0


推荐阅读
author-avatar
以下犯上LOVE_845
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有