Saturday, September 4, 2010

XEN operations

XEN List command
----------

xm list


to check if Xen has started. It should list Domain-0 (dom0):

[root@server1 ~]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 350 1 r----- 94.4
[root@server1 ~]#
---------

Creating A Virtual Machine
--------------

CentOS comes with a nice tool called virt-install with which we can create virtual machines for Xen. To start it, we simply run

virt-install


The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 256MB RAM and a disk size of 4GB. I want to store it in the file /vm/vm01.img:

What is the name of your virtual machine? <-- vm01
How much RAM should be allocated (in megabytes)? <-- 256
What would you like to use as the disk (path)? <-- /vm/vm01.img
How large would you like the disk (/vm/vm01.img) to be (in gigabytes)? <-- 4
Would you like to enable graphics support? (yes or no) <-- no
What is the install location? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.0/os/i386

The question about the graphics support refers to the installer, not the virtual machine itself! It is possible to start a graphical installer, but you'd have to connect to it via VNC. It's easier to use the text installer - it offers the same options, so I choose the text installer.

As install location, you should specify a mirror close to you where the installer can download all files needed for the installation of CentOS 5.0 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 5.0 installer (in text mode) in our vm01 virtual machine. You already know the CentOS installer, so it should be no problem for you to finish the CentOS installation in vm01.

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.

virt-install has created the vm01 configuration file /etc/xen/vm01 for us (in dom0). It should look like this:

====================================================
cat /etc/xen/vm01

# Automatically generated xen config file
name = "vm01"
memory = "256"
disk = [ 'tap:aio:/vm/vm01.img,xvda,w', ]
vif = [ 'mac=00:16:3e:13:e4:81, bridge=xenbr0', ]

uuid = "5aafecf1-dd66-401d-69cc-151c1cb8ac9e"
bootloader="/usr/bin/pygrub"
vcpus=1
on_reboot = 'restart'
on_crash = 'restart'
====================================================

Run
-----------

xm 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
---------------

xm list

The output should look like this:

[root@server1 xen]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 259 1 r----- 1906.6
vm01 3 255 1 ------ 137.9
[root@server1 xen]#

To shut down vm01, do this:
--------------

xm shutdown vm01

To start vm01 again, run
---------------

xm create /etc/xen/vm01

If you want vm01 to start automatically at the next boot of the system, then do this:
------------------

ln -s /etc/xen/vm01 /etc/xen/auto

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown - Stop a virtual machine.
xm destroy - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console - Log in on a virtual machine.
xm help - List of all commands.

No comments:

Post a Comment