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

Prerequisites

This howto needs :

Parameters

Provide a hostname for the new domU:

XEN_HOST="host.domain.xen1"

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 :

XEN_HOST="mysql.biapy.ovh3"

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

XEN_VAR="10g"

Provide the IP address of the new domU :

XEN_IP="10.0.0.3"

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

# XEN_IP="dhcp"

DomU creation

Initialization

Check the IP address settings :

if [ "${XEN_IP}" = "dhcp" -o -z "${XEN_IP}" ]; then
IP_OPTIONS="--dhcp"
else
IP_OPTIONS="--ip ${XEN_IP}"
fi

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}"
DISK_TYPE="sda"
if [ -n "$(command grep -e "xvda" "${MOUNT_POINT}/etc/fstab")" ]; then
  DISK_TYPE="xvda"
fi
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

Activation

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 :

LANG=fr_FR.UTF-8

Reboot the domU to apply changes.