Virtualization With Xen On CentOS 6.2 (x86_64) (Paravirtualization & Hardware Virtualization)
Rabu, 08 Februari 2012
0
komentar
This tutorial provides step-by-step instructions on how to install Xen (version 4.1.2) on a CentOS 6.2 (x86_64) system.
Xen lets you create guest operating systems (*nix operating systems like Linux and FreeBSD), so called "virtual machines" or domUs, under a host operating system (dom0). Using Xen you can separate your applications into different virtual machines that are totally independent from each other (e.g. a virtual machine for a mail server, a virtual machine for a high-traffic web site, another virtual machine that serves your customers' web sites, a virtual machine for DNS, etc.), but still use the same hardware. This saves money, and what is even more important, it's more secure. If the virtual machine of your DNS server gets hacked, it has no effect on your other virtual machines. Plus, you can move virtual machines from one Xen server to the next one.
I will use CentOS 6.2 (x86_64) for both the host OS (dom0) and the guest OS (domU).
This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.
This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 Preliminary Note
This guide will explain how to set up image-based virtual machines and also LVM-based virtual machines.Make sure that SELinux is disabled or permissive:
vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system. |
reboot
2 Creating A Network Bridge
We need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.To do this, we install the package bridge-utils...
yum install bridge-utils
... and configure a bridge. Create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the IPADDR, PREFIX, GATEWAY, DNS1 and DNS2 values from the /etc/sysconfig/network-scripts/ifcfg-eth0 file); make sure you use TYPE=Bridge, not TYPE=Ethernet:vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0" |
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" |
/etc/init.d/network restart
... and runifconfig
It should now show the network bridge (br0):[root@server1 ~]# ifconfig
br0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1196 (1.1 KiB) TX bytes:2794 (2.7 KiB)
eth0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4554 errors:0 dropped:0 overruns:0 frame:0
TX packets:3020 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6249612 (5.9 MiB) TX bytes:254928 (248.9 KiB)
Interrupt:25 Base address:0x6000
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:16436 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1304 (1.2 KiB) TX bytes:1304 (1.2 KiB)
[root@server1 ~]#
br0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1196 (1.1 KiB) TX bytes:2794 (2.7 KiB)
eth0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4554 errors:0 dropped:0 overruns:0 frame:0
TX packets:3020 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6249612 (5.9 MiB) TX bytes:254928 (248.9 KiB)
Interrupt:25 Base address:0x6000
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:16436 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1304 (1.2 KiB) TX bytes:1304 (1.2 KiB)
[root@server1 ~]#
3 Installing Xen
First check if your CPU supports hardware virtualization - if this is the case, the commandegrep '(vmx|svm)' --color=always /proc/cpuinfo
should display something, e.g. like this:[root@server1 ~]# egrep '(vmx|svm)' --color=always /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
[root@server1 ~]#
If nothing is displayed, then your processor doesn't support hardware virtualization. This means you can use only paravirtualization with Xen, but not hardware virtualization.flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
[root@server1 ~]#
As CentOS 6 is based on RedHat 6, and RedHat has dropped support for Xen in version 6, we need to get Xen from a third-party repository. We can enable the repo as follows:
yum install wget
cd /etc/yum.repos.d/
wget http://www.crc.id.au/repo/kernel-xen.repo
To install Xen, we now simply runwget http://www.crc.id.au/repo/kernel-xen.repo
yum install kernel-xen xen
This installs Xen and a Xen kernel on our CentOS system. Before we can boot the system with the Xen kernel, please check your GRUB bootloader configuration. We open /boot/grub/menu.lst:
vi /boot/grub/menu.lst
The first listed kernel should be the Xen kernel that you've just installed:
[...] |
[...] |
[...] |
# grub.conf generated by anaconda |
yum install libvirt python-virtinst
Because the libvirt package from CentOS 6/RedHat 6 has no support for Xen, we must rebuild it with Xen support. To do this, we install a few prerequisites now:yum groupinstall 'Development Tools'
yum install python-devel xen-devel libxml2-devel xhtml1-dtds readline-devel ncurses-devel libtasn1-devel gnutls-devel augeas libudev-devel libpciaccess-devel yajl-devel sanlock-devel libpcap-devel libnl-devel avahi-devel libselinux-devel cyrus-sasl-devel parted-devel device-mapper-devel numactl-devel libcap-ng-devel netcf-devel libcurl-devel audit-libs-devel systemtap-sdt-devel
Let's find out our libvirt version:rpm -qa | grep libvirt
[root@server1 ~]# rpm -qa | grep libvirt
libvirt-client-0.9.4-23.el6_2.4.x86_64
libvirt-0.9.4-23.el6_2.4.x86_64
libvirt-python-0.9.4-23.el6_2.4.x86_64
[root@server1 ~]#
It's 0.9.4, so we download the appropriate src.rpm package into /root/src and install it:libvirt-client-0.9.4-23.el6_2.4.x86_64
libvirt-0.9.4-23.el6_2.4.x86_64
libvirt-python-0.9.4-23.el6_2.4.x86_64
[root@server1 ~]#
mkdir /root/src
cd /root/src
wget http://vault.centos.org/6.2/os/Source/SPackages/libvirt-0.9.4-23.el6.src.rpm
rpm -i libvirt-0.9.4-23.el6.src.rpm
The last command will show some warnings that you can ignore: cd /root/src
wget http://vault.centos.org/6.2/os/Source/SPackages/libvirt-0.9.4-23.el6.src.rpm
rpm -i libvirt-0.9.4-23.el6.src.rpm
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
Next we patch Xen support into the libvirt sources:warning: group mockbuild does not exist - using root
wget http://pasik.reaktio.net/xen/patches/libvirt-spec-rhel6-enable-xen.patch
cd /root/rpmbuild/SPECS
cp -a libvirt.spec libvirt.spec.orig
patch -p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch
Now we build a new libvirt package:cd /root/rpmbuild/SPECS
cp -a libvirt.spec libvirt.spec.orig
patch -p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch
rpmbuild -bb libvirt.spec
At the end of the build process you should see something like this:Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-client-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-devel-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-lock-sanlock-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-python-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-debuginfo-0.9.4-23.el6.x86_64.rpm
Go to the directory where the new packages have been created (/root/rpmbuild/RPMS/x86_64/ in this case)...Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-client-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-devel-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-lock-sanlock-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-python-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-debuginfo-0.9.4-23.el6.x86_64.rpm
cd /root/rpmbuild/RPMS/x86_64/
... and install the new libvirt packages (with Xen support) as follows:rpm -Uvh --force libvirt-0.9.4-23.el6.x86_64.rpm libvirt-client-0.9.4-23.el6.x86_64.rpm libvirt-python-0.9.4-23.el6.x86_64.rpm
Afterwards, we reboot the system:reboot
The system should now automatically boot the new Xen kernel. After the system has booted, we can check that by runninguname -r
[root@server1 ~]# uname -r
2.6.32.54-1.el6xen.x86_64
[root@server1 ~]#
So it's really using the new Xen kernel!2.6.32.54-1.el6xen.x86_64
[root@server1 ~]#
We can now run
xm list
to check if Xen has started. It should list Domain-0 (dom0):[root@server1 ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r----- 18.9
[root@server1 ~]#
Instead of using the xm command, I will from now on use the virsh command to manage Xen VMs. This is the preferred way as we are using libvirt. Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r----- 18.9
[root@server1 ~]#
virsh list
should show this: [root@server1 ~]# virsh list
Id Name State
----------------------------------
0 Domain-0 running
[root@server1 ~]#
Id Name State
----------------------------------
0 Domain-0 running
[root@server1 ~]#
4 Paravirtualization
4.1 Creating An Image-Based Virtual Machine
CentOS has a nice tool called virt-install with which we can create virtual machines for Xen. To start it, we simply run
virt-install --prompt --network bridge=br0 --virt-type=xen
(We must specify our network bridge with --network bridge=br0 so that the virtual machine uses our network bridge which we created in chapter2.)The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 1024MB RAM and a disk size of 10GB. I want to store it in the file /var/lib/libvirt/images/vm01.img:
Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems.
<-- no
What is the name of your virtual machine?
<-- vm01
How much RAM should be allocated (in megabytes)?
<-- 1024
What would you like to use as the disk (file path)?
<-- /var/lib/libvirt/images/vm01.img
How large would you like the disk (/vm/vm01.img) to be (in gigabytes)?
<-- 10
What is the install URL?
<-- http://ftp.tu-chemnitz.de/pub/linux/centos/6.2/os/x86_64
In this chapter I want to create a paravirtualized guest, not a fully (hardware) virtualized guest, that's why I answer the first question with no.
As install URL, you should specify a mirror close to you where the installer can download all files needed for the installation of CentOS 6.2 in our virtual machine. You can find a list of CentOS mirrors here: http://www.centos.org/modules/tinycontent/index.php?id=13
After we have answered all questions, virt-install starts the normal CentOS 6.2 installer (in text mode) in our vm01 virtual machine. After a few moments the installer gives you the choice to use VNC or to continue with the text mode installer. Using text mode is no problem if you are familiar with the CentOS installer, but if you like a little more comfort, select Start VNC here:
On the next screen you can provide a password for the VNC connection (recommended). IF you don't want to use a password, hit No password:
Afterwards, the installer tells you how you can connect to the installer via VNC (192.168.0.15:1 in this case):
Now open a VNC client (like TightVNC) and type in the connection details (192.168.0.15:1 in this case) and click on Connect:
If you have specified a password for the VNC connection, you must now provide it:
Afterwards you can use the CentOS installer in your VNC client:
After the installation, we stay at the vm01 console. To leave it, type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY. You will then be back at the dom0 console.
Run
virsh console vm01
to log in on that virtual machine again (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it. To get a list of running virtual machines, type
virsh list
The output should look like this:[root@server1 ~]# virsh list
Id Name State
----------------------------------
0 Domain-0 running
2 vm01 idle
[root@server1 ~]#
To shut down vm01, do this:Id Name State
----------------------------------
0 Domain-0 running
2 vm01 idle
[root@server1 ~]#
virsh shutdown vm01
To start vm01 again, runvirsh start vm01
Here are the most important Xen commands:virsh start
virsh shutdown
virsh destroy
virsh list - List all running systems.
virsh console
virsh help - List of all commands.
4.2 Creating An LVM-Based Virtual Machine (Paravirtualization)
This chapter explains how you can set up LVM-based virtual machines instead of virtual machines that use disk images. Virtual machines that use disk images are very slow and heavy on disk IO.In this example I'm using a CentOS 6.2 host with the LVM volume group /dev/VolGroup00 that has about 465GB of space. /dev/VolGroup00 contains two logical volumes, /dev/VolGroup00/LogVol00 and /dev/VolGroup00/LogVol01 that consume about 104GB of space - the rest is not allocated and can be used to create logical volumes for our virtual machines:
vgdisplay
[root@server1 ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 465.26 GiB
PE Size 4.00 MiB
Total PE 119106
Alloc PE / Size 26250 / 102.54 GiB
Free PE / Size 92856 / 362.72 GiB
VG UUID LCdZgy-jVrp-S92Q-RQeI-H87G-jiko-4fmaHF
[root@server1 ~]#
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 465.26 GiB
PE Size 4.00 MiB
Total PE 119106
Alloc PE / Size 26250 / 102.54 GiB
Free PE / Size 92856 / 362.72 GiB
VG UUID LCdZgy-jVrp-S92Q-RQeI-H87G-jiko-4fmaHF
[root@server1 ~]#
lvdisplay
[root@server1 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID n5remv-KYEE-O0Ry-g2r6-OrUe-rjyV-x65rHu
LV Write Access read/write
LV Status available
# open 1
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID CnvnGP-sDL8-OtBU-OzTT-VjZQ-ZIUo-yzISkX
LV Write Access read/write
LV Status available
# open 1
LV Size 97.66 GiB
Current LE 25000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
[root@server1 ~]#
I want to create the virtual machine vm02 now which uses the logical volume /dev/VolGroup00/vm02. I want the virtual machine to have a disk space of 10GB, so I create the logical volume /dev/VolGroup00/vm02 as follows:--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID n5remv-KYEE-O0Ry-g2r6-OrUe-rjyV-x65rHu
LV Write Access read/write
LV Status available
# open 1
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID CnvnGP-sDL8-OtBU-OzTT-VjZQ-ZIUo-yzISkX
LV Write Access read/write
LV Status available
# open 1
LV Size 97.66 GiB
Current LE 25000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
[root@server1 ~]#
lvcreate -L10G -n vm02 VolGroup00
Afterwards we can runvirt-install --prompt --network bridge=br0 --virt-type=xen
again:Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems.
<-- no
What is the name of your virtual machine?
<-- vm02
How much RAM should be allocated (in megabytes)?
<-- 1024
What would you like to use as the disk (file path)?
<-- /dev/VolGroup00/vm02
What is the install URL?
<-- http://ftp.tu-chemnitz.de/pub/linux/centos/6.2/os/x86_64
As the disk file path, we specify our new volume group /dev/VolGroup00/vm02. Please note that virt-install doesn't ask for the disk space anymore because the disk space is determined by the size of the logical volume (10GB).
4.3 Using virt-manager To Create & Manage Virtual Machines
Initialize a new VM on the CentOS 6.2 host (in this example, it's vm06):
virt-install --prompt --network bridge=br0 --virt-type=xen --vnc --noautoconsole
The --vnc --noautoconsole parameters are important - they allow us to connect to the installer with virt-manager.[root@server1 ~]# virt-install --prompt --network bridge=br0 --virt-type=xen --vnc --noautoconsole
Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems.
<-- no
What is the name of your virtual machine?
<-- vm06
How much RAM should be allocated (in megabytes)?
<-- 1024
What would you like to use as the disk (file path)?
<-- /var/lib/libvirt/images/vm06.img
How large would you like the disk (/var/lib/libvirt/images/vm06.img) to be (in gigabytes)?
<-- 10
What is the install URL?
<-- http://ftp.tu-chemnitz.de/pub/linux/centos/6.2/os/x86_64
Starting install...
Retrieving file .treeinfo... | 798 B 00:00 ...
Retrieving file vmlinuz... | 7.5 MB 00:01 ...
Retrieving file initrd.img... | 59 MB 00:10 ...
Allocating 'vm06.img' | 10 GB 00:00
Creating domain... | 0 B 00:01
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@server1 ~]#
As you see the command returns to the prompt, so we must use virt-manager now to complete the VM installation. Retrieving file .treeinfo... | 798 B 00:00 ...
Retrieving file vmlinuz... | 7.5 MB 00:01 ...
Retrieving file initrd.img... | 59 MB 00:10 ...
Allocating 'vm06.img' | 10 GB 00:00
Creating domain... | 0 B 00:01
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@server1 ~]#
You can install virt-manager as follows on a Fedora 16 desktop - open a terminal and become root:
su
Then install virt-manager:yum install virt-manager openssh-askpass
Go to Applications > System Tools > Virtual Machine Manager to start virt-manager:When you start virt-manager for the first time, you will most likely see the following message (Packages required for KVM usage). You can ignore this because we don't want to connect to the local libvirt daemon, but to the one on our CentOS 6.2 Xen host. Click on No...
... and go to File > Add Connection... to connect to our CentOS 6.2 Xen host:
Select Xen as Hypervisor, then check Connect to remote host, select SSH in the Method drop-down menu, type in root as the Username and the hostname (server1.example.com) or IP address (192.168.0.100) of the CentOS 6.2 Xen host in the Hostname field. Then click on Connect:
If this is the first connection to the remote Xen server, you must type in yes and click on OK:
Afterwards type in the root password of the CentOS 6.2 Xen host:
You should see vm06 as running. Mark that guest and click on the Open button to open the graphical console of the guest:
Type in the root password of the Xen host again:
You should now be connected to the graphical console of the guest and see the CentOS installer:
Now install CentOS as you would normally do on a physical system. Please note that at the end of the installation, the CentOS guest needs a reboot. The guest will then stop, so you need to start it again, either with virt-manager or like this on our CentOS 6.2 Xen host command line:
CentOS 6.2 Xen Host:
virsh start vm06
Afterwards, you can connect to the guest again with virt-manager and configure the guest. If you install OpenSSH in the guest, you can connect to it with an SSH client (such as PuTTY).5 Full Virtualization (Hardware Virtualization)
5.1 Creating A Fully Virtualized Guest On The Command Line
Because we need installation media, you can now either put your CentOS 6.2 DVD (the first one) into your DVD drive, or you download the CentOS 6.2 iso file and put it in the /var/lib/libvirt/images/ directory (it must be in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual machines through virt-manager from your Fedora desktop, and virt-manager will look for ISO images in the /var/lib/libvirt/images/ directory). IT is also possible to create an iso file from the DVD as follows:dd if=/dev/cdrom of=/var/lib/libvirt/images/CentOS-6.2-x86_64-bin-DVD1.iso
The guest installation can be started as follows: virt-install --prompt --network bridge=br0 --virt-type=xen --vnc --noautoconsole
[root@server1 ~]# virt-install --prompt --network bridge=br0 --virt-type=xen --vnc --noautoconsoleWould you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems.
<-- yes
What is the name of your virtual machine?
<-- vm03
How much RAM should be allocated (in megabytes)?
<-- 1024
What would you like to use as the disk (file path)?
<-- /var/lib/libvirt/images/vm03.img (you can as well specify a logical volume here, see chapter 4.2)
How large would you like the disk (/var/lib/libvirt/images/vm03.img) to be (in gigabytes)?
<-- 10
What is the install CD-ROM/ISO or URL?
<-- /dev/cdrom (you can also specify an iso file here, e.g. /var/lib/libvirt/images/CentOS-6.2-x86_64-bin-DVD1.iso)
Starting install...
Creating domain... | 0 B 00:01
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@server1 ~]#
That's it! Now you must open virt-manager and complete the guest installation, as shown in chapter 4.3. Creating domain... | 0 B 00:01
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@server1 ~]#
5.2 Creating A CentOS 6.2 Guest (Image-Based) From The Desktop With virt-manager
Instead of creating a virtual machine from the command line, you can as well create it from the Fedora desktop using virt-manager (of course, the virtual machine will be created on the CentOS 6.2 Xen host - in case you ask yourself if virt-manager is able to create virtual machines on remote systems).(I have tried this for a paravirtualized guest as well, but got an error after initrd.img got loaded - therefore this chapter is only for fully-virtualized guests.)
To do this, click on the following button:
The New VM dialogue comes up. Fill in a name for the VM (e.g. vm07), select Local install media (ISO image or CDROM), and click on Forward:
Next check Use ISO image and click on the Browse... button:
Select the CentOS-6.2-x86_64-bin-DVD1.iso image and click on Choose Volume:
Now select Linux in the OS type drop-down menu and RedHat Enterprise Linux 6 in the Version drop-down menu, then click on Forward:
Assign memory and the number of CPUs to the virtual machine and click on Forward:
Now we come to the storage. Check Enable storage for this virtual machine, select Create a disk image on the computer's hard drive, specify the size of the hard drive (e.g. 10GB), and check Allocate entire disk now. Then click on Forward:
Now we come to the last step of the New VM dialogue. Go to the Advanced options section. Select Specify shared device name and then specify br0 in the Bridge name field; that is the name of the bridge which we created in chapter 2. Click on Finish afterwards:
The disk image for the VM is now being created:
Afterwards, the VM will start. Type in the root password of the CentOS 6.2 Xen host:
You should now be connected to the graphical console of the guest and see the CentOS installer:
Now install CentOS as you would normally do on a physical system.
6 Managing A Xen Guest From The Command Line
virsh
This is how the virtual shell looks:[root@server1 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #
You can now type in commands on the virtual shell to manage your guests. RunWelcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #
help
to get a list of available commands:virsh # help
Grouped commands:
Domain Management (help keyword 'domain'):
attach-device attach device from an XML file
attach-disk attach disk device
attach-interface attach network interface
autostart autostart a domain
blkiotune Get or set blkio parameters
blockpull Populate a disk from its backing image.
blockjob Manage active block operations.
console connect to the guest console
cpu-baseline compute baseline CPU
cpu-compare compare host CPU with a CPU described by an XML file
create create a domain from an XML file
define define (but don't start) a domain from an XML file
destroy destroy (stop) a domain
detach-device detach device from an XML file
detach-disk detach disk device
detach-interface detach network interface
domid convert a domain name or UUID to domain id
domjobabort abort active domain job
domjobinfo domain job information
domname convert a domain id or UUID to domain name
domuuid convert a domain name or id to domain UUID
domxml-from-native Convert native config to domain XML
domxml-to-native Convert domain XML to native config
dump dump the core of a domain to a file for analysis
dumpxml domain information in XML
edit edit XML configuration for a domain
inject-nmi Inject NMI to the guest
send-key Send keycodes to the guest
managedsave managed save of a domain state
managedsave-remove Remove managed save of a domain
maxvcpus connection vcpu maximum
memtune Get or set memory parameters
migrate migrate domain to another host
migrate-setmaxdowntime set maximum tolerable downtime
migrate-setspeed Set the maximum migration bandwidth
reboot reboot a domain
restore restore a domain from a saved state in a file
resume resume a domain
save save a domain state to a file
save-image-define redefine the XML for a domain's saved state file
save-image-dumpxml saved state domain information in XML
save-image-edit edit XML for a domain's saved state file
schedinfo show/set scheduler parameters
screenshot take a screenshot of a current domain console and store it into a file
setmaxmem change maximum memory limit
setmem change memory allocation
setvcpus change number of virtual CPUs
shutdown gracefully shutdown a domain
start start a (previously defined) inactive domain
suspend suspend a domain
ttyconsole tty console
undefine undefine an inactive domain
update-device update device from an XML file
vcpucount domain vcpu counts
vcpuinfo detailed domain vcpu information
vcpupin control or query domain vcpu affinity
version show version
vncdisplay vnc display
Domain Monitoring (help keyword 'monitor'):
domblkinfo domain block device size information
domblklist list all domain blocks
domblkstat get device block stats for a domain
domcontrol domain control interface state
domifstat get network interface stats for a domain
dominfo domain information
dommemstat get memory statistics for a domain
domstate domain state
list list domains
Host and Hypervisor (help keyword 'host'):
capabilities capabilities
connect (re)connect to hypervisor
freecell NUMA free memory
hostname print the hypervisor hostname
nodecpustats Prints cpu stats of the node.
nodeinfo node information
nodememstats Prints memory stats of the node.
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
sysinfo print the hypervisor sysinfo
uri print the hypervisor canonical URI
Interface (help keyword 'interface'):
iface-begin create a snapshot of current interfaces settings, which can be later commited (iface-commit) or restored (iface-rollback)
iface-commit commit changes made since iface-begin and free restore point
iface-define define (but don't start) a physical host interface from an XML file
iface-destroy destroy a physical host interface (disable it / "if-down")
iface-dumpxml interface information in XML
iface-edit edit XML configuration for a physical host interface
iface-list list physical host interfaces
iface-mac convert an interface name to interface MAC address
iface-name convert an interface MAC address to interface name
iface-rollback rollback to previous saved configuration created via iface-begin
iface-start start a physical host interface (enable it / "if-up")
iface-undefine undefine a physical host interface (remove it from configuration)
Network Filter (help keyword 'filter'):
nwfilter-define define or update a network filter from an XML file
nwfilter-dumpxml network filter information in XML
nwfilter-edit edit XML configuration for a network filter
nwfilter-list list network filters
nwfilter-undefine undefine a network filter
Networking (help keyword 'network'):
net-autostart autostart a network
net-create create a network from an XML file
net-define define (but don't start) a network from an XML file
net-destroy destroy (stop) a network
net-dumpxml network information in XML
net-edit edit XML configuration for a network
net-info network information
net-list list networks
net-name convert a network UUID to network name
net-start start a (previously defined) inactive network
net-undefine undefine an inactive network
net-uuid convert a network name to network UUID
Node Device (help keyword 'nodedev'):
nodedev-create create a device defined by an XML file on the node
nodedev-destroy destroy (stop) a device on the node
nodedev-dettach dettach node device from its device driver
nodedev-dumpxml node device details in XML
nodedev-list enumerate devices on this host
nodedev-reattach reattach node device to its device driver
nodedev-reset reset node device
Secret (help keyword 'secret'):
secret-define define or modify a secret from an XML file
secret-dumpxml secret attributes in XML
secret-get-value Output a secret value
secret-list list secrets
secret-set-value set a secret value
secret-undefine undefine a secret
Snapshot (help keyword 'snapshot'):
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
Storage Pool (help keyword 'pool'):
find-storage-pool-sources-as find potential storage pool sources
find-storage-pool-sources discover potential storage pool sources
pool-autostart autostart a pool
pool-build build a pool
pool-create-as create a pool from a set of args
pool-create create a pool from an XML file
pool-define-as define a pool from a set of args
pool-define define (but don't start) a pool from an XML file
pool-delete delete a pool
pool-destroy destroy (stop) a pool
pool-dumpxml pool information in XML
pool-edit edit XML configuration for a storage pool
pool-info storage pool information
pool-list list pools
pool-name convert a pool UUID to pool name
pool-refresh refresh a pool
pool-start start a (previously defined) inactive pool
pool-undefine undefine an inactive pool
pool-uuid convert a pool name to pool UUID
Storage Volume (help keyword 'volume'):
vol-clone clone a volume.
vol-create-as create a volume from a set of args
vol-create create a vol from an XML file
vol-create-from create a vol, using another volume as input
vol-delete delete a vol
vol-download Download a volume to a file
vol-dumpxml vol information in XML
vol-info storage vol information
vol-key returns the volume key for a given volume name or path
vol-list list vols
vol-name returns the volume name for a given volume key or path
vol-path returns the volume path for a given volume name or key
vol-pool returns the storage pool for a given volume key or path
vol-upload upload a file into a volume
vol-wipe wipe a vol
Virsh itself (help keyword 'virsh'):
cd change the current directory
echo echo arguments
exit quit this interactive terminal
help print help
pwd print the current directory
quit quit this interactive terminal
virsh #
Grouped commands:
Domain Management (help keyword 'domain'):
attach-device attach device from an XML file
attach-disk attach disk device
attach-interface attach network interface
autostart autostart a domain
blkiotune Get or set blkio parameters
blockpull Populate a disk from its backing image.
blockjob Manage active block operations.
console connect to the guest console
cpu-baseline compute baseline CPU
cpu-compare compare host CPU with a CPU described by an XML file
create create a domain from an XML file
define define (but don't start) a domain from an XML file
destroy destroy (stop) a domain
detach-device detach device from an XML file
detach-disk detach disk device
detach-interface detach network interface
domid convert a domain name or UUID to domain id
domjobabort abort active domain job
domjobinfo domain job information
domname convert a domain id or UUID to domain name
domuuid convert a domain name or id to domain UUID
domxml-from-native Convert native config to domain XML
domxml-to-native Convert domain XML to native config
dump dump the core of a domain to a file for analysis
dumpxml domain information in XML
edit edit XML configuration for a domain
inject-nmi Inject NMI to the guest
send-key Send keycodes to the guest
managedsave managed save of a domain state
managedsave-remove Remove managed save of a domain
maxvcpus connection vcpu maximum
memtune Get or set memory parameters
migrate migrate domain to another host
migrate-setmaxdowntime set maximum tolerable downtime
migrate-setspeed Set the maximum migration bandwidth
reboot reboot a domain
restore restore a domain from a saved state in a file
resume resume a domain
save save a domain state to a file
save-image-define redefine the XML for a domain's saved state file
save-image-dumpxml saved state domain information in XML
save-image-edit edit XML for a domain's saved state file
schedinfo show/set scheduler parameters
screenshot take a screenshot of a current domain console and store it into a file
setmaxmem change maximum memory limit
setmem change memory allocation
setvcpus change number of virtual CPUs
shutdown gracefully shutdown a domain
start start a (previously defined) inactive domain
suspend suspend a domain
ttyconsole tty console
undefine undefine an inactive domain
update-device update device from an XML file
vcpucount domain vcpu counts
vcpuinfo detailed domain vcpu information
vcpupin control or query domain vcpu affinity
version show version
vncdisplay vnc display
Domain Monitoring (help keyword 'monitor'):
domblkinfo domain block device size information
domblklist list all domain blocks
domblkstat get device block stats for a domain
domcontrol domain control interface state
domifstat get network interface stats for a domain
dominfo domain information
dommemstat get memory statistics for a domain
domstate domain state
list list domains
Host and Hypervisor (help keyword 'host'):
capabilities capabilities
connect (re)connect to hypervisor
freecell NUMA free memory
hostname print the hypervisor hostname
nodecpustats Prints cpu stats of the node.
nodeinfo node information
nodememstats Prints memory stats of the node.
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
sysinfo print the hypervisor sysinfo
uri print the hypervisor canonical URI
Interface (help keyword 'interface'):
iface-begin create a snapshot of current interfaces settings, which can be later commited (iface-commit) or restored (iface-rollback)
iface-commit commit changes made since iface-begin and free restore point
iface-define define (but don't start) a physical host interface from an XML file
iface-destroy destroy a physical host interface (disable it / "if-down")
iface-dumpxml interface information in XML
iface-edit edit XML configuration for a physical host interface
iface-list list physical host interfaces
iface-mac convert an interface name to interface MAC address
iface-name convert an interface MAC address to interface name
iface-rollback rollback to previous saved configuration created via iface-begin
iface-start start a physical host interface (enable it / "if-up")
iface-undefine undefine a physical host interface (remove it from configuration)
Network Filter (help keyword 'filter'):
nwfilter-define define or update a network filter from an XML file
nwfilter-dumpxml network filter information in XML
nwfilter-edit edit XML configuration for a network filter
nwfilter-list list network filters
nwfilter-undefine undefine a network filter
Networking (help keyword 'network'):
net-autostart autostart a network
net-create create a network from an XML file
net-define define (but don't start) a network from an XML file
net-destroy destroy (stop) a network
net-dumpxml network information in XML
net-edit edit XML configuration for a network
net-info network information
net-list list networks
net-name convert a network UUID to network name
net-start start a (previously defined) inactive network
net-undefine undefine an inactive network
net-uuid convert a network name to network UUID
Node Device (help keyword 'nodedev'):
nodedev-create create a device defined by an XML file on the node
nodedev-destroy destroy (stop) a device on the node
nodedev-dettach dettach node device from its device driver
nodedev-dumpxml node device details in XML
nodedev-list enumerate devices on this host
nodedev-reattach reattach node device to its device driver
nodedev-reset reset node device
Secret (help keyword 'secret'):
secret-define define or modify a secret from an XML file
secret-dumpxml secret attributes in XML
secret-get-value Output a secret value
secret-list list secrets
secret-set-value set a secret value
secret-undefine undefine a secret
Snapshot (help keyword 'snapshot'):
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
Storage Pool (help keyword 'pool'):
find-storage-pool-sources-as find potential storage pool sources
find-storage-pool-sources discover potential storage pool sources
pool-autostart autostart a pool
pool-build build a pool
pool-create-as create a pool from a set of args
pool-create create a pool from an XML file
pool-define-as define a pool from a set of args
pool-define define (but don't start) a pool from an XML file
pool-delete delete a pool
pool-destroy destroy (stop) a pool
pool-dumpxml pool information in XML
pool-edit edit XML configuration for a storage pool
pool-info storage pool information
pool-list list pools
pool-name convert a pool UUID to pool name
pool-refresh refresh a pool
pool-start start a (previously defined) inactive pool
pool-undefine undefine an inactive pool
pool-uuid convert a pool name to pool UUID
Storage Volume (help keyword 'volume'):
vol-clone clone a volume.
vol-create-as create a volume from a set of args
vol-create create a vol from an XML file
vol-create-from create a vol, using another volume as input
vol-delete delete a vol
vol-download Download a volume to a file
vol-dumpxml vol information in XML
vol-info storage vol information
vol-key returns the volume key for a given volume name or path
vol-list list vols
vol-name returns the volume name for a given volume key or path
vol-path returns the volume path for a given volume name or key
vol-pool returns the storage pool for a given volume key or path
vol-upload upload a file into a volume
vol-wipe wipe a vol
Virsh itself (help keyword 'virsh'):
cd change the current directory
echo echo arguments
exit quit this interactive terminal
help print help
pwd print the current directory
quit quit this interactive terminal
virsh #
list
shows all running guests;list --all
shows all guests, running and inactive:virsh # list --all
Id Name State
----------------------------------
0 Domain-0 running
- vm01 shut off
virsh #
To start a stopped guest, run:Id Name State
----------------------------------
0 Domain-0 running
- vm01 shut off
virsh #
start vm10
To stop a guest, runshutdown vm10
To immediately stop it (i.e., pull the power plug), rundestroy vm10
Suspend a guest:suspend vm10
Resume a guest:resume vm10
These are the most important commands.Type
quit
to leave the virtual shell.7 Links
- Xen: http://www.xen.org/
- CentOS: http://www.centos.org/
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Virtualization With Xen On CentOS 6.2 (x86_64) (Paravirtualization & Hardware Virtualization)
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidblackberries.blogspot.com/2012/02/virtualization-with-xen-on-centos-62.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar