You are here: Home / Debian GNU/Linux / System / Xen / Create a Xen domU

Create a Xen domU

by Pierre-Yves Landuré last modified Nov 08, 2017 02:54

This howto helps you to create a Xen domU with xen-tools and a distinct /var partition.

This howto is tested on :

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy


This howto needs :


Provide a hostname for the new domU:


I propose to use this naming convention :

  • host: Code for domU usage, for example: mysql for a MySQL server.
  • domain: Company name, for example: biapy
  • xen1: Code for Xen server, for example: ovh3 for the 3rd company server hosted by OVH.

The result is :


Provide the drive space assigned to /var partition (here, 10GB) :


Provide the IP address of the new domU :


Note: To use a IP address provided by DHCP, use :

# XEN_IP="dhcp"

DomU creation


Check the IP address settings :

if [ "${XEN_IP}" = "dhcp" -o -z "${XEN_IP}" ]; then

Initialize the domU :

command xen-create-image --hostname "${XEN_HOST}" \
    ${IP_OPTIONS} --passwd --role automatic

Adding /var filesystem

According to the recommendations of the Linux Standard Base, the "/var" folder contains files that can be changed by the system (databases, e-mails, web sites datas, backups, etc.) This howto assign a logicial volume to this folder in order to ease the drive space assignation to a domU.

Create the LVM logical volume for the /var filesystem :

LVM_VG=$(command grep 'lvm' '/etc/xen-tools/xen-tools.conf' \
| command sed -e 's/lvm = //') command lvcreate -n "${XEN_HOST}-var" -L "${XEN_VAR}" "${LVM_VG}" command mkfs.ext4 "/dev/${LVM_VG}/${XEN_HOST}-var"

Edit the domU configuration file to use the logical volume :

command umount "/dev/${LVM_VG}/${XEN_HOST}-disk"
MOUNT_POINT=$(command mktemp -d)
command mount "/dev/${LVM_VG}/${XEN_HOST}-disk" "${MOUNT_POINT}"
if [ -n "$(command grep -e "xvda" "${MOUNT_POINT}/etc/fstab")" ]; then
command echo "/dev/${DISK_TYPE}3   /var    ext4    defaults                0       1" \
>> "${MOUNT_POINT}/etc/fstab" VAR_MOUNT_POINT=$(command mktemp -d) command mount "/dev/${LVM_VG}/${XEN_HOST}-var" "${VAR_MOUNT_POINT}" command cp -a "${MOUNT_POINT}/var/"* "${VAR_MOUNT_POINT}" command umount "${VAR_MOUNT_POINT}" command umount "${MOUNT_POINT}" if [ $(command grep "disk[\t ]*=.*\]" "/etc/xen/${XEN_HOST}.cfg" \
| command wc --lines) -eq 0 ]; then command sed -i -e "/^disk[\t ]*=.*/a\\ 'phy:${LVM_VG}\/${XEN_HOST}-var,${DISK_TYPE}3,w'," \ "/etc/xen/${XEN_HOST}.cfg" else command sed -i \
-e "s/^\(disk[\t ]*=.*\)\]/\1, 'phy:${LVM_VG}\/${XEN_HOST}-var,sda3,w' ]/" \
"/etc/xen/${XEN_HOST}.cfg" fi


Activate the new domU with :

command xm create "/etc/xen/${XEN_HOST}.cfg"

Set up the automatic domU activation at dom0 start-up :

command mkdir --parents "/etc/xen/auto"
command mv "/etc/xen/${XEN_HOST}.cfg" "/etc/xen/auto"

Fixing errors

Ubuntu domU

A Ubuntu domU can have locales errors. To fix those, generate the missing locale :

command locale-gen 'fr_FR.UTF-8'

Edit "/etc/environment" file and make sure it contains :


Reboot the domU to apply changes.