Created at:

Modified at:

Xen: Setup Linux as domU

We are using dom0 host configured with NetBSD 8.0. For more information how to setup dom0, check:

Xen setup in NetBSD

Possible guest configurations

Before starting, it is good to know that a domU guest can be installed in different modes. In this guide we are going to initial setup of CentOS Linux as PV and HVM guests.

What's the difference between PV (Paravirtualized) and HVM? For this, I recommend you to take a look at the "Xen Project Software Overview: Guest Types" , but, in summary, in PV mode you need to run a modified version of the kernel for your domU system, but it doesn't require any special processor support. In HVM mode, you can run an unmodified operating system as domU (so, it is possible to run Windows), but it requires special instruction in your processor.

Xen Project Software Overview page, Guest Types

You may want to run your guests as HVM to save you some trouble, but there may be are advantages running them as paravirtualized guests.

Installing CentOS as Paravirtualized (PV) domU

First, it is important to note that CentOS doesn't support paravirtualization since version 7.4, as noted by smart prgmr people (link below) (note that they point to an alternate kernel that can support PV mode). So these instructions work for older versions of CentOS. The one we are going to use in this section is version 6, but it may work for versions up to 7.3.

Upgrade with caution: CentOS 7.4 (1708) does not support PV

How to Install Paravirtualized CentOS 7 DomU on Xen

First, download CentOS 6 kernel and initrd. Links below worked at the time I was writing this:

    # mkdir -p /vm/centos6
    # cd /vm/centos6
    # wget
    # wget

For now, we are going to cover how to setup the virtual machine in a image file. It is possible to use a separated partition for it, improving performance, but it is beyond the scope of this guide. Create the image:

    # dd if=/dev/zero of=centos6.img bs=1m seek=20000 count=1

We created a 20 GB image, but in sparse file format, with the seek operand.

Sparse file

We now create file centos6.cfg with the following content:

    disk=['file:/vm/centos6/centos6.img,xvda,w' ]

You can now just instruct Xen to create our virtual machine:

    # xl create centos6.cfg

And to access its console, type::

    # xl console centos6

Installing CentOS with full hardware virtualization (HVM)

The installation of an CentOS HVM guest is straighforward. You can use recent CentOS official images, since the kernel don't need to be modified.

Download CentOS 7 ISO:

    # mkdir -p /vm/centos7
    # cd /tmp/centos7
    # wget

Let's create a 20 GB image sparse image:

    # dd if=/dev/zero of=centos7.img bs=1m seek=20000 count=1

The centos7.cfg configuration file will look like this:

    disk=['file:/vm/centos7/centos7.img,xvda,w', 'file:/vm/centos7/CentOS-7-x86_64-Minimal-1804.iso,hdc:cdrom,r' ]

Xen domU configuration file example

In HVM setups, you'll need to use vncviewer to see what is happening on the virtual machine:

    # vncviewer localhost

After you perform the installation, you can change the disk=... and boot=... lines to:

    disk=['file:/vm/centos7/centos7.img,xvda,w' ]

And finally boot your machine from the HDD image.

Important: For some reason I didn't discover why (if you know, please, let me know, I couldn't boot from the HDD image if I had the ISO on the configuration, so I removed that after the installation. TODO: why?