Archive:Docs/Fedora7VirtQuickStart

= Virtualization in Fedora 7 =

Fedora 7 includes support for both the KVM and the Xen virtualization platforms. For more information on different virtualization platforms, see http://virt.kernelnewbies.org/TechComparison.

More information on Xen itself can be found at http://wiki.xensource.com/xenwiki/ and the Fedora  Xen  page. More information on KVM can be found at http://kvm.qumranet.com/kvmwiki.

Fedora is following the 3.0.x Xen line. Xen 3.0.0 was released in December of 2005 and is incompatible with guests using the previous Xen 2.0.x releases.

= Quick Start =

Setting up Xen and guests in Fedora 7 has some significant changes and improvements since the release of Fedora Core 6. The following guide will explain how to set up Xen and KVM, and how to create and manage guests using either the command line or GUI interface.

System Requirements

 * For Xen, GRUB, the default boot loader for is required[[FootNote(This is required because the system actually boots the Xen hypervisor and it then starts the Linux kernel. It does this using the Multi  for booting the   kernel. The   kernel is not set as the default boot option.

To set GRUB to boot with  by default, edit   and set the default to the xen [[FootNote(Note that future kernel-xen packages can be set to the default kernel by editing  )]

This is an example  configured to boot into the Xen hypervisor:

default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Fedora (2.6.20-2925.5.fc7xen) root (hd0,0) kernel /xen.gz-2.6.20-2925.5.fc7 module /vmlinuz-2.6.20-2925.5.fc7xen ro root=/dev/VolRoot/LogVolRoot rhgb quiet module /initrd-2.6.20-2925.5.fc7xen.img title Fedora (2.6.20-1.3084.fc7) root (hd0,0) kernel /vmlinuz-2.6.20-1.3084.fc7 ro root=/dev/VolRoot/LogVolRoot rhgb quiet initrd /initrd-2.6.20-1.3084.fc7.img

Installing the KVM Software
When doing a fresh install of Fedora 7, KVM can be installed by selecting KVM in the Base Group in the installer.

For existing Fedora 7 installations, the KVM package and virtualization tools can be installed by running the following command:

This installs the required packages and their dependencies. Note that KVM is included in the regular kernel; booting into a special kernel is not required.

Enabling Xen
Once the system is booted into the Xen kernel, check to verify the kernel and that Xen is running:

2.6.20-2925.5.fc7xen

Name                             ID Mem(MiB) VCPUs State  Time(s) Domain-0                          0      610     1 r- 12492.1

The above output should show that the Xen kernel is loaded and that Domain-0 (the host operating system) is running.

Enabling KVM
After the KVM package is installed, the system should be rebooted in order to load the KVM modules. No other action is required to enable KVM.

Building a Fedora Guest System
With Fedora 7, installation of Fedora 7 guests using anaconda is supported. The installation can be started on the command line via the  program or in the GUI program.

Building a Fedora Guest System using
Start the interactive install process by running the  command-line program:

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  for more details. In particular, kickstart options can be passed with.

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  commands and also appear in   the Gnome-panel Xen applet. In addition, it will be the name of the  file that stores the guest's configuration information. 1. 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. 1. 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. 1. 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 1. Would you like to enable graphics support (yes or no): Should the graphical installer be used? 1. What is the install location? This is the path to a Fedora 7 installation tree in the format used by anaconda. NFS, FTP, and HTTP locations are all supported. Examples include:

The installation will then commence. If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, the standard text installer will appear. Proceed as normal with the installation.

Building a Fedora Guest System using
Start the GUI Virtual Machine Manager by selecting it from the "Applications-->System Tools" menu, or by running the following command as root:


 * 1) Choose "Local Xen Host" and click "Connect" in the "Open Connection" dialog window.
 * 2) Click the "New" button at the bottom of the   window, or select File-->New.
 * 3) A wizard will present the same questions as appear with the   command-line utility (see descriptions above). The wizard assumes that a graphical installation is desired and does not prompt for this option.
 * 4) On the last page of the wizard there is a "Finish" button. When this is clicked, the guest OS is provisioned. After a few moments a VNC window should appear. Proceed with the installation as normal.

Building a Fedora Guest System using 'cobbler' and 'koan'
Cobbler is a tool for configuring a provisioning server for PXE, Xen, and existing systems. See http://cobbler.et.redhat.com for details. The following instructions are rather minimal and more configuration options are available.

First, set up a provisioning server:

yum install cobbler man cobbler # read the docs! cobbler check # validate that the system is configured correctly cobbler distro add --name=myxendistro --kernel=/path/to/vmlinuz --initrd=/path/to/initrd.img cobbler profile add --name=myxenprofile --distro==myxendistro [--kickstart=/path/to/kickstart] cobbler list # review the configuration cobbler sync # apply the configuration to the filesystem

Alternatively, cobbler can import a Fedora rsync mirror and create profiles automatically from there. Some of the imported distros will be Xen profiles and some will be for bare metal. Usage of the Xen profiles will be required. See the manpage for details.

cobbler import --mirror=rsync://your-fedora-mirror --mirror-name=fedora cobbler sync

On the system that will host the image:

yum install koan koan --virt --profile=myxenprofile --server=hostname-of-cobbler-server

After Installation
When the installation of the guest operating system is complete, it can be managed using the GUI  program or on the command line using.

Managing Virtual Machines graphically with
Start the GUI Virtual Machine Manager by selecting it from the "Applications-->System Tools" menue, or by running the following command:

{1} If you are not root, you will be prompted to enter the root password. Choose to operate in a read-only non-root mode.


 * Choose "Local Xen Host" and click "Connect" in the "Open Connection" dialog window.
 * The list of virtual machines is displayed in the main window. The first machine is called "Domain 0"; this is the host computer.
 * If a machine is not listed, it is probably not running. To start up a machine select "File-->Restore a saved machine..." and select the file that serves as the guest's disk.
 * The display lists the status, CPU and memory usage for each machine. Additional statistics can be selected under the "View" menu.
 * Double click the name of a machine to open the virtual console.
 * From the virtual console, select "View-->Details" to access the machine's properties and change its hardware configuration
 * To access the serial console (if there is a problem with the graphical console) select "View-->Serial Console"

For further information about  consult the project website

Bugs in the  tool should be reported in BugZilla  against the 'virt-manager' component

Managing Virtual Machines from the command line with
Virtual machines can be managed on the command line with the  utility. The  utility is built around the libvirt management API and has a number of advantages over the traditional Xen   tool:


 * virsh has a stable set of commands whose syntax & semantics will be preserved across updates to Xen.
 * virsh can be used as an unprivileged user for read-only operations (eg listing domains, getting info, etc)
 * virsh will (in future) be able to manage QEMU, VMWare, etc machines in additional to Xen, since libvirt is hypervisor agnostic.

To start a new virtual machine from an XML vm definition:

To list the virtual machines currently running, use:

To gracefully power off a guest use:

To save a snapshot of the machine to a file of your choosing:

To restore a previously saved snapshot:

To export the XML config associated with a virtual machine:

For a complete list of commands available for use with  run:

Or consult the manual page

Bugs in the  tool should be reported in BugZilla  against the 'libvirt' component

Managing Virtual Machines from the command line with
KVM virtual machines can be managed in the command line using the 'qemu-kvm' command.

Managing Virtual Machines from the command line with
In addition to the  command, virtual machines can also be managed on the command line with the Xen-specific   utility. To power on a virtual machine and attach a serial console, use:

To list the virtual machines currently running, use:

To power off a guest use:

To save a snapshot of the machine to a file:

To restore a previously saved snapshot:

To display -like statistics for all running machines:

For a complete list of commands available for use with  run:

Bugs in the  tool should be reported in BugZilla  against the 'xen' component

= Troubleshooting =

SELinux
The SELinux policy in Fedora 7 has the neccessary rules to allow use of Xen with SELinux enabled. The main caveat to be aware of is that any file backed disk images need to be in a special directory - /var/lib/xen/images. This applies both to regular disk images, and ISO images. Block device backed disks are already labelled correctly to allow them to pass SELinux checks.

Log files
There are two log files stored on the host system to assist with debugging Xen related problems. The file  holds the same information reported with '. Unfortunately these log messages are often very short and contain little useful information. The following is the output of trying to create a domain running the kernel for NetBSD/xen.

[2005-06-27 02:23:02 xend] ERROR (SrvBase:163) op=create: Error creating domain:(0, 'Error') Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/xen/xend/server/SrvBase.py", line 107, in _perform val = op_method(op, req) File "/usr/lib/python2.4/site-packages/xen/xend/server/SrvDomainDir.py", line 71, in op_create raise XendError("Error creating domain: " + str(ex)) XendError: Error creating domain: (0, 'Error')

The second file,  usually contains much more detailed information. Trying to start the NetBSD/xen kernel will result in the following log output:

ERROR: Will only load images built for Xen v3.0 ERROR: Actually saw: 'GUEST_OS=netbsd,GUEST_VER=2.0,XEN_VER=2.0,LOADER=generic,BSD_SYMTAB' ERROR: Error constructing guest OS

When reporting errors, always include the output from both  and.

If starting a fully-virtualized domains (ie to run unmodified OS) there are also logs in /var/log/xen/qemu-dm*.log which can contain useful information.

Finally, hypervisor logs can be seen by running the command

xm dmesg

Host serial console access
For more difficult problems, serial console can be very helpful. If the Xen kernel itself has died and the hypervisor has generated an error, there is no way to record the error persistently on the local host. Serial console lets you capture it on a remote host.

The Xen host must be setup for serial console output, and a remote host must exist to capture it. For the console output, set the appropriate options in /etc/grub.conf:

title Fedora Core (2.6.17-1.2600.fc6xen) root (hd0,2) kernel /xen.gz-2.6.17-1.2600.fc6 com1=38400,8n1 sync_console module /vmlinuz-2.6.17-1.2600.fc6xen ro root=LABEL=/ rhgb quiet console=ttyS0 console=tty pnpacpi=off module /initrd-2.6.17-1.2600.fc6xen.img

for a 38400-bps serial console on com1 (ie. /dev/ttyS0 on Linux.) The "sync_console" works around a problem that can cause hangs with asynchronous hypervisor console output, and the "pnpacpi=off" works around a problem that breaks input on serial console. "console=ttyS0 console=tty" means that kernel errors get logged both on the normal VGA console and on serial console. Once that is done, install and set up  to capture the information on a remote host connected by a standard null-modem cable. For example, on the remote host:

Will log output from /dev/ttyS0 into a file /var/log/ttywatch/myhost.log

Paravirt guest serial console access
Para-virtualized guest OS will automatically have a serial console configured, and plumbed through to the Domain-0 OS. This can be accessed from the command line using

Alternatively, the graphical  program can display the serial console. Simply display the 'console' or 'details' window for the guest & select 'View -> Serial console' from the menu bar.

Fullyvirt guest serial console access
Fully-virtualized guest OS will automatically have a serial console configured, but the guest kernel will not be configured to use this out of the box. To enable the guest console in a Linux fully-virt guest, edit the /etc/grub.conf in the guest and add 'console=ttyS0 console=tty0'. This ensures that all kernel messages get sent to the serial console, and the regular graphical console. The serial console can then be access in same way as paravirt guests:

Alternatively, the graphical  program can display the serial console. Simply display the 'console' or 'details' window for the guest & select 'View -> Serial console' from the menu bar.

Accessing data on a guest disk image
There are two tools which can help greatly in accessing data within a guest disk image: lomount and kpartx.

lomount only works with small disk images and cannot deal with LVM volumes, so for more complex cases, kpartx (from the device-mapper-multipath RPM) is preferred:


 * kpartx

add map guest1p1 : 0 208782 linear /dev/xen/guest1 63 add map guest1p2 : 0 16563015 linear /dev/xen/guest1 208845

Note that this only works for block devices, not for images installed on regular files. To use file images, set up a loopback device for the file first:

/dev/loop0 add map loop0p1 : 0 208782 linear /dev/loop0 63 add map loop0p2 : 0 12370050 linear /dev/loop0 208845

In this case we have added an image formatted as a default Fedora install, so it has two partitions: one /boot, and one LVM volume containing everything else. They are accessible under /dev/mapper:

brw-rw 1 root disk 253, 6 Jun  6 10:32 xen-guest1 brw-rw 1 root disk 253, 14 Jun 6 11:13 guest1p1 brw-rw 1 root disk 253, 15 Jun 6 11:13 guest1p2

To access LVM volumes on the second partition, rescan LVM with  and activate the volume group on that partition (named "VolGroup00" by default) with  :

Reading all physical volumes. This may take a while... Found volume group "VolGroup00" using metadata type lvm2 2 logical volume(s) in volume group "VolGroup00" now active LV       VG         Attr   LSize   Origin Snap%  Move Log Copy% LogVol00 VolGroup00 -wi-a-   5.06G LogVol01 VolGroup00 -wi-a- 800.00M ...

Frequently Asked Questions

 * Q: I am trying to start the xend service and nothing happens, then when I do a  manually and get the following error:

ERROR: Could not obtain handle on privileged command interface (2 = No such file or directory) Traceback (most recent call last): File "/usr/sbin/xend", line 33, in ? from xen.xend.server import SrvDaemon File "/usr/lib/python2.4/site-packages/xen/xend/server/SrvDaemon.py", line 21, in ? import relocate File "/usr/lib/python2.4/site-packages/xen/xend/server/relocate.py", line 26, in ? from xen.xend import XendDomain File "/usr/lib/python2.4/site-packages/xen/xend/XendDomain.py", line 33, in ? import XendDomainInfo File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 37, in ? import image File "/usr/lib/python2.4/site-packages/xen/xend/image.py", line 30, in ? xc = xen.lowlevel.xc.xc RuntimeError: (2, 'No such file or directory')

A: You have rebooted your host into a kernel that is not a xen-hypervisor kernel. Yes I did this myself in testing :)

You either need to select the xen-hypervisor kernel at boot time or set the  xen-hypervisor kernel as default in your grub.conf file.


 * Q. When creating a guest the message "Invalid argument" is displayed.

A. This usually indicates that the kernel image you are trying to boot is incompatible with the hypervisor. This will be seen if trying to run a FC5 (non-PAE) kernel on FC6 (which is PAE only), or if trying to run a bare metal kernel.


 * Q. When I do a yum update and get a new kernel, the grub.conf default kernel switches back to the bare-metal kernel instead of the Xen kernel

A. The default kernel RPM can be changed in /etc/sysconfig/kernel. If it is set to 'kernel-xen', then the Xenified kernel will always be set as default option in grub.conf

Getting Help
If the Troubleshooting section above does not help you to solve your problem, check the Red Hat Bugzilla for existing bug reports on Xen in FC6. The product is "Fedora Core", and the component is "kernel" for bugs related to the xen kernel and "xen" for bugs related to the tools. These reports contain useful advice from fellow xen testers and often describe work-arounds.

For general Xen issues and useful information check the Xen project documentation, and mailing list archives.

Finally, discussion on Fedora Xen support issues occur on the Fedora Xen mailing list