csatblogspotdotcom

Monday, December 22, 2008

在Xen的Domain U上安装OpenSolaris2008.11

前两天在Xen 3.3上以全虚拟化方式安装了OpenSolaris操作系统,具体过程如下:
首先把OpenSolaris的安装光盘下载到本地目录~/OpenSolaris/iso/。
第二步,用命令dd if=/dev/zero of=~/OpenSolaris/OpenSolaris.img bs=1k seek=40M count=1创建一个磁盘镜像,该磁盘镜像被虚拟机当作硬盘使用。磁盘文件的名字为OpenSolaris.img,大小为40G。(注意:用该命令创建的磁盘镜像文件的大小是随着磁盘内容的增加而动态增长的,刚创建好磁盘镜像时用ls –l命令查看到的大小40G并不是真实占用的空间,用du –sh命令可以看到刚创建好的磁盘镜像占用空间只有16K)
第三步,写一个配置文件~/OpenSolaris/OpenSolaris.cfg,内容如下:
#-----------------------------------------------------------------------------
import os, re
arch = os.uname()[4]
if re.search('64', arch):
arch_libdir = 'lib64'
else:
arch_libdir = 'lib'

#----------------------------------------------------------------------------
# Kernel image file.
kernel = "/usr/lib/xen/boot/hvmloader"

#-----------------------------------------------------------------------------
# The domain build function. HVM domain uses 'hvm'.
builder='hvm'

#-----------------------------------------------------------------------------
# Initial memory allocation (in megabytes) for the new domain.
#
# WARNING: Creating a domain with insufficient memory may cause out of
# memory errors. The domain needs enough memory to boot kernel
# and modules. Allocating less than 32MBs is not recommended.
#内存大小设置为1G
memory = 1024

#-----------------------------------------------------------------------------
# A name for your domain. All domains must have different names.
#虚拟机的名字为OpenSolaris
name = "OpenSolaris"

#-----------------------------------------------------------------------------
# The number of cpus guest platform has, default=1
#虚拟CPU的个数为2
vcpus=2

#-----------------------------------------------------------------------------
# Optionally define mac and/or bridge for the network interfaces.
# Random MACs are assigned if not given.
#vif = [ 'type=ioemu, mac=00:16:3e:00:00:11, bridge=xenbr0, model=ne2k_pci' ]
# type=ioemu specify the NIC is an ioemu device not netfront
#vif = [ 'type=ioemu, bridge=xenbr0' ]
#网卡使用eth0物理网卡
vif = [ 'type=ioemu, bridge=eth0' ]

#----------------------------------------------------------------------------
# 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:UNAME,DEV,MODE
# where UNAME is the device, DEV is the device name the domain will see,
# and MODE is r for read-only, w for read-write.
#磁盘镜像文件使用file:/home/cs/OpenSolaris/OpenSolaris.img,同时把file:/home/cs/OpenSolaris/iso/OpenSolaris.iso当作光驱使用。
disk = [ 'file:/home/cs/OpenSolaris/OpenSolaris.img,hda,w', 'file:/home/cs/OpenSolaris/iso/OpenSolaris.iso,hdc:cdrom,r' ]

#----------------------------------------------------------------------------
# Device Model to be used
device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'

#-----------------------------------------------------------------------------
# boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d)
# default: hard disk, cd-rom, floppy
#boot="cda"
#设置为从光驱启动
boot="d"

#----------------------------------------------------------------------------
# enable SDL library for graphics, default = 0
sdl=0

#----------------------------------------------------------------------------
# enable OpenGL for texture rendering inside the SDL window, default = 1
# valid only if sdl is enabled.
opengl=1

#----------------------------------------------------------------------------
# enable VNC library for graphics, default = 1
#启动后通过vnc连接访问其图形界面
vnc=1

#----------------------------------------------------------------------------
# address that should be listened on for the VNC server if vnc is set.
# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp
#允许任何IP使用vnc服务
vnclisten="0.0.0.0"

#----------------------------------------------------------------------------
# set VNC display number, default = domid
#vncdisplay=1

#----------------------------------------------------------------------------
# try to find an unused port for the VNC server, default = 1
#vncunused=1

#----------------------------------------------------------------------------
# set password for domain's VNC console
# default is depents on vncpasswd in xend-config.sxp
#没有设置vnc密码
vncpasswd=''

#----------------------------------------------------------------------------
# enable stdvga, default = 0 (use cirrus logic device model)
stdvga=0

#-----------------------------------------------------------------------------
# serial port re-direct to pty deivce, /dev/pts/n
# then xm console or minicom can connect
serial='pty'
第四步,使用命令sudo xm create ~/OpenSolaris/OpenSolaris.cfg来启动虚拟机,并用命令sudo xm list来查看相应状态。
第五步,通过命令vncviewer 127.0.0.1命令来访问其图形界面。注意:有时端口被其它虚拟机占用时需要用IP:1、IP:2(依此类推)来访问。接下来就和在物理机上安装OpenSolaris一样了。
最后在安装好系统后,将配置文件稍作修改:一个是将disk设置改为disk = [ 'file:/home/cs/OpenSolaris/OpenSolaris.img,hda,w' ],因为不再需要光驱;另一个是将boot=d改为boot=c,不再从光驱启动,而是从硬盘启动。

p.s. 在安装好OpenSolaris后,发现不能上网,怀疑是域名解析设置问题,于是在/etc/nsswitch.conf中查看配置,果然在hosts一行是hosts:file,于是将其修改为hosts:file dns;但是重启网络后发现还是上不了网,更奇怪的是所有的IP都ping的通,但就是ping不同URL,于是怀疑是iptables的原因,试探性的用iptables –F将iptables禁掉,就可以上网了,果然是iptables的问题;最后在/etc/sysconfig/iptables文件中加上两行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
重启iptables后就可以正常上网了。

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home