Xen虚拟机的创建和启动


半虚拟化



获取Sample Image
到Jailtime.org下载,并解压(注默认root密码为password)
# tar jxvf centos.5-0.20070424.img.tar.bz2
centos.5-0.img
centos.5-0.xen2.cfg
centos.5-0.xen3.cfg
centos.swap
当然,也可以到http://www.rpath.com/rbuilder下载

创建配置文件
参考centos.5-0.xen2.cfg和centos.5-0.xen3.cfg,其内容为:
kernel = “/boot/vmlinuz-2.6.18-xen”
ramdisk = “/boot/initrd-2.6.18-xen.img”
memory = 256
name = “centos.5-0”
dhcp = “dhcp”
vif = [ ‘’ ]
disk = [‘tap:aio:/home/xen/centos.5-0.img,xvda1,w’,
‘tap:aio:/home/xen/centos.swap,xvda2,w’]
root = “/dev/xvda1 ro”

Integrating Loadable Kernel Modules into Your Root Filesystem
$ uname -r
2.6.18-xen
$ su
Password: *********
# mkdir -p /mnt/img
# mount -o loop centos.5-0.img /mnt/img
# cd /mnt/img/lib/modules
# cp -r /lib/modules/`uname -r` .
# ls
2.6.18-xen

修改其他的配置文件
# cat /mnt/img/etc/fstab
/dev/xvda1 / ext3 defaults 1 1
/dev/xvda2 none swap sw 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
# cat /mnt/img/etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
# cat /mnt/img/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
# cd /
# sync
# umount /mnt/img
Creating Initial RAM Disks and Filesystems for Your Kernel
# yaird --output initrd-2.6.18-xen.img 2.6.18-xen
# mkinitramfs -o initrd-2.6.18-xen.img 2.6.18-xen
# mkinitrd -o initrd-2.6.18-xen.img 2.6.18-xen

启动虚拟机
# xm create centos.5-0.xen3.cfg -c
# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 1752 2 r----- 56978.8
Foresight 46 384 1 -b---- 1180.1
OpenSUSE 17 256 1 -b---- 2114.4
Ubuntu 34 256 1 -b---- 591.7
centos.5-0 45 256 1 -b---- 302.9
Freespire-HVM 49 256 1 -b---- 63.2

 

连接到虚拟机的终端
#xm console 45 &

全虚拟化HVM



全虚拟化要简单的多,不需要那么多的步骤,只需要分配合适的资源即可。一个简单的配置文件freespire.cfg如下:
import os, re
arch = os.uname()[4]
if re.search(‘64`, arch):
arch_libdir = ‘lib64`
else:
arch_libdir = ‘lib’
kernel = “/usr/lib/xen/boot/hvmloader”
builder=’hvm’
memory = 256
shadow_memory = 8
name = “FS-IMG-HV”
acpi=1
apic=1
vif = [ ‘type=ioemu, bridge=xenbr0`
disk = [ ‘tap:aio:/home/xen/HVM/freespire1013.img,hda,w’,
‘phy:/dev/hda,hdc:cdrom,r’ ]
device_model = ‘/usr/’ + arch_libdir + ‘/xen/bin/qemu-dm’
boot=”dc”
serial=’pty’
usb=1
usbdevice=’tablet’
这样创建的虚拟机可以通过VNC连接,不过VNC的端口为127.0.0.1:5900 + DomainID:
$ vncviewer 127.0.0.1:5931

如果想要配置SDL,需要设置:
sdl=1
vnc=0


启动虚拟机
# xm create freespire.cfg –c


自动启动Domains


将配置文件放到/etc/xen/auto/目录

你可能感兴趣的:(虚拟机)