Installing and Using XEN Virtual Machine on Linux

1. Install Xen

The command is as follows:

yum install xen* kernel-xen* virt-manager vnc* xen-lib python-virtinst

kernel-xen: Linux kernel that can run Xen

xen: Main Xen package, including configuration files, startup scripts, and some libraries

xen-libs: Libraries required by Xen

python-virtinst: Provides terminal installation software

virt-manager: Used for graphical interface management of Xen

2. Modify grub to boot the system from the Xen kernel

The command is as follows:

[root@center ~]# more /etc/grub.conf

< p># grub.conf generated by anaconda

< p>#

< p># Note that you do not have to rerun grub after making changes to this file

< p># NOTICE: You have a /boot partition. This means that

< p># all kernel and initrd paths are relative to /boot/, eg.

< p># root (hd0,1)

< p># kernel /vmlinuz-version ro root=/dev/sda1

< p># initrd /initrd-version.img

< p>#boot=/dev/sda

< p>default=0

< p>timeout=5

< p>splashimage=(hd0,1)/grub/splash.xpm.gz

< p>hiddenmenu

< p>title CentOS (2.6.18-194.32.1.el5xen)

< p>root (hd0,1)

< p>kernel /xen.gz-2.6.18-194.32.1.el5

< p>module /vmlinuz-2.6.18-194.32.1.el5xen ro root=LABEL=/ rhgb quiet

< p>module /initrd-2.6.18-194.32.1.el5xen.img

< p>title CentOS (2.6.18-194.el5)

< p>root (hd0,1)

< p>kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet

< p>initrd /initrd-2.6.18-194.el5.img

3. Restart the system and confirm whether it has booted using the Xen kernel

The command is as follows:

[root@center ~]# uname -ar

< p>Linux test1.aa.com 2.6.18-274.17.1.el5xen #1 SMP Tue Jan 10 18:06:37 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

4. Adjust the memory used by the Xen server (dom0)

The command is as follows:

default=0

< p>timeout=5

< p>splashimage=(hd0,0)/grub/splash.xpm.gz

< p>hiddenmenu

< p>title CentOS (2.6.18-238.9.1.el5xen)

< p>root (hd0,0)

< p>kernel /xen.gz-2.6.18-238.9.1.el5 dom0_mem=2097152 (in kb, 2G)

< p>module /vmlinuz-2.6.18-238.9.1.el5xen ro root=LABEL=/

< p>module /initrd-2.6.18-238.9.1.el5xen.img

< p>title CentOS (2.6.18-194.el5)

< p>root (hd0,0)

< p>kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/

< p>initrd /initrd-2.6.18-194.el5.img

After adjustment, the server needs to be restarted.

5. Create a local YUM source for system installation

Modify http.conf:

Add listening ports:

The command is as follows:

Listen 8000

< p>Listen 8001

Add virtual host:

The command is as follows:

DocumentRoot /data/os

< p>Options Indexes MultiViews

< p>AllowOverride None

< p>Order allow,deny

< p>Allow from all

Restart httpd:

/etc/init.d/httpd reload

6. Create a virtual machine

The command is as follows:

virt-install -n xen1 -r 256 -f /home/xen1.img -lhttp://192.168.0.110:8001 ?network=network:default -s 20 ?nographics ?vnc ?vcpus=8

-n: followed by the virtual machine name, configured under /etc/xen

-r: followed by the allocated memory size

-vcpus: number of CPUs allocated

-f: followed by the new disk file

-nographics: do not use graphical installation

-p: paravirtualization

-s: hard disk space of the virtual machine

7. Clone the virtual machine

The command is as follows:

virt-clone -o xen1 -n xen2 -f /home/xen2.img

8. Common commands

xm info

to view host machine information

xm top

to monitor host and Domain machine information

xm create /etc/xen/xen1

to start

xm shutdown xen1

to shut down

xm reboot xen1

to reboot

xm pause xen1

to pause

xm resume xen1

to resume

xm list

xm console xen1

to enter console

Ctrl + ]

to exit console

9. Optimization

The command is as follows:

[root@test1 ~]# xm list

Name ID Mem(MiB) VCPUs State Time(s)

Domain-0 0 474 1 r—? 1222.9

xen1 10 255 1 -b—- 81.9

Optimization method:

xm vcpu-pin 3 0 1

(directly handle the VCPU used by the virtual machine with physical CPU 1)

Confirm whether a separate physical CPU has been allocated:

The command is as follows:

xm vcpu-list 3

Leave a Comment