Linux Virtualization with Xen
Xen is the new virtualization kid on the block. It's gaining visibility and importance at a speed only projects such as Linux and Apache have seen before. Xen has been around for a couple of years: it was originally part of the Xenoserver platform, which aimed to build a public infrastructure for wide-area distributed computing. Ian Pratt, the principal investigator of the Xenoserver project at the University of Cambridge Computer Laboratory, still leads the development team.
Xen ended up being much more than a part of this project. Now many Linux distributions and some hardware vendors are picking it up. As with many important open source projects these days, it even has a company--Xensource--backing commercial versions and providing support for corporate customers. Xensource also employs several industry veterans. In short, Xen(source) has everything a good open source platform need to becomes an extremely important player in the industry.
At X-Tend, one of our main problems was that we didn't have enough machines to test all new distributions and applications. Basically there was no financially realistic way to provide our users with a quick test environment. My guess is that half of the planet has similar problems.
Ages ago, we used UserModeLinux, but most new users found it too complex to use. Later, we bootstrapped Qemu instances from our central imaging server. That worked. If we wanted to do some tests on an isolated environment, we quickly started Qemu with the distribution we needed. The only annoyance was that we actually wanted an environment that was constantly online and, in the event of a power outage (this is a test environment, not production), we didn't have to spend too much time getting it back. It had to be scriptable and automatable, and preferably would not require X.
With the arrival of Xen last year, all of that changed. This article describes how we tackled our problem and how we actually now have a stable and performant environment to test everything we want. It's so stable, we now use Xen for production environments!
What's Xen?
Xen is a virtual machine monitor for x86 that supports the execution of multiple guest operating systems with unprecedented levels of performance and resource isolation. Xen is open source software, released under the terms of the GNU General Public License.
Xen has become one of the most popular virtualization platforms during the last six months. Although it's not such a young project, it is now gaining acceptance in the corporate world as a valuable alternative to VMWare.
Adding Xen to your machine changes it from an ordinary x86 machine to a totally new platform. It's not an x86 anymore. It's a Xen machine. All the operating systems that you want to run on your machine won't work anymore if they know only aboutx86; they need to know about Xen. Of course, the Xen and x86 architecture are really similar, so for the end user and the applications that run on a platform ported to Xen, there is almost no difference.
When Xen is activated, it will also need to boot its first virtual machine, called Domain0. Domain0 has more privileges than the other virtual machines and typically is used only for managing the other (less privileged) virtual machines. Domain0 is also responsible for managing the hardware. Porting a platform to Xen changes almost nothing to the drivers, which means that most drivers supported in traditional Linux kernels also work in Xen.
Within Domain0, the xend daemon handles the management of the virtual machines. Control it via the xm command-line utility.
From there, you can create other virtual machines, or domains.
Xen and Different Distributions
We've been running Xen on different platforms ranging from an "antique" Suse 8.2 with a 2.4 series kernel, a Debian box, and Fedora Core 4 with a fresh 2.6 kernel. Unlike some other projects, Xen currently doesn't care whether you use 2.4 or 2.6, so people who are comfortable with a 2.4 kernel can still benefit from the Xen features. However, future releases probably won't have 2.4 support. People claim that installing Xen is difficult, but it's not, certainly if you compare it with other similar tools. GetXen.org is the place to start; it contains a tarball with most of the required binaries and tools, a demo CD, and pointers to the source code. Some distributions such as Fedora include prebuilt packages. As of this writing, the official stable Xen release is 2.0.7, but most people are already working with the 3.0 betas. 3.0 might be out by the time you actually read this.
It's really easy to start. Here's how we deployed a Debian virtual machine on a Fedora Core 4 install. We opted for a minimal FC4 install. After the installation, we updated, upgraded, and installed Xen with a couple of small commands:
$ yum update
$ yum install xen
$ yum install kernel-xen0
$ yum install kernel-xenU
Can it get easier? You should now carefully inspect your grub.conf file and find a part similar to:
title Xen 2.0 / XenLinux 2.6.9
kernel /boot/xen.gz dom0_mem=131072
module /boot/vmlinuz-2.6.9-xen0 root=/dev/hda1 ro console=tty0
Your version numbers may vary. If that's there, then it's time to reboot into that new entry. Voilá, you now have your first virtual machine up and running. Yes, at first sight the regular Linux version you have just booted into isn't running on a regular x86 anymore but is running on a Xen.
If you already started xend at boot time, run xm list to see output similar to:
HOSTA:/etc/xen/scripts # xm list
Name Id Mem(MB) CPU State Time(s) Console
Domain-0 0 123 0 r---- 41.2
Building a Virtual Host
Your next step is to create another virtual machine. The easiest way to do this is either to download an existing chroot image of the distribution you like or to build one yourself. Xen can use file-backed virtual block devices (dd if=/dev/zero of=vmdisk bs=1k seek 2048k count=1), physical devices (the actual /dev/hda9), LVM volumes (phy:VolumeGroup/root_volume), or an NFS root for your virtual machines. I prefer to use logical volumes on my machines, as they are really flexible to work with. With an existing disk /dev/sda5 available, I created logical volumes to use in my virtual machine:
$ pvcreate /dev/sda5
$ vgcreate vm_volumes /dev/sda5
$ vgchange -a y vm_volumes
$ lvcreate -L4096 -nroot.dokeos vm_volumes
$ lvcreate -L2048 -nvar.dokeos vm_volumes
$ lvcreate -L256 -nswap.dokeos vm_volumes
$ lvcreate -L1024 -nwww.dokeos vm_volumes
I usually create a directory /vhosts on my dom0 host where I mount my partitions. From there, I install the first FC4 base packages in a chroot on the actual future root device.
$ yum --installroot=/vhosts/root.dokeos/ -y groupinstall Base
You need to make a couple of quick fixes to make sure that you can open your initial console and so forth:
$ MAKEDEV -d /path/dev -x console
$ MAKEDEV -d /path/dev -x null
$ MAKEDEV -d /path/dev -x zer
It's almost ready. Now you need the configuration file for this virtual machine. Most of Xen's config files live in /etc/xen. You need a separate config file for each virtual machine you want to deploy on your host. They look like:
[root@xen xen]# cat dokeos.x-tend.be
kernel = "/boot/vmlinuz-2.6.11-1.1366_FC4xenU"
memory = 128
name = "dokeos.x-tend.be"
nics = 1
extra = "selinux=0 3"
vif = ['ip = "10.0.11.13", bridge=xen-br0']
disk = ['phy:vm_volumes/root.dokeos,sda1,w'
,'phy:vm_volumes/var.dokeos,sda3,w'
,'phy:vm_volumes/www.dokeos,sda4,w'
,'phy:vm_volumes/swap.dokeos,sda2,w'
]
root = "/dev/sda1 ro"
The config file is rather straightforward, and the Xen packages include examples. Now start your virtual machine with the command xm create config file. Add a -c to that command to see the machine booting. You should get a login prompt within seconds. That's how fast a physical machine should also boot, but I'll keep on dreaming for a couple of years.
If you create a symlink to the /etc/xen/auto directory, your virtual machines will start at boot time, if you enable thexendomains script at boot time
Linux Virtualization with Xen的更多相关文章
- 检测Linux VPS是Xen、OpenVZ还是KVM真假方法
如果大家对自己购买和使用的VPS需要检测是否为真的Xen,我们可以用如下方法进行测试.比较专业的就是用virt-what脚本进行检测.检测Linux VPS是Xen.OpenVZ还是KVM真假方法方法 ...
- 检测linux vps是xen openvz还是kvm的方法
很多时候不知道自己买的vps是那种虚拟化技术,怕给商家忽悠了,下面给大家介绍下怎么简单的判断自己vps的虚拟化技术. 1.通过系统上的相关目录或文件判断 ll /proc/ ps: /proc目录 ...
- Linux中为XEN网桥绑定物理网卡
XEN虚拟机会默认将可以连通外网的网卡绑定到xenbr0上, 因此如果需要切换到其他物理网卡上时,需要自己配置脚本或执行命令. 1.添加脚本绑定 a.编写一个脚本,指定网卡与网桥绑定的关系 # vim ...
- <Mastering KVM Virtualization>:第一章 了解Linux虚拟化
本章为读者提供了Linux虚拟化中流行技术的深刻见解,以及相较于其他同类技术的优势特点.本书共有14章,囊括了KVM虚拟化中的各个方面,从KVM的内部构造开始,并包括了诸如软件定义网络(SDN),性能 ...
- Virtio: An I/O virtualization framework for Linux
The Linux kernel supports a variety of virtualization schemes, and that's likely to grow as virtuali ...
- Virtualization solutions on Linux systems - KVM and VirtualBox
Introduction Virtualization packages are means for users to run various operating systems without &q ...
- Xen虚拟化基本原理详解
标签:虚拟化 xen 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wangzan18.blog.51cto.com/80210 ...
- Xen
Xen是一个开放源代码虚拟机监视器,由剑桥大学开发.它打算在单个计算机上运行多达128个有完全功能的操作系统. 在旧(无虚拟硬件)的处理器上执行Xen,操作系统必须进行显式地修改(“移植”)以在Xen ...
- 虚拟化之kvm与xen对比
xen XenServer is the leading open source virtualization platform, powered by the Xen Project hypervi ...
随机推荐
- HDFS(三)
DataNode 下面的数据文件有两种类型,一种是数据块,一种是数据块的描述文件(元数据文件),后者文件后面带有.meta后缀: Version文件字段内容其实和NameNode里面涵义是一致的: 安 ...
- MySQL 性能优化技巧
原文地址:MySQL 性能优化技巧 博客地址:http://www.extlight.com 一.背景 最近公司项目添加新功能,上线后发现有些功能的列表查询时间很久.原因是新功能用到旧功能的接口,而这 ...
- 关于ng-class,ng-style的用法
ng-class的使用几种方式 (1):利用双向数据绑定(className根据chang2的值去匹配类) <div class="{{className}}">... ...
- (转)Inno Setup入门(二十一)——Inno Setup类参考(7)
本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17268435 复选框 复选框(CheckBox)用于多个并不互斥的几 ...
- css响应式设计
响应式设计是指在不同分辨率的设备中,网页布局可以自适应的调整.这种弹性化的布局使网站在不同设备中的布局都比较合理,可以为不同终端的用户提供更加舒适的界面和更好的用户体验,其根本理念是使原本 PC 上的 ...
- mongoDB的权限管理
最近做一个关于mongoDB权限的功能, 在网上找了好久,各种命令,各种配置,各种修改,都没有解决哥的困惑.无奈,睡一觉后,灵光乍现,灵感来了. 下面就是我的最新发现,当然在各位看官的眼里,我的这个也 ...
- 【UVA】1594 Ducci Sequence(纯模拟)
题目 题目 分析 真的快疯了,中午交了一题WA了好久,最后发现最后一个数据不能加\n,于是这次学乖了,最后一组不输出\n,于是WA了好几发,最后从Udebug发现最后一组是要输出的!!! ...
- iOS开发API常用英语名词
iOS开发API常用英语名词 0. indicating 决定 1.in order to 以便 2.rectangle bounds 矩形尺寸 3.applied 应用 4.entirety 全部 ...
- windows administrator提升system
最近刚好有这个需求,本想开一个super cmd,但是win10上不兼容不太好. 于是使用PsExec来提升system权限. 微软传送地址:https://docs.microsoft.com/en ...
- php redis pub/sub(Publish/Subscribe,发布/订阅的信息系统)之基本使用
一.场景介绍 最近的一个项目需要用到发布/订阅的信息系统,以做到最新实时消息的通知.经查找后发现了redis pub/sub(发布/订阅的信息系统)可以满足我的开发需求,而且学习成本和使用成本也比较低 ...