川师15级软工研-Javen

花果山
Ubuntu系统下Xen虚拟机的基本安装方法(代码创建)

Ubuntu上Xen安装虚拟机
方法一
dd一个空的磁盘
sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8

下载Xen VM通用配置文件

sudo wget http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/xm-debian.cfg \

-O /etc/xen/vm1.conf
对下载下来的配置文件进行相应的修改

memory = 256
name = "vm1"
disk = [ 'tap2:tapdisk:aio:/home/vm1/vm1.img,xvda1,w']

执行安装命令

sudo xm create -f /etc/xen/vm1.conf -c install=true \
install-kernel="http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz" \
install-ramdisk="http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz" \
install-mirror="http://mirrors.aliyun.com/ubuntu"

 

方法二
dd一个空的磁盘

sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8

格式化磁盘

sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8

挂载磁盘

sudo mkdir /mnt/vm1
sudo mount -o loop /home/vm1.img /mnt/vm1


利用Domain0的文件系统创建DomainU的文件系统

#!/bin/bash
cat > /tmp/exclude.list <<EOF
/proc
/tmp/
/lost+found
/sys
/mnt
/media
/dev
/tmp
/home
/var/cache/apt
/var/cache/apt-xapian-index
/var/lib/apt
EOF</p>< p>#注意vmdisk变量后面的/
vmdisk='/mnt/'
rsync -arv --progress --exclude-from=/tmp/exclude.list / $vmdisk
mkdir -p ${vmdisk}/home ${vmdisk}/mnt ${vmdisk}/tmp ${vmdisk}/dev ${vmdisk}/proc ${vmdisk}/sys

卸载虚拟机磁盘

sudo umount /mnt/vm1

name = 'vm1'
vcpus = 1
memory = '2048'
disk = [ 'tap2:tapdisk:aio:/home/vm1/vm1.img,xvda,w']
vif = [ '' ]
on_reboot = 'restart'
on_crash = 'restart'
kernel = "/home/vm1/vmlinuz"
ramdisk = "/home/vm1/initrd.img"
extra = "ks=http://www.opstool.com/files/man/vm-ks.cfg"

启动虚拟机

sudo xm create -c /etc/xen/vm1.conf

判断CPU是否支持虚拟化
Intel CPU的flag是vmx,AMD的CPU是svm。如果本身CPU支持但cat /proc/cpuinfo看不到,请检查BIOS是否关闭了Intel的VT或AMD的SVM

cat /proc/cpuinfo | grep --color -E (vmx|svm)

 

查看Xen版本

cat /sys/hypervisor/version/major
cat /sys/hypervisor/version/minor
cat /sys/hypervisor/version/extra

 

posted on 2016-03-31 22:39  川师15级软工研-齐能  阅读(558)  评论(0编辑  收藏  举报