home | tech | misc | code | bookmarks (broken) | contact | README

# 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 page, section 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.

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 (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.

Most of the tips I got for this section are here 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 http://mirror.globo.com/centos/6/os/x86_64/isolinux/vmlinuz
# wget http://mirror.globo.com/centos/6/os/x86_64/isolinux/initrd.img


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.

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

name="centos6"
vcpus=4
memory=2048
disk=['file:/vm/centos6/centos6.img,xvda,w' ]
vif=['bridge=xenbr0']
on_reboot="restart"
on_crash="restart"
kernel="/vm/centos6/vmlinuz"
ramdisk="/vm/centos6/initrd.img"


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.

# mkdir -p /vm/centos7
# cd /tmp/centos7
# wget http://mirror.globo.com/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso


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:

name="centos7"
vcpus=4
memory=2048
disk=['file:/vm/centos7/centos7.img,xvda,w', 'file:/vm/centos7/CentOS-7-x86_64-Minimal-1804.iso,hdc:cdrom,r' ]
boot='d'
vif=['bridge=bridge0']
on_reboot="restart"
on_crash="restart"
builder="hvm"


Thanks for this link for the configuration file.

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' ]
boot='c'


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?