Paravirtualization With Xen On CentOS 5.6 (x86_64) - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2011-05-22 18:22. ::

3 Creating An Image-Based Virtual Machine

I want to store the disk images of my image-based virtual machines in the directory /vm. Of course, you can use any other directory that has enough space left. If you use another directory, replace /vm with your own directory in this tutorial.

If you want to save your virtual machines in /vm, too, but haven't created a partition for it or if the directory /vm doesn't exist on your system, you can create it like this:

mkdir /vm

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

The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 512MB RAM and a disk size of 4GB. I want to store it in the file /vm/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)? <-- 512
 What would you like to use as the disk (file path)? <-- /vm/vm01.img
 How large would you like the disk (/vm/vm01.img) to be (in gigabytes)? <-- 4
 What is the install URL? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.6/os/x86_64

You should answer the first question about the fully virtualized guest with no because otherwise you will not see the CentOS installer - the installation of the guest system will seem to hang.

As install URL, you should specify a mirror close to you where the installer can download all files needed for the installation of CentOS 5.6 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.6 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

name = "vm01"
uuid = "809dd76e-f48e-8a3d-343b-1dd8b1d585ea"
maxmem = 512
memory = 512
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/vm/vm01.img,xvda,w" ]
vif = [ "mac=00:16:36:33:80:b7,bridge=xenbr0,script=vif-bridge" ]

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 ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     2702     2 r-----     83.4
vm01                                       3      512     1 -b----     18.2
[root@server1 ~]#

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 <name> - Stop a virtual machine.
xm destroy <name> - 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 <name> - Log in on a virtual machine.
xm help - List of all commands.

 

4 Creating An LVM-Based Virtual Machine

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 5.6 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
  /dev/hda: open failed: No medium found
  --- 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.66 GB
  PE Size               32.00 MB
  Total PE              14901
  Alloc PE / Size       3303 / 103.22 GB
  Free  PE / Size       11598 / 362.44 GB
  VG UUID               veUbuN-BNGq-BP3S-H3mP-bWOF-tbAX-GeIhy6

[root@server1 ~]#

lvdisplay

[root@server1 ~]# lvdisplay
  /dev/hda: open failed: No medium found
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                5tEz3i-YlR7-rdQB-VCPK-xHlB-GsWU-4Rijqk
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                97.66 GB
  Current LE             3125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                3qp5ia-uBJl-eeNZ-JOkH-4E6o-ZAbf-HvdNms
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.56 GB
  Current LE             178
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253: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:

lvcreate -L10G -n vm02 VolGroup00

Afterwards we can run

virt-install --prompt

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)? <-- 512
 What would you like to use as the disk (file path)? <-- /dev/VolGroup00/vm02
 What is the install URL? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.6/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).

 

5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Adrian (not registered) on Tue, 2011-10-25 12:23.
"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. " Why would LVM be any faster or create less disk IO than a normal disk image ? In the end LVM also writes to a hard-drive so what exactly is the difference? Thanks
Submitted by JohnP (not registered) on Mon, 2011-05-23 00:52.
If you are doing more than just 1 VM and plan to run some production on these VMs, you will want to have system performance monitoring be just a little easier. By default, the MAC addresses and TAP names are less than idea. I prefer to force helpful names so monitor software is easier to use and read.

How?
  • I set the MAC address last stanza to match the static IP address the server will get (set inside the VM).
  • I set the NIC name to the VM name


This in the /etc/xen/{vm}.cfg will do that.
vif = [ 'ip=172.18.1.46,mac=00:16:3E:D0:33:46,vifname=crm46.0' ]

Note the use of the "46" in the name, ip AND mac above. It is nice when the Xen/Dom0 doesn't automatically assign an always increasing vifname.