虚拟化技术的分类: (1) 模拟:Emulation: Qemu,PearPC,Bochs (2) 完全虚拟化:Full Virtualization,Native Virtualization HVM VMware Workstation,VirtualBox,VMWare Server,Parallels Desktop,KVM,XEN (3) 半虚拟化:ParaVirtualization GuestOS:知晓自己是运行Virtualization Hypercall (4) OS级别虚拟化: 将用户控件分割为多个,彼此间互相隔离; 容器级虚拟化 OpenVZ,LXC(LinuX Container),libcontainer,Virtuozzo,Linux V Servers (5) 库级别虚拟化 WINE

Type-I,Type-II

IaaS:Infrastructure,基础架构服务 PaaS:Platfrom,平台即服务

Xen: 剑桥大学,开源VMM

Xen组成部分:
	    (1) Xen Hypervisor
	        分配CPU、Memory、Interrupt
			(2) Dom0
			    特权域,I/O分配
					    网络设备
							    net-front(GuestOS),net-backend
							块设备
							    block-front(GuestOS),block-backend
					Linux Kernel:
					    2.6.37:开始支持运行Dom0
					    3.0:对关键特性进行了优化
					 提供管理DomU工具栈
					     用于实现对虚拟机进行添加、启动、快照、停止、删除等操作;
			(3) DomU
			    非特权域,根据其虚拟化方式实现,有多种类型
					    PV:半虚拟化
							HVM:硬件辅助虚拟化

Xen的PV技术: 不依赖于CPU的HVM特性,但要求GuestOS的内核做出修改以知晓自己运行于PV环境; 运行于DomU中的OS:Linux(2.6.24+),NetBSD,FreeBSD,OpenSolaris

Xen的HVM技术: 依赖于Inter VT或AMD AMD-V,还要依赖于Qemu来模拟IO设备; 运行于DomU中的OS:几乎所有支持此X86平台的;

PV on HVM: CPU为HVM模式运行 IO设备为PV模式运行 运行于DomU中的OS:只要OS能驱动PV接口类型的IO设备; net-front,blk-front

Xen的工具栈: xm/xend:在Xen Hypervisor的Dom0中药启动xend服务 xm:命令行管理工具,有诸多子命令; create,destroy,stop,pause...

	xl:基于libxenlight提供的轻量级的命令行工具栈;
	
	xe/xapi:提供了对xen管理的api,因此多用于cloud环境,Xen Server,XCP
	
	virsh/libvirt:

XenStore: 为各Domain提供的共享信息存储空间,有着层级结构的名称空间,位于Dom0

CentOS对Xen的支持: RHEL 5.7-:默认的虚拟化技术为xen kernel version:2.6.18 kernel- kernel-xen RHEL 6+:仅支持kvm Dom0:不支持 DomU:支持 如何在CentOS 6.6上使用Xen: (1) 编译3.0以上版本的内核,启动对Dom0的支持 (2) 编译xen程序

制作好相关程序的项目: xen4centos xen made easy

Para Virt Xen Para-virtualization Architecture

xen工具:

xm vs xl:

libvirtd管理工具:

xen工具栈:

Dom0 Kernel CONFIG_ACPI_PROCFS=y CONFIG_XEN=ye CONFIG_XEN_MAX_DOMAIN_MEMORY=32 CONFIG_XEN_SAVE_RESTORE=y CONFIG_XEN_DOM0=y CONFIG_XEN_PRIVILEGED_GUEST=y CONFIG_XEN_PCI=y CONFIG_PCI_XEN=y CONFIG_XEN_BLKDEV_FRONTENE=y CONFIG_XEN_NETDEV_FRONTEND=y CONFIG_XEN_KBDDEV_FRONTEND=y CONFIG_HVC_XEN=y CONFIG_XEN_FBDEV_FRONTEND=y CONFIG_XEN_BALLOON=y CONFIG_XEN_SCRUB_PAGES=y CONFIG_XEN_DEV_EVTCHN=y CONFIG_XEN_GNTDEV=y CONFIG_XEN_BACKEND=y CONFIG_XEN_BLKDEV_BACKEND=y CONFIG_XEN_NETDEV_BACKEND=y CONFIG_XEN_FS=y CONFIG_XEN_COMPAT_XENFS=y CONFIG_XEN_XENBUS_FRONTEND=y CONFIG_XEN_PCIDEV_FRONTEND=y

DomU Kernel CONFIG_XEN=y CONFIG_PARAVIRT_GUEST=y CONFIG_PARAVIRT=y CONFIG_XEN_PVHVM=y CONFIG_XEN_MAX_DOMAIN_MEMORY=128 CONFIG_XEN_SAVE_RESTORE=y CONFIG_PCI_XEN=y CONFIG_XEN_PCIDEV_FRONTEND=y CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y CONFIG_HVC_XEN=y CONFIG_XEN_FBDEV_FRONTEND=y CONFIG_XEN_DEV_DETCHN=y CONFIG_XEN_XENBUS_FRONTEND=y

grub配置:

#boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Red Hat Enterprise Linux Server (3.7.4-1.el6xen.x86_64) root (hd0,0) kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin(dom0_mem指定dom0使用内存空间多大,cpufreq cpu由xen管理,dom0_max_vcpus dom0最多使用多少虚拟cpu) module /vmlinuz-3.7.4-1.el6xen.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg0/root rhgb quiet module /initramfs-3.7.4-1.el6xen.x86_64.img title Red Hat Enterprise Linux (2.6.32-279.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg0/root rhgb quiet initrd /initramfs-2.6.32-279.el6.x86_64.img

安装完成后对grub的配置示例: #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (3.18.17-13.el6.x86_64) root (hd0,0) kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet module /initramfs-3.18.17-13.el6.x86_64.img

grub.conf boot options:http://xenbits.xen.org/docs/unstable/misc/xen-command-line.html 官网Man手册:http://wiki.xenproject.org/wiki/Xen_Man_Pages

工具栈: xm/xend xl

xl list:显示Domain的相关信息 xen虚拟机状态: r: running b:阻塞 p:暂停 s:停止 c:崩溃 d:dying,正在关闭的过程中

如何创建xen pv模式: 1、kernel 2、initrd或initramfs 3、DomU内核模块 4、根文件系统 5、swap设备 将上述内容定义在DomU的配置文件

	注意:xm与xl启动DomU使用的配置文件略有不同;
	
对于xl而言,其创建DomU使用的配置指令可通过"man xl.cfg"获取
	    常用指令:
			    name:域唯一的名称
					builder:指明虚拟机的类型,generic表示pv,hvm表示hvm
					vcpus:虚拟cpu个数
					maxcpus:最大虚拟cpu个数
					cpus:vcpu可运行于其上物理CPU列表
					memory-MBYTES:内存大小
					maxmem-MBYTES:可以使用的最大内存空间
					on_poweroff:指明关机时采取的action
					    destroy,restart,preserve
					on_reboot="ACTION":指明"重启"DomU执行操作
					on_crash="ACTION":虚拟机意外崩溃时采取的action
					uuid:DomU的唯一标识
					disk=["DISK_SPEC_STRING","DISK_SPEC_STRING",...]:指明磁盘设备,列表;
					vif=["NET_SPEC_STRING","NET_SPEC_STRING",...]:指明网络接口,列表;
					vfb=["VFB_SPEC_STRING","VFB_SPEC_STRING",...]:指明virtual frame buffer,列表;
					pci=["PCI_SPEC_STRING","PCI_SPEC_STRING",...]:pci设备的列表
			
			PV模式专用指令:
			    kernel="PATHNAME":内核文件路径,此路径为Dom0中路径
					ramdisk="PATHNAME":为kernel指定内核提供的ramdisk文件路径
					root="STRING":指明根文件系统
					extra="STRING":额外传递给内核引导的参数
					bootloader="PROGRAM":如果DomU使用自己的kernel及ramdisk,此时需要一个Dom0钟的应用程序来实现其bootloader功能;

    磁盘参数指定方式:
			    官方文档:http://xenbits.xen.org/docs/unstable/misc/xl-disk-configuration.txt
					[<target>,[<format>,[<vdev>,[<access>]]]]
					    <target>表示磁盘映像文件或设备文件路径:/images/xen/linux.img, /dev/myvg/linux
							<format>表示磁盘格式,如果映像文件,有多重格式,例如raw,qcow,qcow2
							vdev:此设备在DomU被识别为硬件设备类型,支持hd[x],xvd[x],sd[x]
							access:访问权限
					        ro,r:只读
									rw,w:读写
									
							disk=["/images/xen/linux.img,raw,xvda,rw",...]
					
					使用qemu-img管理磁盘映像:
					    create [-f fmt] [-o options] filename [size]
							可创建sparse格式的磁盘映像文件
									
示例:
		    创建一个pv格式的vm:
				    (1) 准备磁盘映像文件
						    qemu-img create -f raw -o size=2G /images/xen/busybox.img
								mke2fs -t ext /images/xen/busybox.img
						(2)根文件系统
						    编译busybox,并复制到busybox.img映像中
								mout -o /images/xen/busybox.img /mnt
								cp -a $BUSYBOX/_install/ /mnt
								mkdir /mnt/{proc,sys,dev,var}
						(3) 提供配置DomU配置文件*
						    name = "busybox-001"
								kernel = "/boot/vmlinuz"
								ramdisk = "/boot/initramfs.img"
								extra = "selinux=0 init=/bin/sh"
								memory = 256
								vcpus = 2
								disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
								root = "/dev/xvda ro"
						(4) 启动实例:
						    xl [-v] create <DomU_Config_file> -n
								xl create <DomU_Config_file> -c
								
								Ctrl + ]
			如何配置网络接口:
			    vif = [ '<vifspec>', '<vifspec>',...]
					
					vifspec: [<key>=<value>|<flag>,]
					
					常用的key:
					    mac=: mac地址,要以00:16:3e开头
							bridge=<bridge>: 指定此网络接口在Dom0被关联至那个桥上
							model=<MODEL>: rt8139、e1000;
							vifname=: 接口名称,在Domu0中显示的名称
							script=: 执行的脚本
							ip=: 指定ip地址,会注入到DomU中
							rate=: 指明设备传输速率,通常为"#UNIT/s"格式
							    UNIT: GB, MB, KB, B for bytes,
									          Gb, Mb, Kb, b for bits,

注意:内核版本降至3.7.4,Sources/6.x86_64/xen4.1

网络接口启用: vif = [ 'bridge=xenbr0', ]

xl的其他常用命令: shutdown: 关机 reboot: 重启 pause: 暂停 unpause: 解除暂停 console: 连接控制台 save: 将DomuU内存中的数据转存指定的磁盘文件中; Usage: xl [-vf] save [options] <Domain> <CheckpointFile> [<ConfigFile>] restore: 从指定的磁盘文件中恢复DomU内存数据 Usage: xl [-vf] restore [options] [<ConfigFile>] <CheckpointFile>

vcpu-list vcpu-pin vcpu-set info: 当前xen hypervisor的摘要信息 domid domname top: 查看domain资源占用排序状态命令 network-list: 查看指定域使用的网络及接口 network-attach network-detach

block-list: 查看指定域使用的块设备的列表; block-attach block-detach

uptime: 运行时长

使用DomU自有kernel来运行启动运行DomU: 制作磁盘映像文件: losetup - set up and control loop devices losetup -a: 显示所有已用的loop设备相关信息 losetup -f: 显示第一个空闲的loop设备文件

使用xl命令进行创建虚拟机并完成CentOS 6.6的系统安装 (1) 创建磁盘映像文件 (2) 获取安装指定版本的系统所需要kernel及initrd文件 (3) 创建DomU配置文件,示例如下: name = "centos-001" kernel = "/images/kernel/vmlinuz" ramdisk = "/images/kernel/initrd.img" extra = "ks=http://172.16.100.10/ks_config/CentOS-6.6-ks.cfg" memory = 512 vcpus = 2 vif = [ 'bridge=xenbr0' ] disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ] (4) 安装完成后,创建虚拟机的配置文件需要作出修改; name = "centos-001" bootloader = "/usr/bin/pygrub" memory = 512 vcpus = 2 vif = [ 'bridge=xenbr0' ]

启动图形窗口: 在创建虚拟机的配置文件中定义vfb (1) vfb = [ 'sdl=1' ] (2) vnc (a) yum install tigervnc (b) vfb = [ 'vnc=1' ] vnc监听的端口为5900,相应的DISPLAYNUM为0

使用Dom0中物理磁盘分区为DomU提供存储空间:

使用libvirt实现xen虚拟机管理; yum install libvirt libvirt-damon-xen virt-manager python-virtinst libvirt-client service libvirtd start virt-manager, virsh, virt-install

实验环境: 操作系统:centos6.6 内核版本:2.6.32-504.el6.x86_64 IP地址:172.16.100.6 CPU:4核心 内存:2G

在VMware Workstation操作需要开启cpu虚拟化:

[root@xen ~]# hostname
xen.smoke.com
[root@xen ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=xen.smoke.com
[root@xen ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.100.6    xen.com xen.smoke.com
[root@xen ~]# uname -r
2.6.32-504.el6.x86_64
我这里使用http://archive.kernel.org/centos-vault/6.6/xen4/x86_64/Packages/ yum源安装
[root@xen ~]# vim /etc/yum.repos.d/xen4.repo
[xen4centos]
name=Xen4 for CentOS 6
baseurl=http://archive.kernel.org/centos-vault/6.6/xen4/x86_64/
gpgcheck=0
gpgkey=http://archive.kernel.org/centos-vault/RPM-GPG-KEY-CentOS-6
repo_gpgcheck=0
enabled=1
[root@xen ~]# yum clan all
[root@xen ~]# yum makecache

[root@localhost ~]# yum -y install xen

[root@xen ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.18.17-13.el6.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

[root@xen xen]# shutdown -r now

重新启动操作系统,启动新内核:

现在运行在虚拟化环境中,看到的内核虽然是3.18.17-13.el6.x86_64,但是看到的是Dom0中的内核;

[root@xen ~]# uname -r
3.18.17-13.el6.x86_64

查看运行的虚拟机,r---- r代表运行状态;

[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2     r-----      69.1

xm命令以及废弃,但是仍然是支持的,需要启动xend服务才可以使用;

[root@xen ~]# xm list
WARNING: xend/xm is deprecated.
Error: Unable to connect to xend: No such file or directory. Is xend running?

[root@xen ~]# service xend start

[root@xen ~]# xm list
WARNING: xend/xm is deprecated.
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2     r-----     81.6
[root@xen ~]# service xend stop
[root@xen ~]# mkdir -p /images/xen/

选项-o ?可以查看支持的格式;

[root@xen ~]# qemu-img create -f raw -o ? /images/xen/busybox.img
Supported options:
size             Virtual disk size
preallocation    Preallocation mode (allowed values: off, falloc, full)
[root@xen ~]# qemu-img create -f raw -o size=2G /images/xen/busybox.img

查看为0G,最大可以为2G,稀疏格式的磁盘映像文件;

[root@xen ~]# du -sh /images/xen/busybox.img
0       /images/xen/busybox.img
[root@xen ~]# rm -rf /images/xen/busybox.img
[root@xen ~]# qemu-img create -f raw /images/xen/busybox.img 2G
[root@xen ~]# du -sh /images/xen/busybox.img
0       /images/xen/busybox.img

不分区将整个磁盘当做一个分区使用; [root@xen ~]# mke2fs -t ext2 /images/xen/busybox.img

格式化以后就会部署上元数据,这个磁盘没有分区表;

[root@xen ~]# du -sh /images/xen/busybox.img
33M     /images/xen/busybox.img

本地回环设备挂载使用-o loop选项; [root@xen ~]# mount -o loop /images/xen/busybox.img /mnt

[root@xen ~]# ls /mnt/
lost+found

[root@xen ~]# yum -y groupinstall "Development Tools" "Server Platform Development"

下载busybox,并上传,官网:https://busybox.net/downloads/ 这里使用busybox-1.22.1

[root@xen ~]# tar xf busybox-1.22.1.tar.bz2
[root@xen ~]# cd busybox-1.22.1

将busybox编译静态格式,不让它依赖于其他库,静态格式需要安装glibc-static;

[root@xen busybox-1.22.1]# yum -y install glibc-static
[root@xen busybox-1.22.1]# make menuconfig
Busybox Settings  --->Build Options  --->[*] Build BusyBox as a static binary (no shared libs)    

不使用共享的额外库文件;

[root@xen busybox-1.22.1]# make
[root@xen busybox-1.22.1]# make install
[root@xen busybox-1.22.1]# ls _install/
bin  linuxrc  sbin  usr
[root@xen busybox-1.22.1]# cp -a _install/* /mnt/
[root@xen busybox-1.22.1]# ls /mnt/
bin  linuxrc  lost+found  sbin  usr
[root@xen busybox-1.22.1]# cd /mnt/
[root@xen mnt]# mkdir proc sys dev etc var boot home
[root@xen ~]# chroot /mnt/ /bin/sh
/ # ls
bin         dev         home        lost+found  sbin        usr
boot        etc         linuxrc     proc        sys         var
/ # exit
[root@xen ~]# cd /boot/
[root@xen boot]# ln -s vmlinuz-2.6.32-504.el6.x86_64 vmlinuz
[root@xen boot]# ln -s initramfs-2.6.32-504.el6.x86_64.img initramfs.img
[root@xen boot]# cd /etc/xen/
[root@xen xen]# cp xlexample.pvlinux busybox
[root@xen xen]# vim busybox
name = "busybox-001"
kernel = "/boot/vmlinuz"    pv模式可以使用Dom0中的内核
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
#vif = [ '' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"

测试虚拟机是否可以跑起来;

[root@xen xen]# xl -v create busybox -n
Parsing config from busybox
{
    "domid": null,
    "config": {
        "c_info": {
            "type": "pv",
            "hap": "<default>",
            "oos": "<default>",
            "ssidref": 0,
            "name": "busybox-001",
            "uuid": "10e85dda-f56e-45ec-9b45-d7593cd53d60",
            "xsdata": {

            },
            "platformdata": {

            },
            "poolid": 0,
            "run_hotplug_scripts": "True",
            "pvh": "<default>",
            "driver_domain": "<default>"
        },
        "b_info": {
            "max_vcpus": 2,
            "avail_vcpus": [
                0,
                1
            ],
            "cpumap": [

            ],
            "nodemap": [

            ],
            "numa_placement": "<default>",
            "tsc_mode": "default",
            "max_memkb": 262144,
            "target_memkb": 262144,
            "video_memkb": -1,
            "shadow_memkb": 4096,
            "rtc_timeoffset": 0,
            "exec_ssidref": 0,
            "localtime": "<default>",
            "disable_migrate": "<default>",
            "cpuid": [

            ],
            "blkdev_start": null,
            "device_model_version": "unknown",
            "device_model_stubdomain": "<default>",
            "device_model": null,
            "device_model_ssidref": 0,
            "extra": [

            ],
            "extra_pv": [

            ],
            "extra_hvm": [

            ],
            "sched_params": {
                "sched": "unknown",
                "weight": -1,
                "cap": -1,
                "period": -1,
                "slice": -1,
                "latency": -1,
                "extratime": -1
            },
            "ioports": [

            ],
            "irqs": [

            ],
            "iomem": [

            ],
            "claim_mode": "True",
            "event_channels": 0,
            "u": {
                "kernel": "/boot/vmlinuz",
                "slack_memkb": -1,
                "bootloader": null,
                "bootloader_args": [

                ],
                "cmdline": "root=/dev/xvda ro selinux=0 init=/bin/sh",
                "ramdisk": "/boot/initramfs.img",
                "e820_host": "<default>"
            }
        },
        "disks": [
            {
                "backend_domid": 0,
                "backend_domname": null,
                "pdev_path": "/images/xen/busybox.img",
                "vdev": "xvda",
                "backend": "unknown",
                "format": "raw",
                "script": null,
                "removable": 0,
                "readwrite": 1,
                "is_cdrom": 0
            }
        ],
        "nics": [

        ],
        "pcidevs": [

        ],
        "vfbs": [

        ],
        "vkbs": [

        ],
        "vtpms": [

        ],
        "on_poweroff": "destroy",
        "on_reboot": "restart",
        "on_watchdog": "destroy",
        "on_crash": "destroy"
    }
}

[root@xen xen]# xl -v create busybox
[root@xen xen]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2     r-----    2292.9
busybox-001                                  4   256     2     -b----       1.5
[root@xen xen]# xl console busybox-001
/ # ls
bin         dev         home        lost+found  sbin        usr
boot        etc         linuxrc     proc        sys         var
/ # [root@xen xen]#    (退出ctrl+])
[root@xen xen]# grep -v "^#" busybox | grep -v "^$"
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
关闭虚拟机;
[root@xen xen]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2     r-----    2302.5
busybox-001                                  5   256     2     -b----       2.7
[root@xen xen]# xl destroy busybox-001
DEBUG libxl__device_destroy_tapdisk 105 type=aio:/images/xen/busybox.img disk=:/images/xen/busybox.img
[root@xen xen]# xl create /etc/xen/busybox -c
/ #
/ # [root@xen xen]#
[root@xen xen]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:11:21:56
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe11:2156/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17604 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17754 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3443094 (3.2 MiB)  TX bytes:1829722 (1.7 MiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:11:21:60
          inet addr:192.168.190.128  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe11:2160/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:277920 errors:0 dropped:0 overruns:0 frame:0
          TX packets:54903 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:378101310 (360.5 MiB)  TX bytes:3362705 (3.2 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)
[root@xen xen]# cd /etc/sysconfig/network-scripts/
[root@xen network-scripts]# cp ifcfg-eth0 ifcfg-xenbr0
[root@xen network-scripts]# vim ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:11:21:56
TYPE=Ethernet
UUID=f343369c-4aa9-4975-81b3-3f38f4c56ef0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=xenbr0
[root@xen network-scripts]# vim ifcfg-xenbr0
DEVICE=xenbr0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.100.6
NETMASK=255.255.255.0
[root@xen network-scripts]# chkconfig --list NetworkManager    确认关闭NetworkManager服务
[root@xen network-scripts]# service network restart

默认在centos6.6的bridge-utils工具与3.18的内核可能有冲突导致启动桥设备以后内核就会终止,内核就会死机;只能升级bridge-utils工具;

使用其他版本内核解决:

[root@xen ~]# yum list all kernel*
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
已安装的软件包
kernel.x86_64                    2.6.32-504.el6          @anaconda-CentOS-201410241409.x86_64/6.6
kernel.x86_64                    3.18.17-13.el6          @xen4centos
kernel-devel.x86_64              2.6.32-754.6.3.el6      @updates
kernel-firmware.noarch           3.18.17-13.el6          @xen4centos
kernel-headers.x86_64            2.6.32-754.6.3.el6      @updates
可安装的软件包
kernel-abi-whitelists.noarch     2.6.32-754.6.3.el6      updates
kernel-debug.x86_64              2.6.32-754.6.3.el6      updates
kernel-debug-devel.i686          2.6.32-754.6.3.el6      updates
kernel-debug-devel.x86_64        2.6.32-754.6.3.el6      updates
kernel-devel.x86_64              3.18.17-13.el6          xen4centos
kernel-doc.noarch                3.18.17-13.el6          xen4centos
kernel-headers.x86_64            3.18.17-13.el6          xen4centos

kernel一定不要做升级,要做安装,因为升级以后kernel不能使用将会导致系统无法启动,即便有n个版本kernel也一定要安装,而非升级,安装kernel还会安装kernel-firmware,它们是相匹配的,否则会导致内核版本无法实用; [root@xen ~]# yum -y install kernel-3.10.68 kernel-firmware-3.10.68

[root@xen xen]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

[root@xen xen]# shutdown -r now

重启后,使用新内核还是会死机,用原来内核启动; 下载bridge-utils-1.5-2.el6.x86_64.rpm、kernel-xen-3.7.4-1.el6xen.x86_64.rpm、kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm、kernel-xen-release-6-4.noarch.rpm包;

[root@xen ~]# ls
anaconda-ks.cfg                    install.log
bridge-utils-1.5-2.el6.x86_64.rpm  install.log.syslog
busybox-1.22.1                     kernel-xen-3.7.4-1.el6xen.x86_64.rpm
busybox-1.22.1.tar.bz2             kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm
kernel-xen-release-6-4.noarch.rpm

尝试升级本地的bridge-utils;

[root@xen ~]# rpm -Uvh bridge-utils-1.5-2.el6.x86_64.rpm
[root@xen ~]# rpm -q bridge-utils
bridge-utils-1.5-2.el6.x86_64

[root@xen ~]# vim /etc/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=1     (更改默认启动内核为3.18.17-13.el6.x86_64)
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

[root@xen ~]# shutdown -r now

[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:44 errors:0 dropped:0 overruns:0 frame:0
          TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7171 (7.0 KiB)  TX bytes:9072 (8.8 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1270 (1.2 KiB)  TX bytes:1344 (1.3 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)
[root@xen ~]# ifconfig eth0 0
[root@xen ~]# brctl addbr xenbr0
[root@xen ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.000000000000       no
[root@xen ~]# brctl addif xenbr0 eth0
[root@xen ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.000c2976d258       no              eth0
[root@xen ~]# ifconfig xenbr0 172.16.100.6/24 up

升级bridge-utils后创建桥还是死机,降低内核; [root@xen ~]# rpm -ivh kernel-xen-3.7.4-1.el6xen.x86_64.rpm kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm kernel-xen-release-6-4.noarch.rpm --nodeps --force

[root@xen ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.7.4-1.el6xen.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.7.4-1.el6xen.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.7.4-1.el6xen.x86_64.img
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
        module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

[root@xen ~]# shutdown -r now

[root@xen ~]# uname -r
3.7.4-1.el6xen.x86_64
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1895     2     r-----      34.8
[root@xen ~]# ifconfig eth0 0
[root@xen ~]# brctl addbr xenbr0
[root@xen ~]# brctl addif xenbr0 eth0
[root@xen ~]# ifconfig xenbr0 172.16.100.6/24 up
[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:600 (600.0 b)  TX bytes:1930 (1.8 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:283 errors:0 dropped:0 overruns:0 frame:0
          TX packets:172 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:23729 (23.1 KiB)  TX bytes:17208 (16.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:468 (468.0 b)
[root@xen ~]# cd /etc/sysconfig/network-scripts/
[root@xen network-scripts]# vi ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:76:D2:58
TYPE=Ethernet
UUID=01e1be41-1948-41c6-8f29-9834f8c5586a
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=xenbr0
[root@xen network-scripts]# vi ifcfg-xenbr0
DEVICE=xenbr0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=172.16.100.6
NETMASK=255.255.255.0

[root@xen network-scripts]# service network restart

[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a
lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)
					
/ # exit
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1608     2     r-----      46.7
[root@xen ~]# vim /etc/xen/busybox
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
vif = [ 'bridge=xenbr1' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a    (还是没有网卡,因为没有网卡驱动)
lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)

/ # uname -r
2.6.32-504.el6.x86_64
/ # exit

[root@xen ~]# mount -o loop /images/xen/busybox.img /mnt/

虚拟机内核实用的是2.6.32-504.el6.x86_64,因此在 /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/目录找网卡驱动;

[root@xen ~]# cd /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/
[root@xen net]# mkdir /mnt/lib/modules -pv

查看depends选项有没有依赖其他模块,如果有要移过去;

[root@xen net]# modinfo xen-netfront.ko
filename:       xen-netfront.ko
alias:          xennet
alias:          xen:vif
license:        GPL
description:    Xen virtual network device frontend
srcversion:     5C6FC78BC365D9AF8135201
depends:
vermagic:       2.6.32-504.el6.x86_64 SMP mod_unload modversions
[root@xen net]# cp xen-netfront.ko  /mnt/lib/modules/
[root@xen net]# sync
[root@xen ~]# umount /mnt
[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a
lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)

/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3E:30:08:CB
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18

lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)

在网卡半虚拟化清空下Dom0添加网卡vif3.0,3.0代表Dom ID为3的dom上第0块网卡的后半段;

[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:216 errors:0 dropped:0 overruns:0 frame:0
          TX packets:107 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:34587 (33.7 KiB)  TX bytes:26570 (25.9 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2461 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1281 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:181386 (177.1 KiB)  TX bytes:125444 (122.5 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

vif3.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:1434 (1.4 KiB)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:98 errors:0 dropped:0 overruns:0 frame:0
          TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:11710 (11.4 KiB)  TX bytes:19076 (18.6 KiB)
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1608     2     r-----      57.3
busybox-001                                  3   256     2     -b----       1.9

把虚拟机关闭,vif3.0接口没有了,会自动被删除;

/ # exit
[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8736 errors:0 dropped:0 overruns:0 frame:0
          TX packets:195 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1431302 (1.3 MiB)  TX bytes:33472 (32.6 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:38504 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1717 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2505549 (2.3 MiB)  TX bytes:179962 (175.7 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3253 errors:0 dropped:0 overruns:0 frame:0
          TX packets:156 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:321520 (313.9 KiB)  TX bytes:23874 (23.3 KiB)

[root@xen ~]# xl create /etc/xen/busybox -c

虚拟机ID号变为4;

[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1608     2     r-----     367.6
busybox-001                                  4   256     2     -b----       1.2
[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8826 errors:0 dropped:0 overruns:0 frame:0
          TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1439226 (1.3 MiB)  TX bytes:42620 (41.6 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:38632 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1771 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2514511 (2.3 MiB)  TX bytes:185356 (181.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

vif4.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3339 errors:0 dropped:0 overruns:0 frame:0
          TX packets:219 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:327380 (319.7 KiB)  TX bytes:32980 (32.2 KiB)
[root@xen ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.000c2976d258       no              eth0
                                                        vif4.0
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3E:6B:31:0A
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18

lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)
/ # ifconfig eth0 172.16.100.21 up
/ # ping 172.16.100.254
PING 172.16.100.254 (172.16.100.254): 56 data bytes
64 bytes from 172.16.100.254: seq=0 ttl=64 time=1.546 ms
64 bytes from 172.16.100.254: seq=1 ttl=64 time=0.652 ms
64 bytes from 172.16.100.254: seq=2 ttl=64 time=0.939 ms
^C64 bytes from 172.16.100.254: seq=3 ttl=64 time=1.663 ms
64 bytes from 172.16.100.254: seq=4 ttl=64 time=1.020 ms
^C64 bytes from 172.16.100.254: seq=5 ttl=64 time=0.867 ms
64 bytes from 172.16.100.254: seq=6 ttl=64 time=1.017 ms
64 bytes from 172.16.100.254: seq=7 ttl=64 time=0.260 ms
[root@xen ~]# xl destroy busybox-001
[root@xen ~]# cp /images/xen/busybox.img /images/xen/busybox2.img
[root@xen ~]# du -sh /images/xen/busybox2.img
4.0M    /images/xen/busybox2.img
[root@xen ~]# cp /etc/xen/busybox /etc/xen/busybox2
[root@xen xen]# vim /etc/xen/busybox2
name = "busybox-002"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox2.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen ~]# brctl addbr xenbr1
[root@xen ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.000c2976d258       no              eth0
xenbr1          8000.000000000000       no
[root@xen ~]# ifconfig xenbr1 up
[root@xen ~]# vim /etc/xen/busybox
vif = [ 'bridge=xenbr1' ]
[root@xen ~]# vim /etc/xen/busybox2
vif = [ 'bridge=xenbr1' ]
[root@xen ~]# xl create /etc/xen/busybox2
Parsing config from /etc/xen/busybox2
[root@xen ~]# xl create /etc/xen/busybox
Parsing config from /etc/xen/busybox
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     403.2
busybox-002                                  6   256     2     -b----       1.3
busybox-001                                  8   256     2     -b----       1.0
[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12159 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3134 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1777571 (1.6 MiB)  TX bytes:315554 (308.1 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:41158 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2489 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2689974 (2.5 MiB)  TX bytes:253078 (247.1 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

vif6.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

vif7.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3767 errors:0 dropped:0 overruns:0 frame:0
          TX packets:431 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:358705 (350.2 KiB)  TX bytes:51636 (50.4 KiB)

xenbr1    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::807b:9dff:fe55:b07f/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:468 (468.0 b)
[root@xen ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.000c2976d258       no              eth0
xenbr1          8000.feffffffffff       no              vif6.0
                                                        vif7.0
[root@xen ~]# xl console busybox-001
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig eth0 172.16.100.21 up
/ # ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:49:F2:49
          inet addr:172.16.100.21  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:384 (384.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18
[root@xen ~]# ping 172.16.100.21
PING 172.16.100.21 (172.16.100.21) 56(84) bytes of data.
From 172.16.100.6 icmp_seq=1 Destination Host Unreachable
From 172.16.100.6 icmp_seq=2 Destination Host Unreachable
From 172.16.100.6 icmp_seq=3 Destination Host Unreachable
From 172.16.100.6 icmp_seq=4 Destination Host Unreachable
^C
--- 172.16.100.21 ping statistics ---
7 packets transmitted, 0 received, +4 errors, 100% packet loss, time 6639ms
pipe 4
/ # ifconfig eth0 10.0.11.1 up
/ # ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:49:F2:49
          inet addr:10.0.11.1  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:384 (384.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18
[root@xen ~]# xl console busybox-002
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig eth0 10.0.11.2 up
/ # ping 10.0.11.1
PING 10.0.11.1 (10.0.11.1): 56 data bytes
64 bytes from 10.0.11.1: seq=0 ttl=64 time=1.841 ms
64 bytes from 10.0.11.1: seq=1 ttl=64 time=1.293 ms
64 bytes from 10.0.11.1: seq=2 ttl=64 time=1.959 ms
64 bytes from 10.0.11.1: seq=3 ttl=64 time=1.389 ms
64 bytes from 10.0.11.1: seq=4 ttl=64 time=1.517 ms
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     408.0
busybox-001                                  8   256     2     -b----       1.4
busybox-002                                  9   256     2     -b----       1.4

关闭虚拟机,如果虚拟机有shutdown命令,但是这里使用busybox没有shutdown命令;

[root@xen ~]# xl shutdown busybox-002
Shutting down domain 9
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     410.3
busybox-001                                  8   256     2     -b----       1.7
busybox-002                                  9   256     2     -b----       2.1

查看pci设备、暂停虚拟机、恢复暂停;

[root@xen ~]# xl pci-list busybox-002
[root@xen ~]# xl pause busybox-002
[root@xen ~]# xl unpause busybox-002

挂起虚拟机,从内存转存到磁盘文件;

[root@xen ~]# xl save busybox-002 /tmp/busybox-002.img /etc/xen/busybox2
Saving to /tmp/busybox-002.img new xl format (info 0x0/0x0/1416)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%
[root@xen ~]# xl save busybox-001 /tmp/busybox-001.img  /etc/xen/busybox
Saving to /tmp/busybox-001.img new xl format (info 0x0/0x0/1415)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     418.0

恢复挂起的虚拟机,从磁盘文件恢复到内存;

[root@xen ~]# ls /tmp/ -h
busybox-001.img  busybox-002.img  yum.log
[root@xen ~]# xl restore /etc/xen/busybox /tmp/busybox-001.img
Loading new save file /tmp/busybox-001.img (new xl fmt info 0x0/0x0/1415)
 Savefile contains xl domain config
Parsing config from /etc/xen/busybox
xc: Reloading memory pages: 65536/65536  100%
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     420.4
busybox-001                                 10   256     2     -b----       0.0
[root@xen ~]# xl vcpu-list busybox-001
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
busybox-001                         10     0    3   -b-       0.2  all
busybox-001                         10     1    2   -b-       0.2  all

绑定vcpu到物理cpu核心;

root@xen ~]# xl vcpu-pin busybox-001 0 3
[root@xen ~]# xl vcpu-list busybox-001
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
busybox-001                         10     0    3   -b-       0.3  3
busybox-001                         10     1    2   -b-       0.3  all

可以设置使用vcpu的个数,不能随便加,在启动虚拟机实例配置文件已经指定最大cpu个数为2个,只能少于最大cpu个数;

[root@xen ~]# xl vcpu-set busybox-001 4
[root@xen ~]# xl vcpu-list busybox-001
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
busybox-001                         10     0    3   -b-       0.3  3
busybox-001                         10     1    2   -b-       0.3  all
[root@xen ~]# xl vcpu-set busybox-001 1
[root@xen ~]# xl vcpu-list busybox-001
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
busybox-001                         10     0    3   -b-       0.4  3
busybox-001                         10     1    -   --p       0.3  all
[root@xen ~]# xl vcpu-set busybox-001 2
[root@xen ~]# xl vcpu-list busybox-001
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
busybox-001                         10     0    3   -b-       0.4  3
busybox-001                         10     1    -   --p       0.3  all

查看xen hypervisor摘要信息;

[root@xen ~]# xl info busybox-001
host                   : xen.smoke.com
release                : 3.7.4-1.el6xen.x86_64
version                : #1 SMP Wed Jan 23 15:52:51 EST 2013
machine                : x86_64
nr_cpus                : 4
max_cpu_id             : 127
nr_nodes               : 1
cores_per_socket       : 2
threads_per_core       : 1
cpu_mhz                : 2493
hw_caps                : 1f8bfbff:28100800:00000000:00007f00:f7ba2223:00000000:00000001:00000283
virt_caps              : hvm
total_memory           : 2047
free_memory            : 413
sharing_freed_memory   : 0
sharing_used_memory    : 0
outstanding_claims     : 0
free_cpus              : 0
xen_major              : 4
xen_minor              : 4
xen_extra              : .2-5.el6
xen_version            : 4.4.2-5.el6
xen_caps               : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler          : credit
xen_pagesize           : 4096
platform_params        : virt_start=0xffff800000000000
xen_changeset          : Thu Apr 23 15:06:13 2015 +0100 git:a93c3fa-dirty
xen_commandline        : dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
cc_compiler            : gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
cc_compile_by          : mockbuild
cc_compile_domain      : centos.org
cc_compile_date        : Mon Jul 27 12:16:07 UTC 2015
xend_config_format     : 4
[root@xen ~]# xl domid busybox-001
10
[root@xen ~]# xl domname 10
busybox-001
[root@xen ~]# xl dmesg busybox-001
 Xen 4.4.2-5.el6
(XEN) Xen version 4.4.2-5.el6 (mockbuild@centos.org) (gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)) debug=n Mon Jul 27 12:16:07 UTC 2015
(XEN) Latest ChangeSet: Thu Apr 23 15:06:13 2015 +0100 git:a93c3fa-dirty
(XEN) Bootloader: GNU GRUB 0.97
(XEN) Command line: dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
(XEN) Video information:
(XEN)  VGA is text mode 80x25, font 8x16
(XEN) Disc information:
(XEN)  Found 1 MBR signatures
(XEN)  Found 1 EDD information structures
(XEN) Xen-e820 RAM map:
(XEN)  0000000000000000 - 000000000009ec00 (usable)
(XEN)  000000000009ec00 - 00000000000a0000 (reserved)
(XEN)  00000000000dc000 - 0000000000100000 (reserved)
(XEN)  0000000000100000 - 000000007fee0000 (usable)
(XEN)  000000007fee0000 - 000000007feff000 (ACPI data)
(XEN)  000000007feff000 - 000000007ff00000 (ACPI NVS)
(XEN)  000000007ff00000 - 0000000080000000 (usable)
(XEN)  00000000f0000000 - 00000000f8000000 (reserved)
(XEN)  00000000fec00000 - 00000000fec10000 (reserved)
(XEN)  00000000fee00000 - 00000000fee01000 (reserved)
(XEN)  00000000fffe0000 - 0000000100000000 (reserved)
(XEN) System RAM: 2047MB (2096632kB)
(XEN) ACPI: RSDP 000F6A10, 0024 (r2 PTLTD )
(XEN) ACPI: XSDT 7FEE965B, 005C (r1 INTEL  440BX     6040000 VMW   1324272)
(XEN) ACPI: FACP 7FEFEE73, 00F4 (r4 INTEL  440BX     6040000 PTL     F4240)
(XEN) ACPI: DSDT 7FEEB345, 13B2E (r1 PTLTD  Custom    6040000 MSFT  3000001)
(XEN) ACPI: FACS 7FEFFFC0, 0040
(XEN) ACPI: BOOT 7FEEB31D, 0028 (r1 PTLTD  $SBFTBL$  6040000  LTP        1)
(XEN) ACPI: APIC 7FEEA8BD, 0742 (r1 PTLTD        APIC    6040000  LTP        0)
(XEN) ACPI: MCFG 7FEEA881, 003C (r1 PTLTD  $PCITBL$  6040000  LTP        1)
(XEN) ACPI: SRAT 7FEE9757, 08A8 (r2 VMWARE MEMPLUG   6040000 VMW         1)
(XEN) ACPI: HPET 7FEE971F, 0038 (r1 VMWARE VMW HPET  6040000 VMW         1)
(XEN) ACPI: WAET 7FEE96F7, 0028 (r1 VMWARE VMW WAET  6040000 VMW         1)
(XEN) Domain heap initialised
(XEN) Processor #0 7:10 APIC version 21
(XEN) Processor #1 7:10 APIC version 21
(XEN) Processor #2 7:10 APIC version 21
(XEN) Processor #3 7:10 APIC version 21
(XEN) IOAPIC[0]: apic_id 128, version 32, address 0xfec00000, GSI 0-23
(XEN) Enabling APIC mode:  Phys.  Using 1 I/O APICs
(XEN) Not enabling x2APIC: depends on iommu_supports_eim.
(XEN) Using scheduler: SMP Credit Scheduler (credit)
(XEN) Detected 2493.508 MHz processor.
(XEN) Initing memory sharing.
(XEN) xstate_init: using cntxt_size: 0x340 and states: 0x7
(XEN) I/O virtualisation disabled
(XEN) ENABLING IO-APIC IRQs
(XEN)  -> Using new ACK method
(XEN) Platform timer is 14.318MHz HPET
(XEN) Allocated console ring of 16 KiB.
(XEN) VMX: Supported advanced features:
(XEN)  - APIC TPR shadow
(XEN)  - Extended Page Tables (EPT)
(XEN)  - Virtual-Processor Identifiers (VPID)
(XEN)  - Virtual NMI
(XEN)  - MSR direct-access bitmap
(XEN)  - Unrestricted Guest
(XEN) HVM: ASIDs enabled.
(XEN) HVM: VMX enabled
(XEN) HVM: Hardware Assisted Paging (HAP) detected
(XEN) HVM: HAP page sizes: 4kB, 2MB
(XEN) Brought up 4 CPUs
(XEN) *** LOADING DOMAIN 0 ***
(XEN)  Xen  kernel: 64-bit, lsb, compat32
(XEN)  Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x1d87000
(XEN) PHYSICAL MEMORY ARRANGEMENT:
(XEN)  Dom0 alloc.:   0000000074000000->0000000078000000 (459256 pages to be allocated)
(XEN)  Init. ramdisk: 000000007d43d000->000000007f9ff400
(XEN) VIRTUAL MEMORY ARRANGEMENT:
(XEN)  Loaded kernel: ffffffff81000000->ffffffff81d87000
(XEN)  Init. ramdisk: ffffffff81d87000->ffffffff84349400
(XEN)  Phys-Mach map: ffffffff8434a000->ffffffff846fddd8
(XEN)  Start info:    ffffffff846fe000->ffffffff846fe4b4
(XEN)  Page tables:   ffffffff846ff000->ffffffff84726000
(XEN)  Boot stack:    ffffffff84726000->ffffffff84727000
(XEN)  TOTAL:         ffffffff80000000->ffffffff84800000
(XEN)  ENTRY ADDRESS: ffffffff81745210
(XEN) Dom0 has maximum 2 VCPUs
(XEN) Scrubbing Free RAM: .done.
(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) Std. Loglevel: Errors and warnings
(XEN) Guest Loglevel: Nothing (Rate-limited: Errors and warnings)
(XEN) Xen is relinquishing VGA console.
(XEN) *** Serial input -> DOM0 (type 'CTRL-a' three times to switch input to Xen)
(XEN) Freed 284kB init memory.

[root@xen ~]# xl top

显示网络接口、网络接口热插拔;

[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:4e:c6:cb     0     4     14   769/768         /local/domain/0/backend/vif/10/0
[root@xen ~]# xl network-attach busybox-001 bridge=xenbr0
[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:4e:c6:cb     0     4     14   769/768         /local/domain/0/backend/vif/10/0
1   0  00:16:3e:23:d4:a1     1     4      8  1280/1281        /local/domain/0/backend/vif/10/1
[root@xen ~]# xl console busybox-001
/ # ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3E:4E:C6:CB
          inet addr:10.0.11.1  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:758 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62228 (60.7 KiB)  TX bytes:72100 (70.4 KiB)
          Interrupt:18

eth1      Link encap:Ethernet  HWaddr 00:16:3E:23:D4:A1
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:26

lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)
[root@xen ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:15541 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5753 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2063044 (1.9 MiB)  TX bytes:620056 (605.5 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:76:D2:62
          inet addr:192.168.190.130  Bcast:192.168.190.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:42664 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2634 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2789515 (2.6 MiB)  TX bytes:266230 (259.9 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:784 (784.0 b)  TX bytes:784 (784.0 b)

vif10.0   Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:28 (28.0 b)  TX bytes:468 (468.0 b)

vif10.1   Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:618 (618.0 b)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:76:D2:58
          inet addr:172.16.100.6  Bcast:172.16.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6942 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3046 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:559406 (546.2 KiB)  TX bytes:337324 (329.4 KiB)

xenbr1    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::807b:9dff:fe55:b07f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:56 (56.0 b)  TX bytes:468 (468.0 b)
[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:4e:c6:cb     0     4     14   769/768         /local/domain/0/backend/vif/10/0
1   0  00:16:3e:23:d4:a1     1     4      8  1280/1281        /local/domain/0/backend/vif/10/1
[root@xen ~]# xl network-detach busybox-001 1
/ # net eth1: xennet_release_rx_bufs: fix me for copying receiver.

/ # ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3E:4E:C6:CB
          inet addr:10.0.11.1  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:758 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62228 (60.7 KiB)  TX bytes:72100 (70.4 KiB)
          Interrupt:18

lo        Link encap:Local Loopback
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 B)  TX bytes:0 (0.0 B)
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table
[root@xen ~]# qemu-img create -f qcow2 -o ? /images/xen/busybox1.2.img
Supported options:
size             Virtual disk size
backing_file     File name of a base image
backing_fmt      Image format of the base image
encryption       Encrypt the image
cluster_size     qcow2 cluster size
preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
[root@xen ~]# qemu-img create -f qcow2 -o size=5G,preallocation=metadata /images/xen/busybox1.2.img
Formatting '/images/xen/busybox1.2.img', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='metadata'
[root@xen ~]# ll -h /images/xen/
总用量 40M
-rw-r--r--. 1 root root 5.1G 11月 25 06:37 busybox1.2.img
-rw-r--r--. 1 root root 2.0G 11月 25 05:34 busybox2.img
-rw-r--r--. 1 root root 2.0G 11月 24 07:00 busybox.img
[root@xen ~]# du -sh /images/xen/
40M     /images/xen/
[root@xen ~]# du -sh /images/xen/busybox1.2.img
972K    /images/xen/busybox1.2.img
[root@xen ~]# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   10     4     13     8        /local/domain/0/backend/qdisk/10/51712
[root@xen ~]# xl block-attach busybox-001 '/images/xen/busybox1.2.img,qcow2,xvdb,w'
[root@xen ~]# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   10     4     13     8        /local/domain/0/backend/qdisk/10/51712
51728 0   10     4     8      1281     /local/domain/0/backend/qdisk/10/51728
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table

Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvdb doesn't contain a valid partition table
/ # fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI, OSF or GPT disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that the previous content
won't be recoverable.

Command (m for help): p

Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks  Id System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +50M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-652, default 8): Using default value 8
Last cylinder or +size or +sizeM or +sizeK (8-652, default 652): +1G

Command (m for help): p

Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks  Id System
/dev/xvdb1               1           7       56196  83 Linux
/dev/xvdb2               8         130      987997+ 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
 xvdb: xvdb1 xvdb2
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table

Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks  Id System
/dev/xvdb1               1           7       56196  83 Linux
/dev/xvdb2               8         130      987997+ 83 Linux
[root@xen ~]# xl block-detach busybox-001 51728
[root@xen ~]# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   10     4     13     8        /local/domain/0/backend/qdisk/10/51712
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table
[root@xen ~]# xl uptime busybox-001
Name                                ID Uptime
busybox-001                         10  0:38:46
[root@xen ~]# xl destroy busybox-001
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----     436.8
[root@xen ~]# qemu-img create -f qcow2 -o size=5G,preallocation=metadata /images/xen/busybox3.img
Formatting '/images/xen/busybox3.img', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='metadata'

显示已用的回环设备、显示空闲loop设备、关联loop设备;

[root@xen yum.repos.d]# losetup -a
[root@xen yum.repos.d]# mount -o loop /images/xen/busybox.img /mnt
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131076 (/images/xen/busybox.img)
[root@xen yum.repos.d]# umount /mnt
[root@xen yum.repos.d]# losetup -f
/dev/loop0
[root@xen yum.repos.d]# losetup /dev/loop0 /images/xen/busybox3.img
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen yum.repos.d]# fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xad46703f.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/loop0: 5369 MB, 5369757696 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xad46703f

      Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +50M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-652, default 8):
Using default value 8
Last cylinder, +cylinders or +size{K,M,G} (8-652, default 652): +1G

Command (m for help): p

Disk /dev/loop0: 5369 MB, 5369757696 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xad46703f

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1               1           7       56196   83  Linux
/dev/loop0p2               8         139     1060290   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: 无效的参数.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

显示loop设备分区信息;

[root@xen yum.repos.d]# kpartx -av /dev/loop0
add map loop0p1 (253:0): 0 112392 linear /dev/loop0 63
add map loop0p2 (253:1): 0 2120580 linear /dev/loop0 112455
[root@xen yum.repos.d]# ls /dev/mapper/
control  loop0p1  loop0p2
[root@xen yum.repos.d]# mke2fs -t ext2 /dev/mapper/loop0p1
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
14056 inodes, 56196 blocks
2809 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=57671680
7 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961

正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@xen yum.repos.d]# mke2fs -t ext2 /dev/mapper/loop0p2
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265072 blocks
13253 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen yum.repos.d]# mkdir /mnt/{boot,sysroot}
[root@xen yum.repos.d]# mount /dev/mapper/loop0p1 /mnt/boot/
[root@xen yum.repos.d]# mount /dev/mapper/loop0p2 /mnt/sysroot/
[root@xen yum.repos.d]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/loop0p1 on /mnt/boot type ext2 (rw)
/dev/mapper/loop0p2 on /mnt/sysroot type ext2 (rw)
[root@xen yum.repos.d]# cp /boot/vmlinuz-2.6.32-504.el6.x86_64 /mnt/boot/vmlinuz
[root@xen yum.repos.d]# cp /boot/initramfs-2.6.32-504.el6.x86_64.img /mnt/boot/initramfs.img
[root@xen yum.repos.d]# grub-install --root-directory=/mnt /dev/loop0
Probing devices to guess BIOS drives. This may take a long time.
/dev/loop0 does not have any corresponding BIOS drive.
[root@xen yum.repos.d]# ls /mnt/boot/
grub  initramfs.img  lost+found  vmlinuz
[root@xen yum.repos.d]# ls /mnt/boot/grub/
device.map     fat_stage1_5  iso9660_stage1_5  minix_stage1_5     stage1  ufs2_stage1_5    xfs_stage1_5
e2fs_stage1_5  ffs_stage1_5  jfs_stage1_5      reiserfs_stage1_5  stage2  vstafs_stage1_5
[root@xen yum.repos.d]# vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title BusyBox(kernel-2.6.32)
        root (hd0,0)
        kernel /vmlinuz root=/dev/xvda1 ro selinux=0 init=/bin/sh
        initrd /initramfs.img
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/sysroot/
[root@xen ~]# cd /mnt/sysroot/
[root@xen sysroot]# ls
bin  linuxrc  lost+found  sbin  usr
[root@xen sysroot]# mkdir lib/modules dev proc sys etc var tmp -p
[root@xen sysroot]# cp /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/xen-netfront.ko lib/modules/
[root@xen sysroot]# sync

拆除loop设备;

[root@xen sysroot]# cd
[root@xen ~]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen ~]# umount /mnt/boot/
[root@xen ~]# umount /mnt/sysroot/
[root@xen ~]# losetup -d /dev/loop0
[root@xen ~]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen ~]# kpartx -d /dev/loop0
[root@xen ~]# ls /dev/mapper/
control
[root@xen ~]# losetup -f
/dev/loop0
[root@xen ~]# cd /etc/xen/
[root@xen xen]# cp busybox busybox3
[root@xen ~]# which pygrub
/usr/bin/pygrub
[root@xen xen]# vim busybox3
name = "busybox-003"
#kernel = "/boot/vmlinuz"
#ramdisk = "/boot/initramfs.img"
#extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox3.img,qcow2,xvda,rw' ]
#root = "/dev/xvda ro"
bootloader = '/usr/bin/pygrub'
[root@xen xen]# xl create busybox3 -c
Parsing config from busybox3
libxl: error: libxl_device.c:1225:libxl__wait_for_backend: Backend /local/domain/0/backend/qdisk/0/51712 not ready
libxl: error: libxl_bootloader.c:405:bootloader_disk_attached_cb: failed to attach local disk for bootloader execution
libxl: error: libxl_bootloader.c:276:bootloader_local_detached_cb: unable to detach locally attached disk
libxl: error: libxl_create.c:1022:domcreate_rebuild_done: cannot (re-)build domain: -3

虚拟机启动不了的原因是使用losetup方式对qcow2格式的映像文件进行分区、格式化、挂载、虚拟机xen的xl是识别不了这个分区。

[root@xen xen]# cd /images/xen/
[root@xen xen]# ls
busybox1.2.img  busybox2.img  busybox3.img  busybox.img
[root@xen xen]# rm busybox3.img
rm:是否删除普通文件 "busybox3.img"?y
[root@xen xen]# qemu-img create -f raw -o size=2G /images/xen/busybox3.img
Formatting '/images/xen/busybox3.img', fmt=raw size=2147483648
[root@xen xen]# losetup -f
/dev/loop0
[root@xen xen]# losetup /dev/loop0 /images/xen/busybox3.img
[root@xen xen]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen xen]# fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x07f78d24.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/loop0: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x07f78d24

      Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): +50M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-261, default 8):
Using default value 8
Last cylinder, +cylinders or +size{K,M,G} (8-261, default 261): +1G

Command (m for help): p

Disk /dev/loop0: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x07f78d24

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1               1           7       56196   83  Linux
/dev/loop0p2               8         139     1060290   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: 无效的参数.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
[root@xen xen]# kpartx -av /dev/loop0
add map loop0p1 (253:0): 0 112392 linear /dev/loop0 63
add map loop0p2 (253:1): 0 2120580 linear /dev/loop0 112455
[root@xen xen]# ls /dev/mapper/
control  loop0p1  loop0p2
[root@xen xen]# mke2fs -t ext2 /dev/mapper/loop0p1
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
14056 inodes, 56196 blocks
2809 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=57671680
7 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961

正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@xen xen]# mke2fs -t ext2 /dev/mapper/loop0p2
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265072 blocks
13253 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@xen xen]# mount /dev/mapper/loop0p1 /mnt/boot/
[root@xen xen]# mount /dev/mapper/loop0p2 /mnt/sysroot/
[root@xen xen]# cp /boot/vmlinuz-2.6.32-504.el6.x86_64 /mnt/boot/vmlinuz
[root@xen xen]# cp /boot/initramfs-2.6.32-504.el6.x86_64.img /mnt/boot/initramfs.img
[root@xen xen]# cd
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/sysroot/
[root@xen ~]# mkdir /mnt/sysroot/lib/modules -p
[root@xen ~]# modinfo xen-netfront
filename:       /lib/modules/3.7.4-1.el6xen.x86_64/kernel/drivers/net/xen-netfront.ko
alias:          xennet
alias:          xen:vif
license:        GPL
description:    Xen virtual network device frontend
srcversion:     746EC04CBED591C2D0F65D1
depends:
intree:         Y
vermagic:       3.7.4-1.el6xen.x86_64 SMP mod_unload modversions
[root@xen ~]# cp /lib/modules/3.7.4-1.el6xen.x86_64/kernel/drivers/net/xen-netfront.ko /mnt/sysroot/lib/modules/
[root@xen ~]# cd /mnt/sysroot/
[root@xen sysroot]# mkdir -p dev proc sys tmp var home boot
[root@xen sysroot]# sync
[root@xen sysroot]# xl create /etc/xen/busybox -c
/ #

[root@xen ~]# xl block-attach busybox-001 '/images/xen/busybox3.img,raw,xvdb,w'

/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table

Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks  Id System
/dev/xvdb1               1           7       56196  83 Linux
/dev/xvdb2               8         139     1060290  83 Linux
/ # mount /dev/xvdb1 /etc/
EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
/ # ls /etc/
initramfs.img  lost+found     vmlinuz
/ # umount /etc
[root@xen ~]# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   14     4     13     8        /local/domain/0/backend/qdisk/14/51712
51728 0   14     4     14     28       /local/domain/0/backend/qdisk/14/51728
[root@xen ~]# xl block-detach busybox-001 51728
[root@xen ~]# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   14     4     13     8        /local/domain/0/backend/qdisk/14/51712
[root@xen ~]# grub-install --root-directory=/mnt /dev/loop0
Probing devices to guess BIOS drives. This may take a long time.
/dev/loop0 does not have any corresponding BIOS drive.
[root@xen ~]# ls /mnt/boot/
grub  initramfs.img  lost+found  vmlinuz
[root@xen ~]# vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title BusyBox(kernel-2.6.32)
        root (hd0,0)
        kernel /vmlinuz root=/dev/xvda1 ro selinux=0 init=/bin/sh
        initrd /initramfs.img
[root@xen ~]# sync
[root@xen ~]# vim /etc/xen/busybox3
[root@xen ~]# which pygrub
/usr/bin/pygrub
[root@xen xen]# vim busybox3
name = "busybox-003"
#kernel = "/boot/vmlinuz"
#ramdisk = "/boot/initramfs.img"
#extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox3.img,raw,xvda,rw' ]
#root = "/dev/xvda ro"
bootloader = '/usr/bin/pygrub'

[root@xen ~]# xl create /etc/xen/busybox3 -c

[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1352     2     r-----    1634.9
busybox-001                                 14   256     2     -b----      66.0

[root@xen ~]# xl destroy busybox-001

下载Centos6.6的vmlinuz和initrd.img文件,可以将Centos6.6操作系统iso文件解压后再isolinux目录中找到

[root@xen ~]# ls
anaconda-ks.cfg                    busybox-1.22.1.tar.bz2  install.log.syslog                             vmlinuz
bridge-utils-1.5-2.el6.x86_64.rpm  initrd.img              kernel-xen-3.7.4-1.el6xen.x86_64.rpm
busybox-1.22.1                     install.log             kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm
[root@xen ~]# mkdir /images/kernel
[root@xen ~]# mv vmlinuz initrd.img /images/kernel/
[root@xen ~]# cp /etc/xen/busybox /etc/xen/centos
[root@xen ~]# qemu-img create -f qcow2 -o size=120G,preallocation=metadata /images/xen/centos6.6.img
Formatting '/images/xen/centos6.6.img', fmt=qcow2 size=128849018880 encryption=off cluster_size=65536 preallocation='metadata'
[root@xen ~]# vim /etc/xen/centos
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = ""
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen ~]# xl create /etc/xen/centos
Parsing config from /etc/xen/centos
[root@xen ~]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1350     2     r-----    1656.1
centos-001                                  18   512     2     -b----       8.8

[root@xen ~]# xl console centos-001

配置虚拟机ip地址;

使用URL安装,我这里将cenots6.6的ios文件进行解压,搭建http服务器;

设置web服务器url;

安装完成;

初始化,进行下面的初始化就可以了,我这里就不安装了;

[root@xen xen]# xl destroy centos-001

使用Kickstart自动化安装虚拟机操作系统,Kickstart部署详细见:http://blog.51cto.com/smoke520/2325660

[root@xen ~]# vim /etc/xen/centos
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = "ks=http://172.16.100.10/ks_config/CentOS-6.6-ks.cfg"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen ~]# xl create centos -c
e:09:ab:21 (CentOS6) via eth0
Aug  1 17:36:34 linux-node1 dhcpd: DHCPREQUEST for 172.16.100.33 (172.16.100.10) from 00:16:3e:09:ab:21 (CentOS6) via eth0
Aug  1 17:36:34 linux-node1 dhcpd: DHCPACK on 172.16.100.33 to 00:16:3e:09:ab:21 (CentOS6) via eth0
[root@xen xen]# vim centos
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen xen]# xl destroy centos-001
[root@xen xen]# xl create centos -c

ctrl+]退回到宿主机;

[root@CentOS6 ~]# [root@xen xen]#
[root@xen xen]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   838     2     r-----    6347.0
centos-001                                  68   512     2     -b----       8.2
[root@xen xen]# xl shutdown centos-001
Shutting down domain 68
[root@xen xen]# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   838     2     r-----    6348.5

cloud-init专门为云实现初始化磁盘映像文件;

[root@xen xen]# yum info cloud-init
Name        : cloud-init
Arch        : x86_64
Version     : 0.7.5
Release     : 10.el6.centos.2
Size        : 432 k
Repo        : extras
Summary     : Cloud instance init scripts
URL         : http://launchpad.net/cloud-init
License     : GPLv3
Description : Cloud-init is a set of init scripts for cloud instances.  Cloud instances
            : need special scripts to run during initialization to retrieve and install
            : ssh keys and to let the user run various scripts.
[root@xen xen]# vim busybox
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr1' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
vfb = [ 'sdl=1' ]
[root@xen xen]# xl create busybox

[root@xen xen]# xl destroy busybox-001
[root@xen xen]# vim centos
[root@xen xen]# grep -v "#" centos | grep -v "^$"
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'sdl=1' ]
[root@xen xen]# xl create centos

[root@xen xen]# xl destroy centos-001

使用vnc,安装vnc客户端;

[root@xen xen]# yum -y install tigervnc
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'vnc=1' ]
[root@xen xen]# xl create centos
[root@xen xen]# ss -tnl
State      Recv-Q Send-Q                                     Local Address:Port                                       Peer Address:Port
LISTEN     0      1                                              127.0.0.1:5900                                                  *:*
LISTEN     0      128                                                   :::22                                                   :::*
LISTEN     0      128                                                    *:22                                                    *:*
LISTEN     0      100                                                  ::1:25                                                   :::*
LISTEN     0      100                                            127.0.0.1:25                                                    *:*
LISTEN     0      128                                            127.0.0.1:6010                                                  *:*
LISTEN     0      128                                                  ::1:6010                                                 :::*
LISTEN     0      128                                            127.0.0.1:6011                                                  *:*
LISTEN     0      128                                                  ::1:6011                                                 :::*
LISTEN     0      128                                            127.0.0.1:6012                                                  *:*
LISTEN     0      128                                                  ::1:6012                                                 :::*
[root@xen xen]# vncviewer :5900

[root@xen xen]# vim centos
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'vnc=1,vnclisten=0.0.0.0,vncpasswd=smoke520' ]
[root@xen xen]# xl create centos
[root@xen xen]# ss -tnl
State      Recv-Q Send-Q                                     Local Address:Port                                       Peer Address:Port
LISTEN     0      1                                                      *:5900                                                  *:*
LISTEN     0      128                                                   :::22                                                   :::*
LISTEN     0      128                                                    *:22                                                    *:*
LISTEN     0      100                                                  ::1:25                                                   :::*
LISTEN     0      100                                            127.0.0.1:25                                                    *:*
LISTEN     0      128                                            127.0.0.1:6010                                                  *:*
LISTEN     0      128                                                  ::1:6010                                                 :::*
LISTEN     0      128                                            127.0.0.1:6011                                                  *:*
LISTEN     0      128                                                  ::1:6011                                                 :::*
LISTEN     0      128                                            127.0.0.1:6012                                                  *:*
LISTEN     0      128                                                  ::1:6012                                                 :::*

在Windows操作系统使用VNC Viewer连接虚拟机;

输入vnc密码smoke520;

正常登陆;

[root@xen xen]# xl destroy centos-001

使用宿主机分区作别DomU的磁盘;

[root@xen ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +30G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@xen ~]# kpartx -a /dev/sdb
[root@xen ~]# pvcreate /dev/sdb1
[root@xen ~]# vgcreate myvg /dev/sdb1
[root@xen ~]# lvcreate -L 2G -n bbox myvg
[root@xen ~]# mke2fs -t ext2 /dev/myvg/bbox
[root@xen ~]# mount /dev/myvg/bbox /mnt/
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/
[root@xen ~]# cd /mnt/
[root@xen mnt]# mkdir proc dev sys tmp etc var boot
[root@xen mnt]# ll
总用量 100
drwxr-xr-x. 2 root root  4096 11月 24 05:51 bin
drwxr-xr-x. 2 root root  4096 12月  4 22:17 boot
drwxr-xr-x. 2 root root  4096 12月  4 22:17 dev
drwxr-xr-x. 2 root root  4096 12月  4 22:17 etc
lrwxrwxrwx. 1 root root    11 11月 24 05:51 linuxrc -> bin/busybox
drwx------. 2 root root 16384 12月  4 22:11 lost+found
drwxr-xr-x. 2 root root  4096 12月  4 22:17 proc
drwxr-xr-x. 2 root root  4096 11月 24 05:51 sbin
drwxr-xr-x. 2 root root  4096 12月  4 22:17 sys
drwxr-xr-x. 2 root root  4096 12月  4 22:17 tmp
drwxr-xr-x. 4 root root  4096 11月 24 05:51 usr
drwxr-xr-x. 2 root root  4096 12月  4 22:17 var
[root@xen mnt]# cd /etc/xen/
[root@xen xen]# cp busybox bbox
[root@xen xen]# vim bbox
name = "bbox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/dev/myvg/bbox,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen xen]# xl create bbox -n
[root@xen xen]# xl create bbox -c
/ # ls
bin         dev         linuxrc     proc        sys         usr
boot        etc         lost+found  sbin        tmp         var
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn't contain a valid partition table
/ # exit

使用libvirt实现xen虚拟机管理; [root@xen xen]# yum -y install libvirt libvirt-daemon-xen [root@xen xen]# service libvirtd start [root@xen xen]# yum -y install virt-manager [root@xen xen]# virt-manager

如果创建虚拟机时候出现Error:list.remove(x):x not in list;

[root@xen yum.repos.d]# ps -ef | grep python
root      4529     1  1 22:48 ?        00:00:23 /usr/bin/python /usr/share/virt-manager/virt-manager.py
root      6050  3049  0 23:12 pts/0    00:00:00 grep python
[root@xen yum.repos.d]# kill -9 4529
[root@xen yum.repos.d]# /usr/bin/python /usr/share/virt-manager/virt-manager.py

选择使用pxe方式安装(需要有Kickstart服务器);

选择操作系统类型;

分配cpu、内存大小;

分配磁盘大小,不要立即指定磁盘空间(磁盘映像文件默认存放在/var/lib/libvirt/images/目录);

使用PXE安装Virt Type只支持全虚拟机类型;

如果没有问题点击Begin Installation开始安装操作系统;

[root@xen yum.repos.d]# virsh list
 Id    Name                           State
----------------------------------------------------
 4     centos                         running
[root@xen yum.repos.d]# virsh destroy centos