The following is a guide for creating DomU virtual machines in Xen Project Hypervisor using xen-tools. If you are looking for an in-depth Xen Projoect Hypervisor guide, please refer to Installing Xen Project Hypervisor on Debian 9: An in-depth beginner’s guide.
If xen-tools is not yet installed on your Dom0 host, you may do so by running the following apt-get command as root:
# apt-get install xen-tools
As advertised on xen-tools’s official website, “xen-tools is a collection of simple perl scripts which allow you to easily create new guest Xen domains upon your Debian GNU/Linux host.”
Two important factors to consider before deciding whether or not xen-tools is suitable for your project include:
- xen-tools currently only supports the creation of paravirtualized (“PV”) DomUs – in other words, no “HVM”, and
- xen-tools currently only supports installs of Debian, Ubuntu, and CentOS 5/6 DomU operating systems (“OS”).
If the above points fit your requirements, then you’ll be happy to know that,
- xen-tools automates the creation of LVM (or loopback or EVMS) root and swap partitions,
- xen-tools automates the installation of the selected OS on the newly generated root partition, and
- xen-tools automates the creation of the new DomU’s “.cfg” file.
Overall, xen-tools is a huge time saver when it comes to creating new virtual machines. After running the program, the new DomU is ready to boot by simply executing the xl create command.
Before we look at some command line examples, let’s get a better understanding of xen-tools’s most popular options for configuring new DomU, and their corresponding defaults.
xen-tools has two types of default values: hard defaults coded into the software, and soft defaults easily changed in the xen-tools.conf file. Any hard or soft default may be overridden, or additional options added, at the command line when the xen-tools xen-create-image command is executed.
Note that the defaults described below are only a small fraction of all options available in xen-tools: the xen-create-image manual page is the best reference for unlocking the program’s full potential.
$ man xen-create-image
Some notable xen-tools hard defaults include the following:
- xen-tools devises disk names for DomU using the pattern “xvda”,
- new DomU configuration files are created with the suffix “.cfg”,
- xen-tools generates random root account passwords for new DomU,
- the default number of virtual cpus (“vcpus”) assigned to new DomU is 1,
- xen-tools uses “debootstrap” as the install method for Debian and Ubuntu DomU,
- xen-tools uses preset mirror servers while creating Debian and Ubuntu DomU, and
- new DomU .cfg files are created and saved in the /etc/xen directory.
Post installation of xen-tools version 4.7-1, the following uncommented lines are found in the /etc/xen-tools/xen-tools.conf file. For our purposes, these lines are considered soft defaults as the values stored in the .conf file may be easily edited by the user.
# Installation method. install-method = debootstrap ... # Disk and Sizing options. size = 4G # Root disk, suffix (G, M, k) required memory = 256M # Suffix (G, M, k) required swap = 512M # Suffix (G, M, k) required fs = ext4 # Default file system for any disk dist = `xt-guess-suite-and-mirror --suite` # Default distribution is determined by Dom0's distribution image = sparse # Specify sparse vs. full disk images (file based images only) ... # Default kernel and ramdisk to use for the virtual servers kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` ... # Filesystem options for the different filesystems we support. ext4_options = noatime,nodiratime,errors=remount-ro ext3_options = noatime,nodiratime,errors=remount-ro ext2_options = noatime,nodiratime,errors=remount-ro xfs_options = defaults reiserfs_options = defaults btrfs_options = defaults
Now that we’ve reviewed the default values supplied in the standard Debian 9 installation of xen-tools, it’s time to have a look at a few real-world examples.
All examples assume that a LVM volume group (“vg0”) has been created for the allocation of DomU swap and root disk partitions. Although xen-tools provides the option of using loopback, LVM, or EVMS for this purpose, it is the author’s opinion that LVM is the easiest to configure and manage. As such, this guide only covers procedures for LVM-based DomU installations.
Example 1 – Basic Configuration with DHCP
In our first example, the xen-create-image command is executed with four added command line values including (1) the new DomU’s hostname, “httpserver”; (2) the LVM volume group from which to provision swap and root disk partitions, “vg0”; (3) instruction that the DomU use DHCP for networking; and, (4) instruction that the DomU use the recommended pygrub bootloader.
# xen-create-image --hostname=httpserver --lvm=vg0 --dhcp --pygrub
Running this command as root creates a new DomU virtual machine with the following notable specifications:
Soft Defaults (per xen-tools.conf)
- an installed Debian “Stretch” OS (since nothing was specified at the command line, xen-tools defaults to the Dom0’s OS),
- two new LVM partitions: 512M swap, and 4G root with an ext4 filesystem, and
- 256M memory (note that the Stretch DomU booted with only 28M used).
- 1 virtual cpu,
- a newly created “httpserver.cfg” file, named according to the hostname passed at the command line, located in the /etc/xen directory, and
- a random root password assigned to the DomU (printed to screen during the xen-create-image configuration process, see below).
Command Line Values
- the DomU internal hostname and associated .cfg file set to “httpserver”,
- the LVM swap (“httpserver-swap”) and root (“httpserver-disk”) partitions created in volume group “vg0”,
- the networking configured through DHCP, and
- the DomU configured to boot with “pygrub”.
Running the above xen-create-image command results in the following configuration information printed to the terminal:
General Information -------------------- Hostname : httpserver Distribution : stretch Mirror : http://httpredir.debian.org/debian Partitions : swap 512M (swap) / 4G (ext4) Image type : full Memory size : 256M Bootloader : pygrub Networking Information ---------------------- IP Address : DHCP [MAC: 00:16:3E:82:CD:5C] Creating swap on /dev/vg0/httpserver-swap Done Creating ext4 filesystem on /dev/vg0/httpserver-disk Done Installation method: debootstrap Done Running hooks Done No role scripts were specified. Skipping Creating Xen configuration file Done No role scripts were specified. Skipping Setting up root password Generating a password for the new guest. All done Logfile produced at: /var/log/xen-tools/httpserver.log Installation Summary --------------------- Hostname : httpserver Distribution : stretch MAC Address : 00:16:3E:82:CD:5C IP Address(es) : dynamic SSH Fingerprint : SHA256:zVjA88b4bvVsj5LTADksxmfB/BcBt1zzuq3+XObI1NI (DSA) SSH Fingerprint : SHA256:cnzgN9k6fh14M5KChmzRU3ifYbeQ53mxAP28h5MFeUA (ECDSA) SSH Fingerprint : SHA256:2KsTrn9WQMiYjkc+fWclaqaQrGGEqnMZ24JyKDM0HYs (ED25519) SSH Fingerprint : SHA256:z5UEpJRCvEuGq8k3INGYEnXsnofqouC+N4nSKxR7DIk (RSA) Root Password : Bjrgt5s5sT5SX3YSMSkcufY
To start the newly created virtual machine, run the following command as root:
# xl create /etc/xen/httpserver.cfg
Example 2 – Basic Configuration with Static Networking
If you are creating a DomU that requires static networking (i.e., DHCP is not provided on your network), configuration options are easily passed at the command line while executing the xen-create-image command.
For instance, if your project requires the same basic DomU as in Example 1, above – but with static networking instead of DHCP – then you can add the following broadcast, gateway, ip, and network options to expand the Example 1 command:
# xen-create-image --hostname=httpserver --lvm=vg0 --pygrub --broadcast=10.0.0.255 --gateway=10.0.0.1 --ip=10.0.0.101 --netmask=255.255.255.0
N.B. Don’t forget to leave out “–dhcp”!
Other Common Options
Listed below are a some additional, commonly-used configuration options that may be passed at the command line or added to your xen-tools.conf file to further customize your DomU instances. Don’t forget to check out the xen-create-image manual page for other configuration options not covered here.
Change DomU Distribution
Selecting a different OS for the new DomU is as simple as adding the “–dist” option and the desired distribution’s version “codename”. To see what codenames are supported by xen-tools, review the listing provided in the /etc/xen-tools/distributions.conf file.
For users who want to tryout Debian 8 “Jessie”, use:
Change DomU Memory Allocation
Use the “–memory” option to override the default 256M memory allocated to newly created DomU. If you have the extra RAM, “–memory=1024M” is a good minimum for most DomU instances.
If your Xen Project Hypervisor setup permits dynamic memory allocation (“memory ballooning”), then consider capping the maximum memory that may be allocated to the DomU. This is implemented with the option “–maxmem”.
Change DomU Swap
The default DomU swap space may be increased or decreased using the “–swap” option. For example, the default 512M of swap may be increased to 1024M with the following code:
If your DomU doesn’t require swap, use the option “–noswap” and the xen-create-image program will only create a root partition (and no swap partition).
Change Root Partition Size
Need a larger or smaller root partition for your DomU? Use the option “–size” to modify the virtual machine’s partition size. A default Debian Stretch server installation only uses about 900M. For a 2G root partition, pass the following option:
Set Root Password at Installation
If you would like to set the root password during the xen-create-image process, use the option “–passwd” and you’ll be prompted to enter the root password while the DomU is being created.
 The preset mirror servers are located in the /etc/xen-tools/mirrors.conf file.