Derwynd's Weblog

Derwynd's Weblog

Installation and management of XEN on Redhat-linux

$ yum install xen kernel-xen*

Reboot with xen kernel after changes in grub

$ ps aux | grep xend

If you do not see xend in the resulting listing, you need to start it yourself by switching to root with su – and then running

$ /etc/init.d/xend start
$ free -m
             total       used       free     shared    buffers     cached
Mem:           942        332        609          0         26        239
-/+ buffers/cache:         66        875
Swap:         1996          0       1996
$ xm list

which prints out a list of all the virtual machines that are running and how much RAM they have allocated — you should see Domain-0, which is your current system, in the list.

$ xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      942     1 r-----     55.4

The output from xm list probably shows that domain 0 is taking up all the RAM on your system, which means there is no room to create a new guest OS.

$ xm mem-set Domain-0 256
$ xm mem-max Domain-0 256

Run the command xm mem-set Domain-0 256 to have domain 0 use 256MB RAM

$ xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      256     1 r-----     58.2
****Note that for the default setup, networking for guest OS's is bridged. This means that they will get an IP address on the same network as your host, thus, if you have a DHCP server providing addresses, you will need to ensure that it is configured to give addresses to your guests. You can change to another networking type by editing /etc/xen/xend-config.sxp
$ virt-install

What is the name of your virtual machine? test
 How much RAM should be allocated (in megabytes)? 256
 What would you like to use as the disk (file path)? /opt/test1
 How large would you like the disk (/opt/test1) to be (in gigabytes)? 4
 Would you like to enable graphics support? (yes or no) no
 What is the install location? /opt/testinst
 ERROR:  Install media location must be an NFS, HTTP or FTP network install source, or an existing local file/device
 What is the install location? http://192.168.50.50/centos52

This information can also be passed as command line options; run with an argument of –help for more details. In particular, kickstart options can be passed with

 virt-install -x ks=options
eg
 virt-install -x ks=http://192.168.50.8/rhelas.cfg
$ /usr/sbin/virt-install

The following questions about the new guest OS will be presented. This information can also be passed as command line options; run with an argument of --help for more details. In particular, kickstart options can be passed with -x ks=options.

   1. What is the name of your virtual machine? This is the label that will identify the guest OS. This label will be used for various xm commands and also appear in virt-manager the Gnome-panel Xen applet. In addition, it will be the name of the /etc/xen/<name> file that stores the guest's configuration information.
   2. How much RAM should be allocated (in megabytes)? This is the amount of RAM to be allocated for the guest instance in megabytes (eg, 256). Note that installation with less than 256 megabytes is not recommended.
   3. What would you like to use as the disk (path)? The local path and file name of the file to serve as the disk image for the guest (eg, /home/joe/xenbox1). This will be exported as a full disk to your guest.
   4. How large would you like the disk to be (in gigabytes)? The size of the virtual disk for the guest (only appears if the file specified above does not already exist). 4.0 gigabytes is a reasonable size for a "default" install
   5. Would you like to enable graphics support (yes or no): Should the graphical installer be used?
   6.  What is the install location? This is the path to a Fedora Core 6 installation tree in the format used by anaconda. NFS, FTP, and HTTP locations are all supported. Examples include:
          * nfs:my.nfs.server.com:/path/to/test2/tree/
          * http://my.http.server.com/path/to/tree/
          * ftp://my.ftp.server.com/path/to/tree

      {i} Installation must be a network type. It is not possible to install from a local disk or CDROM. It is possible, however, to set up an installation tree on the host OS and then export it as an NFS share.

The xen config files are usually found under /etc/xen

to restart a console with a mc

$ xm create -c <configfile>

You can connect to the console of any virtual machine by running

$ xm list
$ xm console <yourvmname>

Xen request the VM to shutdown

$ xm shutdown <yourvmname>

On Linux, this goes through the whole shutdown sequence properly, ensuring that the machine is cleanly terminated. If you want an immediate shutdown, use

$ xm destroy yourvm

but make sure the virtual machine is in a safe state first — if you have a text file open and unsaved, for example, it will be lost.

The xm command can also be used to save snapshots of a virtual machine, rather than just switching them off. To do this, use

$ xm save yourvm yourvm.state

That command essentially saves the RAM of the yourvm VM (change yourvm to whatever you called your virtual machine) to a file and then turns off the VM. To restore a saved state, just use

$ xm restore yourvm.state

To display top-like statistics for all running machines:

$ /usr/sbin/xm top

On the virtualization host server, open a terminal and enter

xm delete vm_name

to delete the virtual machine’s reference in xenstore so it is no longer managed.

Hacks

For CDROM

open the xen config under /ect/xen/mc-name and add

eg if the xm machine is called relay1 under /ect/xen/relay1
add 

disk = [ "tap:aio:/opt/relay1,xvda,w",
'phy:/dev/cdrom,hdc:cdrom,r']

After starting the mc try

mount /dev/hdc /media/

To mount a iso in place of cdrom

disk = [ "tap:aio:/com_xen/atoq,xvda,w",'file:/tmp/fedorax.iso,hdc:cdrom,r' ]

After starting the mc try 

mount /dev/hdc /media/

Or in rc.local add 

ln -s /dev/hdc /dev/cdrom to be able to mount /dev/cdrom

To automatically run the guest after a system (Dom0) reboot, we have to create the following link:

$ ln -s /etc/xen/[guest_name] /etc/xen/auto/

For 2 network-interfaces

Shut down the xen m/c first

in /etc/xen/xend-config.sxp
find (network-script network-bridge) line
replace with
(network-script network-multi-bridge)
$ cd /etc/xen/scripts
$ vi network-multi-bridge
#!/bin/sh
dir=$(dirname "$0")
"$dir/network-bridge" "$@" vifnum=0 bridge=xenbr0 netdev=eth0
"$dir/network-bridge" "$@" vifnum=1 bridge=xenbr1 netdev=eth0 (or eth1)

Be sure to make the script executable

$ chmod +x network-multi-bridge

In my /etc/xen/test config I’v added a second interface

name = "test"
uuid = "44147e5d-a9a1-dfa5-24a5-646b9543ccbb"
maxmem = 256
memory = 256
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [  ]
disk = [ "tap:aio:/opt/test1,xvda,w" ]
vif = [ "mac=00:16:3e:1e:83:6e,bridge=xenbr0",
        "mac=00:16:3e:1e:83:7e,bridge=xenbr1" ]

Please restart

xend

service
To generate a unique mac address for use

echo "#! /usr/bin/python
# macgen.py script generates a MAC address for Xen guests
#
import random
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
print ':'.join(map(lambda x: '%02x' % x, mac))" > /tmp/macgen

$ python /tmp/macgen

The configuration files in /etc/xen are in text format and so are easily edited.
For example, if you want to change the number of CPUs a VM sees, look for the vcpus setting.
Note that these are virtual CPUs rather than real ones —
you can set this to 8 and have your guest see eight CPUs, even if your actual machine has just one

Advertisements

November 10, 2008 - Posted by | Uncategorized

Sorry, the comment form is closed at this time.

%d bloggers like this: