使用命令行创建虚拟机Xen

本文介绍了在Xen4.9平台上使用命令行创建完全虚拟化Android4.4的domU客户机过程,使用Xen4.9的dom0运行在Centos6.9上。本文使用的是Xen安装附带的xl程序(Xen4CentOS版本已经不再支持xm)。

首先确保已经安装好xen了,xen在线安装的教程有很多, 这里就不说了。可以使用xl info查询xen安装信息。

Xen安装成功以后,需要对网络进行配置,假设已经按照CentOS官网的桥接方式对网络配置好了,也可以参考我的另外一篇博客(在 CentOS6上为Xen设置桥接网络)。

安装 libvirt及 virt-manager(在 Dom0 机器上)

必要的组件

yum install rsync wget vim-enhanced openssh-clients
yum install libvirt python-virtinst libvirt-daemon-xen


安装(要使用图形化桌面才能打开)
yum install virt-manager
安装完成后以普通用户的身份即可打开 virt-manager。可利用 Applications => System Tools => Virtual Machine Manager 这条捷径,或从终端窗口输入 virt-manager。

利用 virt-manager 来安装 DomU

使用virt-manager可使用图形化界面安装DomU,其过程比较简单,但需要注意以下两点:

1. virt-manager无法连接Xen内核
解决方法是执行:

yum upgrade device-mapper-libs
yum -y install avahi
/etc/init.d/messagebus restart
/etc/init.d/avahi-daemon restart
/etc/init.d/libvirtd restart
2. 启动管理器出错,unsupported format character
出错的原因是CentOS6.9使用的virt-manager-0.9.0-34对中文字符集支持有bug,卸载掉virt-manager-0.9.0-34安装下面这个版本即可。
先卸载0.9.0-34版本:

yum remove virt-manager
找到virt-manager-0.9.0-31的CentOS版本,安装就可以了
yum localinstall virt-manager-0.9.0-31.el6.x86_64.rpm
下载地址:
http://download.csdn.net/detail/z_yttt/9887393

准备镜像及配置文件

我是通过ISO文件来安装Android的,所以我在Dom0上创建了一个名为的/home/dahai/android/的目录,用于存放镜像文件。 

[root@localhost ~]# cd /home/dahai/android/

[root@localhost android]# ls 

android-x86_64-4.4-rc1.iso

在安装虚拟机之前,用以下命令检查CPU是支持半虚拟化还是全虚拟化:

grep hvm /sys/hypervisor/properties/capabilities --color=always

若有输出,则说明支持全虚拟化,以下是我的服务器的输出:

首先,查看自己的网桥情况:

brctl show

以下是我的网桥情况:

网桥名为virbr0,网桥名在以下配置文件中要用到。

在路径/home下创建虚拟机文件,大小约为30G:

dd if=/dev/zero of=/home/hvm.img bs=1M count=30000

然后我们需要为每个虚拟机配置文件。在安装成功Xen后有一个名为/etc/xen/xlexample.hvm的HVM示例配置文件。

gedit  /etc/xen/xlexample.hvm

[root@localhost xen]# cat /etc/xen/xlexample.hvm 
# =====================================================================
# Example HVM guest configuration
# =====================================================================
#
# This is a fairly minimal example of what is required for an
# HVM guest. For a more complete guide see xl.cfg(5)

# This configures an HVM rather than PV guest
builder = "hvm"

# Guest name
name = "example.hvm"

# 128-bit UUID for the domain as a hexadecimal number.
# Use "uuidgen" to generate one if required.
# The default behavior is to generate a new UUID each time the guest is started.
#uuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

# Enable Microsoft Hyper-V compatibile paravirtualisation /
# enlightenment interfaces. Turning this on can improve Windows guest
# performance and is therefore recommended
#viridian = 1

# Initial memory allocation (MB)
memory = 128

# Maximum memory (MB)
# If this is greater than `memory' then the slack will start ballooned
# (this assumes guest kernel support for ballooning)
#maxmem = 512

# Number of VCPUS
vcpus = 2

# Network devices
# A list of 'vifspec' entries as described in
# docs/misc/xl-network-configuration.markdown
vif = [ '' ]

# Disk Devices
# A list of `diskspec' entries as described in
# docs/misc/xl-disk-configuration.txt
disk = [ '/dev/vg/guest-volume,raw,xvda,rw' ]

# Guest VGA console configuration, either SDL or VNC
sdl = 1
#vnc = 1
 

将memory至少改为1024,2048最好,要不启动不了,会报错。

将vif和disk改为

vif = [ 'mac=00:25:90:0d:a0:b0,bridge=virbr0' ]

disk=['file:/home/dahai/android/hvm.img,hda,w','file:/home/dahai/android/android-x86_64-4.4-rc1.iso,hdc:cdrom,r' ]

在该文件最后添加启动位置及方式:

boot = 'dc'

其中,vif的网桥输入自己的网桥名(用brctl show查出来的);disk定位刚才创建的hvm.img路径以及android的光盘镜像路径。

输入xm create hvm.hvm创建虚拟机.

接下来会安装Android系统,安装完后记得改为从硬盘启动。即boot = 'c',否则还会从 光盘启动。

参考博客:

https://blog.csdn.net/lnqariel/article/details/41050479

https://blog.csdn.net/yzy1103203312/article/details/77386922

猜你喜欢

转载自blog.csdn.net/u010194538/article/details/95050235