Grant McWilliams

Tech Virtualization

Virtualization

Note: I lost my original xen config files so I've created new ones here. I no longer have a xen system so I can't test them. Please let me know if the tutorial still works or not - Grant

Introduction

A lot of this tutorial was stolen from my CentOS 5 Installation which in turn was stolen from the CentOS wiki. I've shortened and updated it for installing a CentOS 6 DomU. I just copy and paste all the indented lines into a root terminal and voila! a CentOS VM.

1. Creating an Virtual Disk Image

The first step is to create an disk image that will act as the VM hard drive. The following command will create a 4 GB sparse disk image named /srv/xen/centos6.img. A sparse file is created in such a way that the disk image doesn't actually take up the whole 4GB until you fill it up. If you'd like a larger (11GB) disk image substitute seek=10240 into the following line. I make my VMs nice and small so I can move them around easier. Making a disk image larger or adding a second drive later is easier than making it smaller or taking a drive away.

 

dd if=/dev/zero of=/srv/xen/centos6.img oflag=direct bs=1M seek=3800 count=1

2. Preparing the Xen configuration file for installation

Xen uses one configuration file per VM. We will start out with a config to do the install and replace it later with a config for normal operation. Now we download the install kernel, ramdisk and xen config file.

wget http://mirror.centos.org/centos/6/os/i386/isolinux/vmlinuz -O /boot/vmlinuz-xen6-install
wget http://mirror.centos.org/centos/6/os/i386/isolinux/initrd.img -O /boot/initrd-xen6-install
wget http://www.grantmcwilliams.com/files/xen-centos6-i386-install -O /etc/xen/centos6

 

 

 

3. Starting the installation

A kickstart file holds instructions for automatic installation and is referenced in my xen config above. My example kickstart file is very minimal but is enough to get a working CentOS 6 VM.

 

Add a comment

The lastest version of Xen as of this writing is 4.0 but there's been some issues with blktap2 and other things with it so I'm still holding onto Xen 3.4. This tutorial shows how to upgrade a CentOS/RHEL 5 system to Xen 3.4. As soon as Xen 4.0 is as mature as I want it I'll update it again. I'm also retesting all of this as I'm not sure I had the problems with upgrading to 3.4 that I had with 3.3. I'll update it as soon as I'm done testing.

 

1. First we need to download the YUM repository file for the updated Xen. Then uninstall the old Virtualization group and reinstall it. This will upgrade the packages.

wget http://www.gitco.de/linux/x86_64/centos/5/CentOS-GITCO.repo -O /etc/yum.repos.d/gitco.repo
yum groupremove Virtualization
yum update
yum clean all
yum groupinstall -y Virtualization

 

Yum will probably want to upgrade some other files along with the ones we've chosen.

Warning! If you get an error message from grubby this is bad!

Installing: kernel-xen                   ####################### [ 9/13]
grubby fatal error: unable to find a suitable template

This means that your grub.conf file couldn't be written to for whaterver reason so you won't be able to successfully reboot. If you get this message you need to edit your /boot/grub/grub.conf file and make the kernel lines match the kernel you installed.

Get your installed kernel version:

[ root@vs / ] rpm -q kernel-xen

kernel-xen-2.6.18-128.4.1.el5

Now edit your /boot/grub/grub.conf to match this

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/vgsys/lvroot
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.4.1.el5xen)
root (hd0,0)
kernel /xen.gz-3.4.0
module /vmlinuz-2.6.18-128.4.1.el5xen ro root=/dev/vgsys/lvroot rhgb quiet
module /initrd-2.6.18-128.4.1.el5xen.img

4. Reboot - no really I mean it.

5. Try it out by using the xm dmesg command

[ root@vs ~ ] xm dmesg
__  __            _____ _  _    ___  
\ \/ /___ _ __   |___ /| || |  / _ \
\  // _ \ '_ \    |_ \| || |_| | | |
/  \  __/ | | |  ___) |__   _| |_| |
/_/\_\___|_| |_| |____(_) |_|(_)___/

(XEN) Xen version 3.4.0 (root@gitco.tld) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) Fri May 29 21:39:26 CEST 2009

That's about all. If you have any questions drop a comment here.

Add a comment

1. First we need to download the YUM repository file for the updated Xen. Then uninstall the old Virtualization group and reinstall it. This will upgrade the packages.

wget http://www.gitco.de/linux/x86_64/centos/5/CentOS-GITCO.repo -O /etc/yum.repos.d/gitco.repo
yum groupremove Virtualization
yum groupinstall -y Virtualization

Yum will probably want to upgrade some other files along with the ones we've chosen.

Warning! If you get an error message from grubby this is bad!

Installing: kernel-xen                   ####################### [ 9/13]
grubby fatal error: unable to find a suitable template

This means that your grub.conf file couldn't be written to for whaterver reason so you won't be able to successfully reboot. If you get this message you need to edit your /boot/grub/grub.conf file and make the kernel lines match the kernel you installed.

Get your installed kernel version:

[ root@vs / ] rpm -q kernel-xen

kernel-xen-2.6.18-128.4.1.el5

Now edit your /boot/grub/grub.conf to match this

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/vgsys/lvroot
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.4.1.el5xen)
root (hd0,0)
kernel /xen.gz-3.4.0
module /vmlinuz-2.6.18-128.4.1.el5xen ro root=/dev/vgsys/lvroot rhgb quiet
module /initrd-2.6.18-128.4.1.el5xen.img

4. Reboot - no really I mean it.

5. Try it out by using the xm dmesg command

\ \/ /___ _ __   |___ / |___ / / _ \
\  // _ \ '_ \    |_ \   |_ \| | | |
/  \  __/ | | |  ___) | ___) | |_| |
/_/\_\___|_| |_| |____(_)____(_)___/

(XEN) Xen version 3.3.0 (root@labor.lan) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) Tue Sep  9 20:18:14 CEST 2008
(XEN) Latest ChangeSet: unavailable
(XEN) Command line:
(XEN) Video information:
(XEN)  VGA is text mode 80x25, font 8x16
(XEN)  VBE/DDC methods: V2; EDID transfer time: 2 seconds
(XEN) Disc information:
(XEN)  Found 1 MBR signatures
(XEN)  Found 1 EDD information structures
(XEN) Xen-e820 RAM map:

That's about all. If you have any questions drop a comment here.

Add a comment

This is just a beta at this point

 

1. Install CentOS from CD. Do not choose Virtualization

2. Follow installing Xen 3.4 the easy way

3. Follow installing DomU the easy way

Add a comment

Qcow2

Create a disk image or download one from Stacklet.com

dd if=/dev/zero of=/srv/xen/CentOS5.img bs=1024 count=10000000

qemu-img convert -O qcow2 CentOS5-base.img CentOS5-base.qcow2.img

qcreate-qcow 50GB CentOS5-base.qcow2.img CentOS5.qcow2.img

 

 

 

Add a comment
fdfdfds Add a comment

I'm using a Xen Virtual Server to provide my Linux students with their own machines with admin rights. This has prompted interest in Xen from a lot of people just starting out in Virtualization. Following is a quick explaination of Xen and how to get a Virtual Machine up and running as fast as possible.

Hypervisors

Xen is a hypervisor meaning that it runs above the hardware but below any OS. Traditionally when you "virtualized" an OS you'd have a computer that you logged into which you installed virtualization software on such as VMWare workstation or VirtualBox. With this software you'd start the Virtual Machine from it's GUI and install the Guest OS via CDROM. In this case you have a Host Machine (the real physical machine) and a Guest Machine (the virtualized OS). With a hypervisor ALL operating systems are virtualized. This might seem a bit strange or impossible but is very powerful and extremely effecient. The side effect is that Xen can be very complex to set up. Let me explain the Xen boot process.

Xen Boot Process

  1. Machine runs code in Master Boot Record
  2. Bootloader loads the OS kernel
  3. Xen lodges itself in memory and loads the rest of the kernel in a Virtual Machine
  4. The user logs into the first Virtual Machine and starts, stops and restarts the other Virtual Machines from there

The name for the first Virtual Machine is Dom0 - it's the privileged Domain so it has direct access to the physical hardware. All subsequent Virtual Machines that are started are called DomU - unprivileged Domains. To manage a Xen Virtual Server you log into the Privileged Domain (Dom0) and use various commands to administer the Unprivileged Domains (DomUs).

Two modes of Virtualization

Virtualizers work in one of two modes - paravirtualization or hardware (full) virtualization. The difference being that a paravirtualized DomU OS knows it's being virtualized and has extensions to allow and assist in this. Paravirtualized Operating Systems are very fast and effecient. However there are times when you won't be virtualizing an OS that has these extensions such as Windows. In this case you need to use a CPU that has hardware vitualization support and run Xen in HVM (Hardware Virtualization Mode).

Paravirtualization:

  • Runs on a lot of hardware - x86, x86-64, Itanium and PowerPC 970 with or without hardware Virtualization support
  • DomUs can be Linux, NetBSD and Solaris
  • Very fast

Full Virtualization:

  • Requires Intel or AMD cpus with Virtualization Support built in
  • DomUs can be most any unmodified OS including Windows
  • Not so fast

To get around the speed issues with Full Virtualization there are paravirtualized drivers that have been written for many Operating Systems including Windows for disk access and network cards. This allows Full Virtualization to reach the speeds of paravirtualization in these two areas without requiring further modification to the Operating System. The Linux KVM Hypervisor runsin Full Virtualization mode all the time and thus needs paravirtualized drivers.

 

 

Add a comment

A lot of this tutorial was stolen from the CentOS wiki - http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU. I've shortened it by quite a bit to make it easier.  I assume you know this already but you will need to be logged in as root or have root privileges in order to execute this tutorial.

Creating an Image

The first step is to create an image that will hold the domU virtual disk. Since this can just be a file filled with zeros, our usual friend dd comes in handy.  The following command will create a /srv/xen/centos5.img file of 11GB, although the actual data blocks are allocated in a lazy fashion meaning that the disk image doesn't actually take up the whole 11GB until you fill it up. This is referred to as a sparse file.

 

dd if=/dev/zero of=/srv/xen/centos5.img oflag=direct bs=1M seek=10240 count=1

 

Add a comment

 

1. First we need to add the YUM repository holding the updated Xen. You will need to be logged in as root to carry out these instructions

 

wget http://www.gitco.de/linux/i386/centos/5/CentOS-GITCO.repo -O /etc/yum.repos.d/CentOS-GITCO.repo

2. Uninstall and reinstall the Virtualization group

yum groupremove Virtualization
yum update
yum clean all
yum groupinstall -y Virtualization
Add a comment

If you're moving from a real server installation to a VirtualBox virtualized configuration you may want to take your real physical disk and just turn it into a virtual disk. There are advantages to creating a new disk and rsyncing your OS into it but this tutorial will show you how to make an exact copy of it. Note the exact copy will be the same size as the real physical disk so make sure you have enough drive space. This is most useful for Operating System images with shared storage for data. I wouldn't advise anyone to make a 1TB copy of their new drive and turn it into a VDI file!

To get the image from the disk use the dd command.

  1. dd if=/dev/hda of=./hda.img
  2. VBoxManage convertdd hda.img hda.vdi
grant@workstation:~$ dd if=/dev/hda of=./hda.img
grant@workstation:~$ VBoxManage convertdd hda.img hda.vdi
VirtualBox Command Line Management Interface Version 1.6.0
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Converting VDI: from DD image file="hda.img" to file="hda.vdi"...
Creating fixed image with size 1024966656 bytes (978MB)...

This will make an exact copy of /dev/hda to the raw image file hda.img. Then VBoxManage will convert the raw disk hda.img to hda.vdi for use with VirtualBox.

Add a comment
Tech Virtualization