Xen、KVM和VirtualBox比拼

vbox 与 kvm 的区别:
vbox 是由 qemu 改写而成,包含大量 qemu 代码。可以使用于 不支持 虚拟化的cpu。值得说的一点:vbox 在图形方面比较好,能进行2D 3D加速。cpu控制不理想(估计是因为图形支持的缘故)。操作上有独立的图形界面,易于上手。 kvm 是linux内核包含的东西,使用qemu作为上层管理(命令行)。cpu 必须支持虚拟化。性能,作为服务器很好,可是图形能力十分的差。即使放电影,图像也是像刷油漆一样,一层一层的。cpu使用率控制很好。 控制上比较简洁,功能比较丰富:比如使用 “无敌功能”所有更改指向内存,你的镜像永远保持干净。 “母镜像”功能让你拥有n个独立快照点。 还有很多参数。另外,kvm作为内核级的虚拟机,刚开始发展关注的公司比较多——但是还没有达到商业应用的水平。
总体而言:在支持 虚拟化的情况下,vbox 和 kvm 的性能差不多,主要是面向对象不同:kvm使用于服务器,vbox使用于桌面应用。 ***********************************************
关于kvm: kvm是开源软件,全称是kernel-based virtual machine(内核级虚拟机)。是x86架构且硬件支持虚拟化技术(如 intel VT 或 AMD-V)的linux 全虚拟化 解决方案。它包含一个为处理器提供底层虚拟化 可加载的核心模块kvm.ko(kvm-intel.ko 或 kvm-AMD.ko)。 kvm还需要一个经过修改的QEMU软件(qemu-kvm),作为虚拟机上层控制和界面。 kvm能在不改变linux或windows镜像的情况下同时运行多个虚拟机,(ps:它的意思是多个虚拟机使用同一镜像)并为每一个虚拟机配置个性化硬件环境(网卡、磁盘、图形适配器……)。 在主流的linux内核,如2.6.20以上的内核均包含了kvm核心。
KVM官方地址: http://kvm.qumranet.com/kvmwiki KVM的Changelog: http://kvm.qumranet.com/kvmwiki/ChangeLog, 可以知道最新的版本是多少,做了那些改变。 KVM下载地址在sourceforge.net上: http://sourceforge.net/project/showfile … _id=180599 KVM的Howto文档: http://kvm.qumranet.com/kvmwiki/HOWTO Kqemu: http://sourceforge.net/projects/kqemu/ Qemu: http://fabrice.bellard.free.fr/qemu/index.html **************************入门篇(基于ubuntu9.10) 基本知识: qemu是独立虚拟软件,能独立运行虚拟机(根本不需要kvm)。kqemu是该软件的加速软件。kvm并不需要qemu进行虚拟处理,只是需要它的上层管理界面进行虚拟机控制。虚拟机依旧是由kvm驱动。 所以,大家不要把概念弄错了,盲目的安装qemu和kqemu。
安装准备: 查看你的硬是否支持虚拟化。 命令: egrep ‘(vmx|svm)’ /proc/cpuinfo 要有 vmx 或 svm 的标识才行。总的说来,AMD在虚拟化方面作得更好一些。 使用intel cpu的朋友还需要进入bios进行设置——因为我的是AMD,所以设置方法不敢乱说。
安装kvm: 打开新立得软件库,安装kvm。系统会自动安装相关的软件包,包括qemu-kvm。什么kvm-AMD 或 kvm-intel模式系统都自动处理好了。现在大多文章都是2008年写的,已经过时了,可惜好多人只知道复制,好多设置已经不需要了,有些跟官方的完全冲突。
创建虚拟镜像: 命令(先cd 到你要保存镜像的位置): kvm-img create xxx.img 2G 由于是要安装xp精简系统,2G已经足够大了(安装下来只要700M)。xxx 代表名字,想取什么都可以。最好是连续的英文.默认格式为raw,当然你可以自己设定,比如(-f qcow2)加在 create 后面即可。(.img这个后缀是我随便编的,kvm对后缀名没有要求) 其它格式如下: Supported formats: cow qcow vmdk cloop dmg bochs vpc vvfat qcow2 parallels nbd host_cdrom host_floppy host_device raw tftp ftps ftp https http
安装虚拟机系统: 命令(先cd 到你要保存镜像的位置): kvm -hda xxxx.img -cdrom /path/to/boot-media.iso -boot d -m 512 说明几点:/path/to/boot-media.iso 只是个举例。具体为你的系统盘镜像位置。-m 为虚拟机内存大小,单位是M默认(不写这个选项)为128M。当然,自己看着给吧。 建议如果虚拟的是xp系统,把页面缓存给关了。
使用虚拟机最简单的命令: 命令(先cd 到你要保存镜像的位置): kvm -m 1024 -hda xxx.img 由于默认内存是128M,所以不得不指定一下,要不连-m 1024都可以省了。此时是没有声卡的,当然也可加上声音选项。cpu默认是一颗,网络默认启动(为net-内部端口映射)(可以上网,但是主机识别不了,它也无法连接主机)。 你可以使用: kvm -m 1024 -hda /xxx/xxx/xxx.img 你也可以把它作为桌面“创建启动器”的命令使用。每次轻轻一点就可使用了。
****************************中级篇 命令: kvm –help 命令: kvm-img –help 看看具体的选项说明,需要什么功能就在“最简单命令”后面加就是了——特别简单、功能又很多。用的满意了,可以做成“程序启动器”。或者打开gedit,把命令保存进去,把文件名改为xxx.sh。再把属性改为“可执行”,要用就点击。 比如:kvm -m 1024 -hda xxx.img -xxx xx -xxxx xxx -xxxxxx -xxx
现在分功能讲解
1,文件共享 我们希望虚拟机能和主机对一些文件夹进行共享操作。类似于vbox的共享文件夹。 首先安装 samba 。这是linux的共享功能软件,支持windows系统的访问。记住不是samba4 然后,新建一个文件夹,属性。共享选项,把所有选项开启。应用。接受系统的权限的更改。
好了,默认在虚拟机的网上邻居,就能找见了。没有?看看整个网络(侧边任务)。 简单吧,kvm早已升级了。根本不需要什么配置。
关于权限:你是否有“无法访问,权限不够……”的问题?主机无法修改共享文件“你不是该文件的创建者”? 那是因为linux的权限相当的严格,必须要放权别人才能访问、修改。 如果上级文件夹(无论哪个)不让读取(比如: 其它;文件夹访问 无),那么就会出现无法访问的情况。你要设置上级文件夹权限为(其它;文件夹访问 访问文件)就可以了,不必完全放权。
因为安全考虑,我的用户文件夹(其它;文件夹访问 无)。所以一开始就出了权限问题。我的解决办法是使用命令: sudo gnome-open /home/ 在home中再新建一个文件夹,在属性上,把创建者改为非root(改为经常使用的普通用户),组群:sambashare。权限全为:创建和删除。
经测试,外网虽然能显示共享文件夹,却无法访问——保证只有虚拟机可以访问。(我使用了ufw防火墙)
windows虚拟机在共享文件夹中创建的文件,主机是无法更改的。要设置权限: 我的电脑-打开-工具-文件夹选项-查看 把“使用简单的文件共享”选项去掉。在文件(夹)属性——安全:知道怎么弄了吧。
linux的文件夹系统权限作的十分的好。比如你把其它非受权文件夹的链接复制到共享文件夹,依然无法访问。windows那种权限的随意性,看见就想哭。
多说一点:我的电脑右键,可以把共享文件夹设置为网络硬盘。相当于移动硬盘,可以方便的安装软件,保存资料。
2。无敌模式(-snapshot) -snapshot       write to temporary files instead of disk image files 意思是不更改镜像文件,启动后的所有改动均不会往镜像文件上写。临时文件存放在内存中了,具体是cached。 同样的功能,在vbox要独立安装软件。效率可想而知…… 在命令后面空格加上: -snapshot 即可
3.高速网络(-net nic,model=virtio -net user) 表 2. 虚拟网络模块的性能差异 虚拟网络模块     网络传输速度(ssh)     客户机操作系统     网络状态 rtl8029    200-300KB/s    SLES10SP2 (kernel 2.6.16-60)    不稳定 e1000    4.8-5.4MB/s    SLES10SP2 (kernel 2.6.16-60)    稳定 virtio    10.6-11.1MB/s    SLES11 (kernel 2.6.27-19)    稳定 驱动下载地址: http://sourceforge.net/projects/kvm/files/ 名字是 kvm-driver-disc 的 NETKVM-20081229.iso  具体可能有变化,使用命令: kvm -m 1024 -hda xp.img -cdrom /home/cat650/linux/kvm/NETKVM-20081229.iso  -enable-kvm -net nic,model=virtio -net user 其中:-cdrom是加载光驱的意思。网络默认设置是 (-net nic -net user) 这里由于要指定virtio模块所以要把命令加上。然后自动安装驱动就行了。听说速度接近真实网卡——明显是为打造虚拟服务器配置的。 以后在启动虚拟机命令后面加上-net nic,model=virtio -net user就可以了。
4.高速虚拟 VirtIO paravirtual 是 Linux 虚拟机平台上统一的虚拟 IO 接口驱动。通常主机为了让客户机像在真实环境中一样运行,需要为客户机创建各式各样的虚拟设备,如磁盘,网卡,显卡,时钟,USB 等。这些虚拟设备大大降低了客户机的性能。如果客户机不关注这些硬件设备,就可以用统一的虚拟设备代替他们,这样可以大大提高虚拟机的性能。这个统一的标准化接口在 Linux 上就是 VirtIO 。需要注意的是 VirtIO 运行在 kernel 2.6.24 以上的版本中才能发挥它的性能优势。另外 KVM 项目组也发布了  Windows 平台上的 VirtIO 驱动,这样 windows 客户机的网络性能也可以大大提高了。 下载地址:http://www.linux-kvm.org/page/WindowsGuestDrivers/Download_Drivers viostor是磁盘的虚拟驱动。 带图片的参考:http://www.linux-kvm.org/page/WindowsGuestDrivers/viostor/installation 命令:把-hda xxx.img 替换为-drive file=/home/cat650/virt/xp.img,if=virtio,boot=on 意思是使用virtio磁盘系统,并作为启动盘(默认是boot=off,作为附加的第二硬盘)。第一次使用的时候记得挂载viostorXXXX.img,来安装驱动。
5.使用金手指“母镜像”功能 要求,镜像格式为 qcow2 。作用:在“母镜像”的基础上,建立一个新的镜像。虚拟机操作这个新镜像时不会对“母镜像”进行任何更改(只读“母镜像”),新镜像只保存由于操作产生的与“母镜像”的数据差异(大小很小)。由此实现超越“快照”“还原点”的金手指功能(数量没有限制)。 命令(先cd 到你要保存镜像的位置): kvm-img create -b xp.img -f qcow2 xp.test 其中xp.img是“母镜像”(参数 -b xxx),xp.test是新镜像——只能用 qcow2 格式。 新镜像的使用:正常使用即可。
6.镜像格式转换,镜像信息查询 能转换的格式有:raw,qcow2,qcow,cow,vmdk,cloop 如果你记不清你创建的镜像是什么格式的,可以使用命令(先cd 到你要保存镜像的位置): kvm-img info xxx.img 关于格式的优缺点,请参看高级篇 转换命令(先cd 到你要保存镜像的位置): kvm-img convert -f raw -O qcow2 xp.img xp.qco 注意:-O是字母o的大写。 这条命令举例的意思是:把名为xp.img格式为raw的镜像转换成新镜像xp.qco格式为qcow2 其它格式”vmdk”是 VMware 3 / 4 兼容镜像格式。
*******************************深入了解 1.kvm-img 命令 用法:kvm-img 后续命令 [命令选项]
后续命令如下
check [-f fmt] filename create [-F base_fmt] [-b base_image] [-f fmt] [-o options] filename [size] commit [-f fmt] filename convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 […]] output_filename info [-f fmt] filename snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename
部分内容详解:
filename 镜像的文件名(比如:xp.img cat.raw……后缀名随便取,或者不取)
base_image 只读的镜像——有点像“母镜像”。在“母镜像”基础上创建的镜像只储存对“母镜像”的修改。
output_base_image
forces the output image to be created as a copy on write image of the specified base image; “output_base_image” should have the same content as the input’s base image, however the path, image format, etc may differ base_fmt base_image(母镜像) 的格式. 参考 fmt
fmt 指镜像格式。建议大多数情况让系统自动选择(不使用该选项)。 主要格式如下:
“raw” Raw disk image format (默认).该格式精简,易被多种虚拟机接受。 如果你的系统支持 holes (如 linux 的 ext2 ext3 ext4? windows 的 NTFS),那么它将有效节约空间(比如你创建的磁盘是2G,虚拟系统只使用了800M,那么它实际也只占用800M的空间)。使用命令“kvm-img info 镜像文件名”,将显示实际使用的大小。linux用户还可以使用“ls -ls”命令直接查看。
“qcow2” QEMU 镜像格式, 使用最多的格式. 创建的镜像比较小(用多少就占多少),对于系统文件不支持 holes 的(比如windows系统下使用qemu)很有帮助。可进行AES加密,zlib基本压缩,并支持多种VM的快照(snapshots)。
“qcow” 古老的 QEMU 镜像格式. Left for compatibility.
“cow” User Mode Linux Copy On Write image format. Used to be the only growable image format in QEMU. It is supported only for compatibility with previous versions. It does not work on win32.不能运行win32. “vmdk” VMware 3 / 4 兼容镜像格式
“cloop” Linux Compressed Loop image, useful only to reuse directly compressed CD-ROM images present for example in the Knoppix CD- ROMs. size 镜像文件的大小比特. 一般单位使 “M” (megabyte, 1024k) 、 “G” (gigabyte, 1024M)、 T (terabyte, 1024G) 。 “b” is ignored.
output_filename 生成的镜像文件名
output_fmt 生成的镜像文件格式

 

 

KVM,Xen与VirtualBox在Intel Haswell上的Linux虚拟化性能比较 

现在我们做的是Intel Haswell的虚拟化基准测试。我们在Intel酷睿i7 4770K的“Haswell”处理器上使用搭载了最新软件组件的Fedora 19,来进行KVM,Xen和VirtualBox的基准测试。

自从上个月推出Haswell以来,我们已经发布了许多和这款全新的英特尔处理器相关的基准测试,但我们直到这篇文章发布前,一直没有涵盖虚拟化方面的性能测试。这里,启用了英特尔硬件虚拟化后,将在一个纯净的Fedora 19 的64位操作系统上,分别安装KVM,Xen和Virtualbox,并进行比较。

目前Fedora 19拥有搭载GCC 4.8.1的Linux 3.9.8版本内核,Mesa 9.2.0开发库和一个EXT4文件系统。所有的虚拟化组件都从Fedora 19的仓库中获取的,包括QEMU 1.4.2,Xen 4.2.2和libvirt/virt-manager组件。Xen和KVM的虚拟化通过virt-manager来建立。VirtualBox 4.2.16则是通过VirtualBox.org获取并安装在Fedora 19中。

Xen、KVM和VirtualBox比拼

这个英特尔酷睿i7 4770K机器拥有16GB的内存和240GB的OCZ Vertex 3 固态硬盘。在测试中,每一个虚拟机能够使用全部八个逻辑核心(四个物理核心加上超线程)、16GB内存中的12GB以及16GB的虚拟磁盘。

在采用英特尔酷睿i7 “Haswell”处理器的Linux 3.9版本内核的Fedora 19上安装的KVM,Xen和VirtualBox的性能也和在没有任何形式的虚拟化或其它抽象层上运行基准测试的“裸机(Bare Metal)”的性能进行了对比。VMWare的产品没有在这篇文章里被测试,因为它们的EULA特性限制了这种公开基准测试(尽管VMware在过去可以让我们正常地做这样的基准测试),并且它们的试用软件只能限制运行在四核CPU上。但以后的另外一篇文章会比较下在其它硬件上XEN/KVM/VMware的性能。

Xen、KVM和VirtualBox比拼

全部的Linux虚拟化基准测试采用完全自动化和可重复的方式进行处理,使用开源软件Phoronix Test Suite并由OpenBenchmarking.org支持。在使用虚拟磁盘而且Xen/KVM都没有一个可靠的访问主机驱动或GPU的方法以使用3D功能的情况下,这篇文章里的大部分基准测试都是集中在不同Linux虚拟化方法计算性能开销上。

Xen、KVM和VirtualBox比拼

磁盘测试在这里并不是虚拟化测试的一个重点,因为只有一个虚拟磁盘被主机的文件系统使用。然而,当把这三种Linux虚拟化方法与裸机结果进行比较时,运行在Linux 3.9内核上的KVM性能最好,其次是Xen。Oracle的Virtual仅仅跑出了主机上PostMark邮件服务器性能的66%,而KVM跑出了性能的96%,Xen是83%。

Xen、KVM和VirtualBox比拼

对于Dolfyn计算流体动力学的工作量,当运行在KVM或Xen上时,和裸机的运行结果相比并没有任何重大的变化。然而,VirtualBox则是明显变慢了。

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

FFTE和HMMer的结果和Dolfyn类似:Xen和KVM用很小的开销获得很好的性能,但Oracle的VirtualBox则慢得多。

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

当John The Ripper这个破解密码的程序在VirtualBox中运行时,则直接崩溃了。

Xen、KVM和VirtualBox比拼

运行TTSIOD渲染器时,在Linux 3.9 内核的Fedora 19上运行的Xen虚拟化方法获得了它的第一次性能比拼的胜利。

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

总之,运行在搭载英特尔酷睿i7 4770K处理器Fedora 19上的Xen和KVM虚拟化技术工作良好。这些虚拟化方法在Haswell处理器上的性能开销是最小的。当Xen和KVM在这款全新的英特尔处理器上运行良好的时候,Oracle的VirtualBox(最新版本,v4.2.16)相对慢得多。虽然VirtualBox的一个优点是支持客户机3D加速,但这会在未来的一篇Phoronix文章中再次进行测试。而把Haswell和前几代的英特尔处理器和AMD处理器比较不同虚拟化方法的性能开销也会在不久之后在Phoronix上进行测试。

 

 

 

 

虚拟化 KVM迁移到VirtualBox

时间:2013-07-17 09:36来源:未知 作者:admin 点击:

           

我最近 尝试 一些 从 我们 的 KVM 服务器 虚拟 机 迁移 到 我的笔记本电脑 在 我 的 VirtualBox的 安装 在 本地 运行 。 正如我 经历的过程 ,我意识到这 不是一件很容易 的 过程 , 所以 我决定要 记下 我的进程 。 它可能 并不完美 , 但 它为我工作 。 Lo

我最近尝试一些从我们的KVM服务器虚拟机迁移到我的笔记本电脑在我的VirtualBox的安装在本地运行。正如我经历的过程,我意识到这不是一件很容易的过程,所以我决定要记下我的进程。它可能并不完美,但它为我工作。

Locate Your KVM VM Managed by libvirt

We can use virsh for this. First let’s list all the VMs that belong to me:

[elatov@klaptop ~]$ virsh -c qemu+ssh://virtuser@kvm01/system list --all| grep kelatov  5     kelatov_win7_client2           running  -     kelatov-child-domain-client    shut off  -     kelatov-haproxy                shut off  -     kelatov-win2k8-DC2-Repl        shut off  -     kelatov-Win2k8-IIS2            shut off  -     kelatov-Win2k8_DC_Repl         shut off  -     kelatov_Win2k8-Child_DC        shut off  -     kelatov_Win2k8-DC2             shut off  -     kelatov_Win2k8_DC              shut off  -     kelatov_win7_client1           shut off 

I have a lot of them, first let’s move the kelatov_Win2k8-DC2 VM.

Locate the Disk Image Configured for the VM in libvirt KVM

virsh is your friend for that as well:

[elatov@klaptop ~]$ virsh -c qemu+ssh://virtuser@kvm01/system domblklist kelatov_Win2k8-DC2 Target     Source ------------------------------------------------ hda        /images/kelatov_win2k8r2.img hdc        - 

So our Disk Image file is under /images/kelatov_win2k8r2.img.

Copy Over the Disk Image File to the Local Machine

Now that we know the location of the disk file, let’s copy it over. First let’s create a folder and then let’s rsync the file over:

[elatov@klaptop ~]$ mkdir vm1 [elatov@klaptop ~]$ rsync -avzP virtuser@kvm01:/images/kelatov_win2k8r2.img vm1/. receiving incremental file list kelatov_win2k8r2.img  21474836480 100%   17.25MB/s    0:19:47 (xfer#1, to-check=0/1)  sent 30 bytes  received 6353239881 bytes  5350096.77 bytes/sec total size is 21474836480  speedup is 3.38 

Generate a libvirt Domain XML format Configuration of the KVM VM

libvirt uses a special XML format file to keep track of all the configurations for a VM. All the specifics of the XML file are here. Using virsh, generating the file is a breeze:

[elatov@klaptop ~]$ cd vm1/ [elatov@klaptop vm1]$ virsh -c qemu+ssh://virtuser@kvm01/system dumpxml kelatov_Win2k8-DC2 > kelatov_Win2k8-DC2.xml 

The file is pretty long, but just checking the top of the file, we should see something like this:

[elatov@klaptop vm1]$ head kelatov_Win2k8-DC2.xml  <domain type='kvm'>   <name>kelatov_Win2k8-DC2</name>   <uuid>b5188795-2be0-b229-7538-0fe7f2e930a3</uuid>   <memory>1048576</memory>   <currentmemory>1048576</currentmemory>   <vcpu>1</vcpu>   <os>     <type arch='x86_64' machine='rhel6.2.0'>hvm</type>     <boot dev='hd'></boot>   </os> 

libvirt keeps the configuration XML file under /etc/libvirt/qemu as well:

[virtuser@kvm01 ~]$ head /etc/libvirt/qemu/kelatov_Win2k8-DC2.xml <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE  OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:   virsh edit kelatov_Win2k8-DC2 or other application using the libvirt API. -->  </domain><domain type='kvm'>   <name>kelatov_Win2k8-DC2</name>   <uuid>b5188795-2be0-b229-7538-0fe7f2e930a3</uuid> 

So if you really wanted to, you could just rsync that file.

Convert RAW Format Disk Image (.img) to VMDK

Now that we have all the files:

[elatov@klaptop vm1]$ ls -1 kelatov_Win2k8-DC2.xml kelatov_win2k8r2.img 

Let’s create an OVF file, so we can import it into VirtualBox. To do  this, first we will need to convert our disk image to VMDK format. You  can use qemu-img to find out the exact format of the disk image file:

[elatov@klaptop vm1]$ qemu-img info kelatov_win2k8r2.img image: kelatov_win2k8r2.img file format: raw virtual size: 20G (21474836480 bytes) disk size: 20G 

So we are currently in RAW format. Here is the command we can use to convert it to VMDK format:

[elatov@klaptop vm1]$ qemu-img convert -O vmdk kelatov_win2k8r2.img kelatov_win2k8r2.vmdk -p     (100.00/100%) 

Convert Domain XML Format Configuration File to libvirt “image” XML Configuration File (virt-image)

For some reason, the virt-image and virt-convert commands can only convert from the image XML Descriptor file. From the virt-image man page:

virt-image is a command line tool for creating virtual machines from an        XML image descriptor "IMAGE.XML" (virt-image(5)). Most attributes of        the virtual machine are taken from the XML descriptor (e.g., where the        files to back the virtual machine's disks are and how to map them into        the guest), though certain information must be added on the command        line, such as the name of the guest.         The XML descriptor defines most attributes of the guest, making it        possible to bundle and distribute it together with the files backing        the guest's disks. 

And here is the section from virt-convert:

 Conversion Options        -i format          Input format. Currently, "vmx", "virt-image", and "ovf" are          supported. 

There have been other people wondering how to convert libvirt domain  XML file into other formats like the XML image format (virt-image),  VMware VMX, or even OVF. Here are some forums that talk about it:

  • virt-convert from libvirt to vmware
  •     

  • [libvirt] Intend to add OVA installation API
  •     

  • [libvirt-users] using virsh (or something) to convert from KVM domain XML to vmx…
  •     

  • [fedora-virt] exporting a vm image

but none of the above have been resolved yet.

There is a script that goes from vmx to libvirt domain XML format: vmware2libvirt. There is also a way to go from XML to VMX, and the process is described here.  But that only works if you already had converted a VMX to XML and then  converted it back. It never has instructions on how to start from XML  and go to VMX. On Fedora, I had to enable another repository to enable libvirt-client tools to have VMware/ESX support built it. Instructions on that can be seen at “Virtualization Preview Repository“. After you install the new libvirt-client tools you can then run commands against an ESX host:

[elatov@klaptop ~]$ virsh -c esx://vmware01/?no_verify=1 dumpxml kelatov-2 Enter username for vmware01 [root]:  Enter root's password for vmware01:  </domain><domain type='vmware'>   <name>kelatov-2</name>   <uuid>564d3355-1ee8-ce81-00fa-ef6c1a767850</uuid>   <memory unit='KiB'>4194304</memory>   <currentmemory unit='KiB'>4194304</currentmemory>   <vcpu placement='static'>2</vcpu>   <os>     <type arch='x86_64'>hvm</type>   </os>   <clock offset='utc'></clock>   <on_poweroff>destroy</on_poweroff>   <on_reboot>restart</on_reboot>   <on_crash>destroy</on_crash>   <devices>     <disk type='file' device='disk'>       <source file='[images] kelatov-2/kelatov-2.vmdk'/>       <target dev='sda' bus='scsi'></target>       <address type='drive' controller='0' bus='0' target='0' unit='0'></address>     </disk>     <disk type='block' device='cdrom'>       <source dev='cdrom1'/>       <target dev='hda' bus='ide'></target>       <address type='drive' controller='0' bus='0' target='0' unit='0'></address>     </disk>     <controller type='scsi' index='0' model='lsilogic'></controller>     <controller type='ide' index='0'></controller>     <interface type='bridge'>       <mac address='00:0c:29:76:78:50'></mac>       <source bridge='net1'/>       <model type='e1000'></model>     </interface>     <video>       <model type='vmvga' vram='4096'></model>     </video>   </devices> </domain> 

So if I had started out with ESX and was trying to go to KVM that would have been pretty easy (but at least now I can use virsh  to query an ESX server). Since no solution has been found, I decided to  write my own python script that converts from libvirt Domain XML format  to virt-image (XML Image Descriptor) XML format. The format of the XML  image descriptor is seen here. Here is an example of the format:

 < ?xml version="1.0" encoding="UTF-8"?>            <image>              <name>sysresccd</name>              <domain>                <boot type="hvm">                  <guest>                    <arch>i686</arch>                  </guest>                  <os>                    <loader dev="cdrom"></loader>                  </os>                  <drive disk="root.raw" target="hda"></drive>                  <drive disk="sysresc"></drive>                </boot>                <devices>                  <vcpu>1</vcpu>                  <memory>262144</memory>                  <interface></interface>                  <graphics></graphics>                </devices>              </domain>              <storage>                <disk file="root.raw" use="scratch" size="100" format="raw"></disk>                <disk ></disk>              </storage>            </image> 

Here is what I came up with:

[elatov@klaptop vm1]$ cat dom2img.py  #!/usr/bin/env python from xml.dom import minidom from xml.dom.minidom import Document import sys  # Read in first arguement input_file = sys.argv[1]  # parse our XML file xml = minidom.parse(input_file)  # Get the DomainName or the VM Name domainName = xml.getElementsByTagName('name') domain_name = domainName[0].childNodes[0].nodeValue  # Get the hypervisor Type domainHType = xml.getElementsByTagName('type') h_type = domainHType[0].childNodes[0].nodeValue  # Get the Arch and OS  domainOSInfo = xml.getElementsByTagName('type') for i in domainOSInfo:     domain_arch = i.getAttribute('arch')     domain_os = i.getAttribute('machine')  # Get Boot Device Type domainBootDevType = xml.getElementsByTagName('boot') for i in domainBootDevType:     boot_dev_type = i.getAttribute('dev')  # Get disk Device location for node in xml.getElementsByTagName("disk"):     if node.getAttribute("device") == "disk":         source = node.getElementsByTagName('source')         for s in source:             disk_loc = s.getAttribute('file')  # Get Boot Device  mapping = {} for node in xml.getElementsByTagName("disk"):     dev = node.getAttribute("device")     target = node.getElementsByTagName('target')     for t in target:         mapping[dev] = t.getAttribute('dev')  if boot_dev_type == 'hd':     boot_dev = mapping['disk'] elif boot_dev_type == 'cdrom':     boot_dev = mapping['cdrom']  # Get amount of CPUS domainVCPUs = xml.getElementsByTagName('vcpu') vcpu_count = domainVCPUs[0].childNodes[0].nodeValue  # Get amount of RAM domainMemory = xml.getElementsByTagName('memory') memory = domainMemory[0].childNodes[0].nodeValue  # Create an empty XML Document doc = Document()  # Create the "image" element image = doc.createElement("image") doc.appendChild(image)  # Create the Name Element name_element = doc.createElement("name") image.appendChild(name_element) name_text = doc.createTextNode(domain_name) name_element.appendChild(name_text)  # Create the Label Element label_element = doc.createElement("label") image.appendChild(label_element) label_text = doc.createTextNode(domain_name) label_element.appendChild(label_text)  # Create the Description Element desc_element = doc.createElement("description") image.appendChild(desc_element) desc_text = doc.createTextNode(domain_os) desc_element.appendChild(desc_text)  # Create the Domain Element domain_element = doc.createElement("domain") image.appendChild(domain_element)  # Create boot element boot_element = doc.createElement("boot") boot_element.setAttribute("type",h_type ) domain_element.appendChild(boot_element)  # Create guest Element guest_element = doc.createElement("guest") boot_element.appendChild(guest_element)  # Create the arch attribute arch_element = doc.createElement("arch") guest_element.appendChild(arch_element) arch_text = doc.createTextNode(domain_arch) arch_element.appendChild(arch_text)  # Create OS Element os_element = doc.createElement("os") boot_element.appendChild(os_element)  # Create the loader element and set the dev attribute loader_element = doc.createElement("loader") loader_element.setAttribute("dev",boot_dev_type) os_element.appendChild(loader_element)  # Create drive element and set it's attributes drive_element = doc.createElement("drive") drive_element.setAttribute("disk", disk_loc) drive_element.setAttribute("target", boot_dev) boot_element.appendChild(drive_element)  # Create device Element devices_element = doc.createElement("devices") domain_element.appendChild(devices_element)  # Create VCPU text vcpu_element = doc.createElement("vcpu") devices_element.appendChild(vcpu_element) vcpu_text = doc.createTextNode (vcpu_count) vcpu_element.appendChild(vcpu_text)  # Create Memory text memory_element = doc.createElement("memory") devices_element.appendChild(memory_element) memory_text = doc.createTextNode(memory) memory_element.appendChild(memory_text)  # Create interface element interface_element = doc.createElement("interface") devices_element.appendChild(interface_element)  # Create graphics element graphics_element = doc.createElement("graphics") devices_element.appendChild(graphics_element)  # Create storage element storage_element = doc.createElement("storage") image.appendChild(storage_element)  # create disk element and set it's attributes disk_element = doc.createElement("disk") disk_element.setAttribute("file",disk_loc) disk_element.setAttribute("format","vmdk") disk_element.setAttribute("use","system") storage_element.appendChild(disk_element)  f = open(input_file + '_converted', 'w') f.write (doc.toprettyxml(indent=" ",encoding="utf-8")) f.close() 

It basically takes in one argument, the domain XML file to be  converted, and produces a new file with “converted” appended to the  original filename. Here is what I did to run the conversion:

[elatov@klaptop vm1]$ ./dom2img.py kelatov_Win2k8-DC2.xml 

Now to check out both files, here is the original:

[elatov@klaptop vm1]$ head kelatov_Win2k8-DC2.xml <domain type='kvm'>   <name>kelatov_Win2k8-DC2</name>   <uuid>b5188795-2be0-b229-7538-0fe7f2e930a3</uuid>   <memory>1048576</memory>   <currentmemory>1048576</currentmemory>   <vcpu>1</vcpu>   <os>     <type arch='x86_64' machine='rhel6.2.0'>hvm</type>     <boot dev='hd'></boot>   </os> 

And here is the converted one:

[elatov@klaptop vm1]$ head kelatov_Win2k8-DC2.xml_converted  < ?xml version="1.0" encoding="utf-8"?> <image>  <name>kelatov_Win2k8-DC2</name>  <label>kelatov_Win2k8-DC2</label>  <description>rhel6.2.0</description>  <domain>   <boot type="hvm">    <guest>     <arch>x86_64</arch>    </guest>    <os> 

Convert XML Image Descriptor to VMX

Luckily virt-convert can handle this:

[elatov@klaptop vm1]$ virt-convert -i virt-image kelatov_Win2k8-DC2.xml_converted -o vmx kelatov_Win2k8-DC2.vmx Generating output in 'vmx' format to /home/elatov/vm1/ Converting disk '/images/kelatov_win2k8r2.img' to type vmdk... Done. 

Now checking out the VMX file:

[elatov@klaptop vm1]$ head -20 kelatov_Win2k8-DC2.vmx  #!/usr/bin/vmplayer  # Generated by virt-convert # http://virt-manager.org/  # This is a Workstation 5 or 5.5 config file and can be used with Player config.version = "8" virtualHW.version = "4" guestOS = "other" displayName = "kelatov_Win2k8-DC2" annotation = "rhel6.2.0" guestinfo.vmware.product.long = "kelatov_Win2k8-DC2" guestinfo.vmware.product.url = "http://virt-manager.org/" guestinfo.vmware.product.class = "virtual machine" numvcpus = "1" memsize = "1024" MemAllowAutoScaleDown = "FALSE" MemTrimRate = "-1" uuid.action = "create" 

That doesn’t look too bad.

Create OVF from VMX and VMDK

Let’s first fix the disk location, right now it’s still pointing to the .img file:

[elatov@klaptop vm1]$ grep img kelatov_Win2k8-DC2.vmx ide0:0.fileName = "/images/kelatov_win2k8r2.img" 

Since the VMDK is located in the same directory:

[elatov@klaptop vm1]$ ls -1 dom2img.py kelatov_Win2k8-DC2.vmx kelatov_Win2k8-DC2.xml kelatov_Win2k8-DC2.xml_converted kelatov_win2k8r2.img kelatov_win2k8r2.vmdk 

Let’s edit the VMX file:

[elatov@klaptop vm1]$ vi kelatov_Win2k8-DC2.vmx 

and fix the location to be relative to the current directory:

[elatov@klaptop vm1]$ grep vmdk kelatov_Win2k8-DC2.vmx  ide0:0.fileName = "kelatov_win2k8r2.vmdk" 

That looks good, now let’s create the OVF. More information regarding installing and using ovftool is seen at “Migrating a VM from VMware Workstation to Oracle VirtualBox“. Here is the command I ran to create our OVF:

[elatov@klaptop vm1]$ ovftool kelatov_Win2k8-DC2.vmx kelatov_Win2k8-DC2.ovf Opening VMX source: kelatov_Win2k8-DC2.vmx Opening OVF target: kelatov_Win2k8-DC2.ovf Writing OVF package: kelatov_Win2k8-DC2.ovf Transfer Completed                     Completed successfully 

After it was done, I had the following files:

[elatov@klaptop vm1]$ ls -rt1  kelatov_win2k8r2.img  kelatov_Win2k8-DC2.xml  kelatov_win2k8r2.vmdk  kelatov_Win2k8-DC2.xml_converted  dom2img.py  kelatov_Win2k8-DC2.vmx  kelatov_Win2k8-DC2-disk1.vmdk  kelatov_Win2k8-DC2.ovf  kelatov_Win2k8-DC2.mf 

The bottom 3 files were created by the OVF creation process.

Import OVF into VirtualBox

Doing a VirtualBox dry-run import, I saw the following:

[elatov@klaptop vm1]$ VBoxManage import -n kelatov_Win2k8-DC2.ovf 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Interpreting /home/elatov/vm1/kelatov_Win2k8-DC2.ovf... OK. Disks:  vmdisk1 20  17550934016 http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized   kelatov_Win2k8-DC2-disk1.vmdk   6997323776  -1   Virtual system 0:  0: Suggested OS type: "Other"     (change with "--vsys 0 --ostype <type>"; use "list ostypes" to list all possible values)  1: Suggested VM name "vm"     (change with "--vsys 0 --vmname <name>")  2: Description "rhel6.2.0"     (change with "--vsys 0 --description <desc>")  3: Number of CPUs: 1     (change with "--vsys 0 --cpus <n>")  4: Guest memory: 1024 MB     (change with "--vsys 0 --memory <mb>")  5: Network adapter: orig nat, config 2, extra type=nat  6: IDE controller, type PIIX4     (disable with "--vsys 0 --unit 6 --ignore")  7: Hard disk image: source image=kelatov_Win2k8-DC2-disk1.vmdk, target path=/home/elatov/.virt/vm/kelatov_Win2k8-DC2-disk1.vmdk, controller=6;channel=0     (change target path with "--vsys 0 --unit 7 --disk path";     disable with "--vsys 0 --unit 7 --ignore") 

I liked the outcome: memory, CPU, and hard disk information was  correct. I decided to run the import and at the same time I changed the  OS type and the name. Here is how the whole process looked like:

[elatov@klaptop vm1]$ VBoxManage import kelatov_Win2k8-DC2.ovf --vsys 0 --ostype Windows2008_64 --vsys 0 --vmname kelatov_win2k8_DC 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Interpreting /home/elatov/vm1/kelatov_Win2k8-DC2.ovf... OK. Disks:  vmdisk1 20  17550934016 http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized   kelatov_Win2k8-DC2-disk1.vmdk   6997323776  -1   Virtual system 0:  0: OS type specified with --ostype: "Windows2008_64"  1: VM name specified with --vmname: "kelatov_win2k8_DC"  2: Description "rhel6.2.0"     (change with "--vsys 0 --description <desc>")  3: Number of CPUs: 1     (change with "--vsys 0 --cpus <n>")  4: Guest memory: 1024 MB     (change with "--vsys 0 --memory <mb>")  5: Network adapter: orig nat, config 2, extra type=nat  6: IDE controller, type PIIX4     (disable with "--vsys 0 --unit 6 --ignore")  7: Hard disk image: source image=kelatov_Win2k8-DC2-disk1.vmdk, target path=/home/elatov/.virt/vm/kelatov_Win2k8-DC2-disk1.vmdk, controller=6;channel=0     (change target path with "--vsys 0 --unit 7 --disk path";     disable with "--vsys 0 --unit 7 --ignore") 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Successfully imported the appliance. 

I then launched VirtualBox and powered on the VM, it booted without any issues:

Xen、KVM和VirtualBox比拼

 

(责任编辑:admin)

 

 

尝试在虚拟机多开系统, Guest OS是WinXP 硬件平台为I5四核,DDRIII 8G 想要实现10-12台虚拟机同时开 每台任务:firefox开一个标签看视频,循环看不同的网络视频,24小时全开…
1>最开始试的是KVM Host系统debian 6 64bit 开了virtio、writeback模式 做Guest系统用的是Ghost版,速度为1000M还原速度 <ignore_js_op>Xen、KVM和VirtualBox比拼 测试平台(点击图片看大图)

  VirtualBox 4.1.2、KVM、和Xen 4.1.1都是在Ubuntu Oneiric上进行安装。Ubuntu 11.10也证明了Xen虚拟化对DomU客户机的支持。不过虽然Xen现在能在Ubuntu上大展身手,但Canonical仍将KVM视作主要的Linux虚拟化技术并加以不断支持。VMware的 Linux虚拟化没有在此次测试中提及,主要是考虑到使用条件方面的限制会影响到基准测试。

  除了VirtualBox、Xen、和KVM的基准测试,我们也会公布Sandy Bridge系统在裸机上的基准测试以供参考。

Xen、KVM和VirtualBox比拼 C-Ray多线程运算测试

  首先,我们采用C-Ray来测试多线程运算性能。从图中我们可以看到,使用KVM虚拟化表现出的运算性能出众。KVM客户机实例能够以91%的裸机运算速度来处理多线程,而Sandy Bridge上的VirtualBox和Xen DomU客户机的运算速度分别为85%和68%。

Xen、KVM和VirtualBox比拼 POV-Ray渲染测试

  POV-Ray 3.6.1是一款单线程、图像渲染测试工具,KVM表现仍然领先 。KVM的渲染速度几乎和使用Linux 3.0 kernel的Sandy Bridge笔记本裸机上的效果相仿。紧随其后的则是VirtualBox,Xen则被远远落在后面。

  加密测试VirtualBox和KVM持平

  Smallpt全局照明渲染测试中,测试结果大体不变:KVM仍然是运算最快的Linux虚拟化平台,随后则是VirtualBox和Xen。


Xen、KVM和VirtualBox比拼 全局照明渲染测试

  在密码测试方面,我们看到KVM仍然保持遥遥领先。其运算速度达到了裸机性能的97%,其次,就是VirtualBox和Xen DomU。后者的运算速度仅为裸机的69%。在对MD5算法进行测试的情况下,测试结果大体一致。

Xen、KVM和VirtualBox比拼 传统DES密码测试

Xen、KVM和VirtualBox比拼 MD5密码测试

  在使用Blowfish进行加密测试的时候,VirtualBox和KVM速度几乎相同,然而DomU客户机的性能与它们却有着30%的差距。

Xen、KVM和VirtualBox比拼 Blowfish加密测试

  在运行OpenSSL的时候其产生的结果,与刚才使用的John The Ripper测试工具得出的结果类似。

Xen、KVM和VirtualBox比拼 利用OpenSSL对4096位字符串进行密码测试

  并行处理测试KVM表现最好

  在KVM实例上运行7-Zip进行解压缩测试时,我们发现其性能只降低了10%,然而使用VirtualBox和Xen,其性能损失分别为15%和30%。


Xen、KVM和VirtualBox比拼 7-Zip解压缩测试

  NAS Parallel并行处理测试中,整体来看KVM表现仍然最为优秀,而Xen表现最差。

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

Xen、KVM和VirtualBox比拼

 

  VT-x技术助KVM大展身手

  在多序列比对软件MAFFT测试中(数值越低越好),KVM仍然表现出众。


Xen、KVM和VirtualBox比拼

  在处理OpenMP方面,KVM表现出的效率也最高。

Xen、KVM和VirtualBox比拼

  对CPU进行的各种压力测试转移到对磁盘测试上,我们也同样看到,KVM仍然不负众望,而Xen的表现也快速得到提升,几乎与KVM持平。VirtualBox表现最差。需要指出的是,这些测试数据都采用了默认的磁盘格式,是基于Apache的静态网页负载测试。

Xen、KVM和VirtualBox比拼

  在PostMark磁盘测试中,KVM性能损失几乎为20%(相比裸机),而VirtualBox则跌去了25%,Xen几乎下降了一半。

Xen、KVM和VirtualBox比拼

  SQLite测试出来的最快虚拟化方案当属甲骨文的VirtualBox,它甚至比裸机的表现还要出色(数值越小表现越佳)。不过,其中的奥秘恐怕在于VirtualBox并不会强迫执行SQLite的Sync/FSync请求。

Xen、KVM和VirtualBox比拼

  综上,从运算性能和磁盘负载角度来说Linux KVM不失为最快的虚拟化解决方案(单线程或者多线程)。得益于英特尔VT-x技术的Sandy Bridge 酷睿i7硬件平台,KVM(Kernel-based Virtual Machine)表现尤为出众。除了最后一项SQLite之外的其他所有测试,KVM都提供了最好的成绩。相比之下,VirtualBox在测试中排名第二,而Xen在HVM模式下的虚拟化表现最差。

  如果要说VirtualBox对比KVM的优势,恐怕要数其目前支持的2D/3D加速技术,通过该技术可以在客户机上重定向至主机的显卡上。Xen同样也支持通过PCI传入和控制显卡。当然,通过Gallium3D驱动支持,VMware也能提供2D/3D加速技术。

 

酷毙

8

 

 

 

 

 

原文链接:https://www.cnblogs.com/timssd/p/4449212.html
本文来源 爱码网,其版权均为 原网址 所有 与本站无关,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源。

© 版权声明

相关文章