Believe it or not, we are under an age called Cloud Computing.
I used to be curious about VPS(Virtual Private Server), how they work, how to build them, etc. As far as I know, AWS, GCE or whatever else solutions depend heavily on Virtualization Technologies and AWS is definitly playing with Xen currently.
I would like very much to have a trial for building my own VPS and blow are my steps doing it. You may need to read some basic wikis about Xen, Xen Overview and Xen Beginners Guide should do some help:–)
Getting a working Dom0 on Centos6.4
Use whatever way you like, remember a minimal install is recommended.
Thanks to Xen4Centos Project, we can get Xen installed in several simple commands(log in as root).
yum -y update yum install centos-release-xen yum install xen /usr/bin/grub-bootxen.sh reboot
After your machine comes to alive, simply type:
uname -r xl list
to verify that Xen Dom0 is running.
I use DHCP to get a valid IP for my box and there is a trick if you can’t ping each other when two machinea are in the same LAN(probably the routing table is not working for you and just delete the record from your routing table).
As me, for example, my laptop got a IP, say 192.168.0.10 and my VPS got 192.168.0.11, but they can’t talk to each:–(
First, check your routing table,
Then, delete the record that is evil,
route del -net 192.168.0.0 netmask 255.255.255.0
Please substitute the parameters to suite your own networking.
After that, ping each other,
to verify the networking is good to go.
In order to give our DomUs valid IPs, we may use a network bridge, do as follows:
yum -y install bridge-utils cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-xenbr0
My modified and working scripts look like this, for ifcfg-xenbr0:
DEVICE=xenbr0 #HWADDR=00:24:E8:46:CC:C9 TYPE=bridge #UUID=ff0ab497-0303-4dc3-b6f3-4a6cbd90466b ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=dhcp
And for ifcfg-eth0:
DEVICE=eth0 HWADDR=00:24:E8:46:CC:C9 TYPE=Ethernet UUID=ff0ab497-0303-4dc3-b6f3-4a6cbd90466b ONBOOT=yes NM_CONTROLLED=no #BOOTPROTO=dhcp BRIDGE=xenbr0
For static IP configuration, please refer to Xen wiki page!
Then, make the configuration work:
service network restart
If you got errors such as
error:check cable, do this manualy:
Verify it works by issuing:
Honestly speaking, I don’t know WTF the real reason to do this, but people say
SELinux can really interfere with Xen.
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
You are good to go with a damn working Dom0 and congratulations!
Bringing Your DomUs Up
It’s up to you to use PV or HVM, personally, I prefer to PV due to higher performance. But if you want a Windows(and other OS whose kernel can’t be modified), HVM is your only choice.
As for me, I want 3 DomUs, namely Debian, Fedora and Arch Linux.
Xen4Cli or Xen4Libvirt
Xen4Cli(xm and xl, currently xm deprecated) are intended for advanced users looking to hand setup the network, the backing filestore and the xen environment. While Xen4Libvirt are for newbies looking for the easiest install path.
xl since I want to know what exactly is happening, and
xl works for Debian and Arch Linux. However for Fedora,
Libvert seems to be the right way(using
To install Libvirt,
yum install libvirt python-virtinst libvirt-daemon-xen
After the install, restart your Dom0 machine.
File or LVM based backend
Since Centos6.4 is shipped perfectly with LVM and also the default partition schema using LVM during OS Installation, I prefer
As for me, I do the following:
lvresize -L -200G vg_centos6/lv_home -r lvcreate -L 30G -n fedora vg_centos6 lvcreate -L 30G -n debian vg_centos6 lvcreate -L 30G -n archlinux vg_centos6
Then verify the Logical Volumes using:
If you are not familiar with LVM, search Google for a good tutorial first.
Bridge, Routing or NAT
Three networking modes are provided and choose one according to your own networking environment.
I got bridge working for me as described in above section.
For choosing other modes, you can modify
/etc/xen/xend-config.sxp or explicitly passing as parameters when creating DomUs.
Let DomUs fly
I choose debian7.1 netinst.iso due to my poor bandwidth,
wget -c http://mirrors.sohu.com/debian-cd/7.1.0/amd64/iso-cd/debian-7.1.0-amd64-netinst.iso mount -o loop /path/to/debian-7.1.0-amd64-netinst.iso /mnt/debian cp /mnt/debian/install.amd/xen/debian.cfg /etc/xen/ cd /etc/xen/ vi debian.cfg ## Make modifications according to the comments xl create -c debian.cfg
Then install Debian as a very normal one.
I download archlinux-2013.10.01-dual.iso by issuing:
Then create a arch.cfg file in
/etc/xen/ similar like:
# Refer to https://wiki.archlinux.org/index.php/Xen#Configuring_a_paravirtualized_.28PV.29_Arch_domU name = "arch" kernel = "/mnt/arch/arch/boot/x86_64/vmlinuz" ramdisk = "/mnt/arch/arch/boot/x86_64/archiso.img" extra = "archisobasedir=arch archisolabel=ARCH_201310" memory = 512 disk = [ "phy:/dev/vg_centos6/archlinux,sda1,w", "file:/root/isos/arch/archlinux-2013.10.01-dual.iso,sdb,r" ] vif = [ '' ]
After that, bring the DomU up by:
mount /path/to/archlinux-2013.10.01-dual.iso /mnt/arch cd /etc/xen/ xl create -c arch.cfg
Install your Arch Linux as you like since it’s really a highly customized distro.
Again I got Fedora-20-Alpha-x86_64-netinst.iso by issuing:
However, nightmares begin since I want to install it using the Debian way.
xl just fails to boot normally but
virt-install does the job.
virt-install --virt-type xen -n fedora19 -r 512 --vcpus=2 -f /dev/vg_centos6/fedora19 --location http://mirrors.163.com/fedora/releases/19/Fedora/x86_64/os/ --os-type linux --accelerate --nographics --network=bridge:xenbr0
Or you can download the ISO file first, then issuing your own httpd locally, thus making it:
mount -o loop /path/to/fedora.iso /mnt/fedora yum -y install httpd service httpd start ln -s /mnt/fedora /var/www/html service iptables stop virt-install --virt-type xen -n fedora19 -r 512 --vcpus=2 -f /dev/vg_centos6/fedora19 --location http://your.http.server.ip.address.here/ --os-type linux --accelerate --nographics --network=bridge:xenbr0
Remember this is for full Fedora installation, if you are using a netinst, you need to copy all the files to /var/www/html instead of creating a symbolic link and modify the .treeinfo file. No warrants here, since I did’t try it myself.
- Xen4 CentOS6 QuickStart
- Xen4 Libvirt for CentOS 6
- Install Xen 4 with Libvirt / XL on CentOS 6 (2013)
- Virtualization With Xen On CentOS 6.2 (x86_64) (Paravirtualization & Hardware Virtualization)
- Xen Configuration File Options
- XL Domain Configuration File Syntax
- Network Configuration Examples (Xen 4.1+))
- Debian Guest Installation Using Debian Installer
- Xen For Arch Linux Wiki page
- Arch Linux Installation Guide
- Install Fedora 10 PV DomU at Xen 3.3.1 CentOS 5.2 Dom0 & Xen 3.3.0 Intrepid Server Dom0 (Novell’s Xen-ified Kernel) via local Apache Mirror
- Installing a domU without virt-install Fedora-xen
- CentOS 6安装配置Xen
- Archlinux 简明安装指南
- archlinux （2012.12.01-dual） i686 硬盘安装
- Choice of Toolstacks
I do believe you will get lots of annoying problems while playing with Xen. Enjoy the problems and enjoy Xen:–)