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 may get “trapped” inside this console. In case there is no “exit” possible, 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

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)"
44c68930-1192-a196-b460-5f411a689c85

A VDI will be created in the process, let's label it to avoid later confusion:

> xe vdi-list
...
uuid ( RO)                : 63e18344-6e0a-4bd5-9cc0-4b32d8de0e11
          name-label ( RW): 0
    name-description ( RW): Created by template provisioner
             sr-uuid ( RO): bc5fc2dd-fb0f-1e74-6226-0ece6e90c7a5
        virtual-size ( RO): 8589934592
            sharable ( RO): false
           read-only ( RO): false
...
> xe vdi-param-set name-label="DebianWheezy 0" uuid=63e18344-6e0a-4bd5-9cc0-4b32d8de0e11

A VBD was also created:

> xe vbd-list vm-name-label=Debian-Wheezy
uuid ( RO)             : 7b503b0e-ae3b-4f55-ef36-f6c3b8ed7ea3
          vm-uuid ( RO): 44c68930-1192-a196-b460-5f411a689c85
    vm-name-label ( RO): Debian-Wheezy
         vdi-uuid ( RO): 63e18344-6e0a-4bd5-9cc0-4b32d8de0e11
            empty ( RO): false
           device ( RO): 

We still need to create the virtual network interface, here we'll specify a MAC address that must be used for compatibility with a given failover IP:

> xe vif-create vm-uuid=44c68930-1192-a196-b460-5f411a689c85 network-uuid=1ce402ce-e6a1-b496-b967-a00cc586e525 device=0 mac=02:00:00:84:fb:29

Templated VM Specific Operations


From: http://wiki.xen.org/wiki/XCP_PV_templates_start:
Eliloader is python script located in /usr/bin/eliloader. It allows XCP to download network installation images (kernel and overgrown initrd) for specified operating system (actual network image is really differ in suse, centos and debian systems). For some legacy and antique systems (like RHEL 4) it to some patching of initrd. Exact path is constructed from type of template (install-distro in other-config) and url, provided by used in other-config: install-repository). After initrd and kernel is extracted they are used as kernel and initrd for virtual machine (and installation started).

Right after successful VM start PV-bootloader is replaced from eliloader to pygrub (to boot to new VM native kernel). Of course, if user stops installation process, at next startup there will be no kernel and vm will not start again.

> xe vm-param-set uuid=44c68930-1192-a196-b460-5f411a689c85 PV-bootloader=
> xe vm-param-set uuid=44c68930-1192-a196-b460-5f411a689c85 PV-kernel=/root/PVs/debian-wheezy/vmlinuz
> xe vm-param-set uuid=44c68930-1192-a196-b460-5f411a689c85 PV-ramdisk=/root/PVs/debian-wheezy/initrd.gz
> xe vm-start uuid=44c68930-1192-a196-b460-5f411a689c85

To follow the installation process:

> xe vm-param-get uuid=44c68930-1192-a196-b460-5f411a689c85 param-name=dom-id
4
> screen -S Wheezy
> /usr/lib/xen-4.1/bin/xenconsole 4

After initial installation:

> xe vm-param-set uuid=... PV-bootloader=pygrub

Add Xen Tools

TBC



Reference: http://www.jansipke.nl/creating-backups-of-running-vms-in-xenserver/

It seems that this operation can be performed even on a running VM.

Pick target VM uuid:

> xe vm-list is-control-domain=false is-a-snapshot=false

Create the snapshot:

> xe vm-snapshot uuid=<vm-uuid> new-name-label=<snapshotname>
<snapshot-uuid>

Transform the snapshot into a VM to be able to save it to a file:

> xe template-param-set is-a-template=false ha-always-run=false uuid=<snapshot-uuid>
> xe vm-export vm=<snapshot-uuid> filename=<filename>.xva
Export succeeded

The export operation can take a while… Be patient until you see the “Export succeeded” message.

Finally let's get rid of the snapshot:

> xe vm-uninstall uuid=<snapshot-uuid> force=true


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