This is an old revision of the document!


Install VM as DomU (guest)

Note that prior to installing a Virtual Machine, you'll need to setup your storage repositories.

To create a new VM, you'll need to execute the following actions:

Have the ISO Image Available

In our first VM, we'll deploy “Linux Mint Debian Edition 201403”.
To achieve this , we first need to download the ISO image of the installer and make it available to Xen. Here's how to do this:

Download the ISO

Into the LocalISORepository:

> cd /var/opt/xen/LocalISORepository/
> wget http://linuxmint.cu.be/debian/linuxmint-201403-cinnamon-dvd-64bit.iso

Re-Scan the Directory

> xe sr-list name-label=Local\ ISO\ Repository --minimal
> xe sr-scan uuid=xxxxxxx-7d10-a322-9ba8-xxxxxxxxxxxxxx
> xe cd-list

Should show you the newly available CD:

> xe cd-list
uuid ( RO)          : e9175357-44e4-41fc-acd7-f361c27d56ef
    name-label ( RW): linuxmint-201403-cinnamon-dvd-64bit.iso

Install the VM

The first thing to do is to “install” the VM, you have to specify a template to use as the base, to figure out what templates are available, use xe template-list. In case none of these fits your needs, i.e. you plan to use an ISO image, select the “Other install media”.

[> xe template-list]
> xe vm-install new-name-label=LMDE-VM1 template="Other install media"

This will output an UUID that you should copy.

Create a VDI

VDI stands for Virtual Disk Image, such an image is required by the VM that will use it as if it was a real hard drive. This VDI has to be stored somewhere, here we'll select an SR that was specifically created for the LMDE VM.

Refer to the Storage Repositories Creation chapter to remember how to do it, in case you often forget (like me).

Get the SR UUID:

> xe sr-list name-label="LMDE Storage" --minimal

Copy this SR UUID

We now can create the actual VDI:

> xe vdi-create sr-uuid=<sr-uuid> type=user virtual-size=256GiB name-label='LMDE-VDI1'

Create a VBD

VBD stands for Virtual Block Device, you can think of it as the “cable” that plugs the VDI into your VM's hard disk connector. Thus, you need to specify what “disk” it starts at and what “machine” it's plugged into.

You need to specify:

  • the virtual disk you want to plug to (vid-uuid)
  • the virtual machine you want to connect to (vm-uuid)
  • whether the disk is bootable / writable - at first we do not make it bootable as we'll startup the VM from the installation CD drive
  • a device name: this device-name will be used by the installer from within the VM, if unsure about how the OS being installed names it, use 'device=0'. You cannot use names at your will here!
> xe vbd-create vdi-uuid=<VDI-UUID> vm-uuid=<VM-UUID> bootable=false type=Disk device=sda

Copy the UUID output

Attach a CD Drive

As we're going to use the préviously downloaded LMDE install CD ISO, we have to attach it to the VM so it can boot from it the first time it is launched.

To get the list of available cd images, you can issue the xe cd-list command.

[> xe cd-list]
> xe vm-cd-add vm=<VM-NAME-LABEL> device=1 cd-name=linuxmint-201403-cinnamon-dvd-64bit.iso

We still need to change the install-behaviour on the VM, so it looks for install-repositories on “cdrom”:

> xe vm-param-set uuid=<VM-UUID> other-config:install-repository=cdrom

Setup the VM's RAM

As the final step, we now can determine how much memory will be made available to our new VM.

> xe vm-memory-limits-set uuid=<VM-UUID> static-min=2GiB dynamic-min=2GiB dynamic-max=4GiB static-max=4GiB

Attach Network

> xe network-list
> xe vif-create vm-uuid=<uuid of vm> network-uuid=<uuid of network> device=0

Start the VM (to execute install)

Up to now we've “just” been defining our VM's specifications, nothing “really” happened. It's time to boot our VM, then connect to it in order to follow and interact with the installation process:

> xe vm-start uuid=<VM-UUID>

Auto-Start a VM

If you need to have a VM automatically started when Xen is launched, here is what you have to do:

> xe vm-param-set uuid=UUID other-config:auto_poweron=true

Connect to the Running VM

We first need to find our VM's dom-id, then we'll look into xenstore to get the connection parameters (VNC listener port):

> xe vm-param-get uuid=<VM-UUID> param-name=dom-id
or
> xe vm-param-get uuid=$(xe vm-list name-label=LMDE-VM1 --minimal); param-name=dom-id
2

Finding VNC Port #

To identiy VM running as PV or HVM:

> ps -eaf | grep qemu

For HVM (xenfv)

> xenstore-ls /local/domain/<DOM-ID>/console

For PV (xenpv)

> xenstore-ls /local/domain/<DOM-ID>/serial

Or:

> xenstore-read /local/domain/<DOM-ID>/console/vnc-port
5901

To VNC connect to the VM, we first need to know it's domain-id, this changes with every reboot of the VM!
We also need the VNC listener port for the VM with found dom-id.

You can now connect with vncviewer to hostname-from-domX:<vnc-port>

Finding the Guest IP Address though VM's console

One easy way to connect to your VM console is as folllow:

> xe vm-list params=dom-id uuid=<uuid-of-vm> --minimal
OR
> xe vm-list params=dom-id name-label=XOA
> /usr/lib/xen/bin/xenconsole <dom-id>

Once in the guest console, simply:

> ip addr show

You might not find the /usr/lib/xen/ directory on your system as it might be appended with the system version, i.e: use /usr/lib/xen-4.1/bin/xenconsole.

To avoid this confusion you could create a symbolic link like this:

> ln -s /usr/lib/xen-4.1 /usr/lib/xen

You might also experiment a “freeze” when connecting, hit the RETURN key to see the terminal prompt…

Once logged into the VM's console, you'll be “trapped” inside this console. It won't be possible for you to come back to the host's console.

This might be a problem when interacting from a plain terminal screen on the host itself, getting locked out of your host's console might force you to force a reboot in case you cannot access it via ssh from another machine to reboot it nicely!.

Install Xen Tools

Log into your VM console:

> xe vm-list params=dom-id name-label=LMDE-VM1
> /usr/lib/xen/bin/xenconsole 1

If you're lucky enough to have chosen a Debian base install, installing Xen Tools is simply a matter of:
IN VM CONSOLE

$ apt-get install xen-tools

Download the kernel and ramdisk

http://cdn.debian.net/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/

> mkdir -p /root/PVs/debian-wheezy
> cd /root/PVs/debian-wheezy/
> wget http://cdn.debian.net/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/initrd.gz
> wget http://cdn.debian.net/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/vmlinuz

Create a logical volume for the VM's hard drive

> sudo lvcreate -L8G -nDebianWheezy xenvg

=== Install the VM using the chosen template

> xe template-list | grep Debian
> xe vm-install new-name-label=Debian-Wheezy template="Debian Wheezy 7.0 (64-bit)"


It is possible to immediately create new VMs based on standard templates readily available in Xen.

What we want to do here is deploy a new VM that will run LinuxMint LMDE 201403 cinnamon 64bit. To do so, we first need to download the corresponding ISO file. We'll ssh into Dom0 and wget the installer image:

> ssh root@my.machine.ip
> cd /var/opt/xen/LocalISORepository/
> wget http://linuxmint.cu.be/debian/linuxmint-201403-cinnamon-dvd-64bit.iso

The new image won't immediately be available in the cd list:

> xe cd-list

Will be empty.

Every time you add (or delete) an ISO image to your repository, you'll have to rescan it to update the list of available images:

> xe sr-scan uuid=$(xe sr-list name-label='Local ISO Repository' --minimal)";
> xe cd-list
uuid ( RO)          : 768af2e3-f6c6-481a-b7c4-a28c2603960b
    name-label ( RW): linuxmint-201403-cinnamon-dvd-64bit.iso

We can now use the Xen Orchestra web interface to create our new VM.

xen-tools is a set of scripts which can easily create fully configured Xen guest domains.

Once you have installed dom0 you can install xen-tools on your host with:

> apt-get install xen-tools

To configure xen-tools, you can edit /etc/xen-tools/xen-tools.conf which contains default values that the xen-create-image script will use. The xen-create-image(8) manual page contains information on the available options.

To give a different path where the domU images being saved and enable the superuser password in the initial build, we will edit the /etc/xen-tools/xen-tools.conf file and uncomment this lines:

> nano /etc/xen-tools/xen-tools.conf

[ 55] lvm = xenvg
[129] memory = 1024Mb   # Memory size
[130] swap = 1024Mb     # Swap size
[158] dhcp = 1
[174] bridge = xenbr0
[221] passwd = 1

Then you can create a basic virtual machine with this command:

> xen-create-image --hostname=VM_name --role=udev

To start the created VM run the command:

> xm create /etc/xen/VM_name.cfg

To erase a VM image (even the main directory) run the command:

> xen-delete-image VM_name