XEN-CREATE-IMAGE(8)
π xen-create-image(8) π
okay bestie, welcome to the manual page for xen-create-image, straight outta the Perl Programmers Reference Guide. She's a section 8 (system admin) girlie and she's here to make your life so much easier. π«Ά
β¨ NAME β¨
xen-create-image β literally the easiest way to spin up brand-new Xen instances, networking and OpenSSH included, no cap. π
πΈ SYNOPSIS πΈ
xen-create-image --hostname=<hostname> <further options>
π¦ EXAMPLES π¦
Obsessed with how simple this is. Look:
xen-create-image --hostname=some-domu --dist=wheezy --lvm=vg0
xen-create-image --hostname=some-domu --dist=precise --dir=/srv/xen
And if you want the extra detailed tea, scroll down to LOOPBACK EXAMPLES, LVM EXAMPLE and EVMS EXAMPLE below. iykyk. π
π OPTIONS π
π Help Options
--helpβ shows you the help info for this script. your lil emergency contact. π--manualβ reads you the manual and the examples for this script. she's thorough.--(no)verboseβ (don't) spill more about whatxen-create-imageis doing right now. main character narration, honestly.--dumpconfigβ dumps the current configuration so you can see what's what. π--versionβ shows the version number and then dips. bye bestie. π
π Size / General options
--(no)accountsβ (don't) copy all the non-system accounts over to the guest image. bringing the whole friend group.--adminsβ says that some administrators should be created for this image, usingxen-shell.--(no)bootβ (don't) boot the new instance right after creating it. no pressure, she can wait. π΄--cache=boolβ caches.debfiles on the host when installing the new guest with thedebootstraptool. accepted values:"yes"(the default, periodt) and"no".--cachedir=/path/to/cache/directoryβ overrides the default.debcache directory. it defaults to/var/cache/apt/archives/if that exists (aka on Debian and Ubuntu) and/var/cache/xen-tools/archives/otherwise (aka on Fedora and CentOS).--config=fileβ reads the file you name in addition to the global configuration file. the more the merrier. π--(no)copyhostsβ (don't) copy the entries from the dom0's/etc/hostsfile over to the guest.--copy-cmdβ NOP: ignored. she's just standing there. π--debootstrap-cmd=/path/to/commandβ picks which debootstrap command gets used. defaults todebootstrapif bothdebootstrapandcdebootstrapare installed. specifying the path is optional.--disk_device=disknameβ uses the device name you give for virtual devices instead of the default value"xvda".--extension=extβ the suffix to give the Xen configuration file. (default value:".cfg")--(no)forceβ (don't) force overwriting existing images. β οΈ heads up: this will remove existing images or LVM volumes which match those that are liable to be used by the new invocation. so like, be sure, bestie.--fs=fsβ the filesystem type for the new guest. valid choices are'ext2','ext3','ext4','reiserfs','xfs'or'btrfs'. (note:pygrubDOES NOT supportxfs) π¨--genpass=1β generates a random root password (default; set it to0to turn it off).--genpass_len=Nβ overrides the default password length of8and generates a random password of length N. note: this only works in conjunction with--genpass.--hash_method=algorithmβ overrides the default hashing method ofsha256and uses the algorithm you provide. can be:md5,sha256orsha512.--hooks=1β says whether to run hooks after the image is created.--ideβ uses IDE names for virtual devices (sohda, notxvda). vintage vibe. π--image=strβ whether to create"sparse"or"full"disk images. full images are mandatory when using LVM, so this setting just gets ignored in that case.--image-dev=/path/to/deviceβ a physical/logical volume for the disk image.--initrd=/path/to/initrdβ the initial ramdisk. if an image is specified it must exist, fr fr.--install=1β says whether to install the guest system or not.--(no)keepβ (don't) keep our images if installation fails. it maybe is unmounted, though. π--keyring=/path/to/keyringβ sets the path to the keyringdebootstrapshould use.--kernel=/path/to/kernelβ sets the path to the kernel to use for domU. if a kernel is specified it must exist.--memory=sizeβ sets the amount of memory allocated to the new instance. recognized size unit suffixes are"M","MB","G"and"GB"(case does not matter). if there's no unit given, megabytes are assumed.--maxmem=sizeβ sets the maximum amount of memory that can be allocated to the new instance. recognized size unit suffixes are"M","MB","G"and"GB"(case does not matter). if there's no unit given, megabytes are assumed. required for dynamic memory ballooning. π--modules=/path/to/modulesβ sets the path to the kernel modules to use for domU. if modules are specified they must exist.--nohostsβ don't touch/etc/hostson the dom0. hands off. π--noswapβ do not create a swap partition. when this option is used the system will not have a swap entry added to its/etc/fstabfile either.--output=dirβ the output directory to create the xen configuration file within.--partitions=fileβ use a specific partition layout configuration file. see/etc/xen-tools/partitions.d/sample-serverfor an example partitioning configuration. β οΈ not supported with theimage-devandswap-devoptions. the parametersfs,size,swapandnoswapare ignored when using this option.--password=passphraseβ sets the root password for the new guest. note: this overrides--genpass.--(no)passwdβ (don't) ask for a root password interactively during setup. NOTE: this overrides--genpass --password. so like, pick your fighter. π--(no)pygrubβ domU should (not) be booted usingpygrub.--role=roleβ runs the specified role script(s) post-install. role scripts are discussed later in this manpage. can be an absolute path. otherwise it's relative to the value of--roledir.--role-args="--arg1 --arg2"β passes the named string literally to any role script. this is useful for site-specific roles.--finalrole=roleβ similar to role scripts. runs the specified role script(s) after cfg file creation.--roledir=/path/to/directoryβ the directory which contains the role scripts. this defaults to/etc/xen-tools/role.d/.--scsiβ uses SCSI names for virtual devices (sosda, notxvda).--serial_device=serialnameβ installs agettyon the specified serial device instead of the default device.--size=sizeβ sets the size of the primary disk image.--swap=sizeβ sets the size of the swap partition.--swap-dev=/path/to/deviceβ a physical/logical volume for swap usage.--tar-cmdβ NOP: ignored. she said nothing, she knows nothing. π--dontformatβ do not format the devices specified for installation. useful if you want tighter control over the filesystem creation. requires the filesystems to be created beforehand.--vcpus=numβ sets the number of vcpus that the new instance will have, instead of the default value of"1".
π§ Installation options
--arch=archβ passes the given architecture todebootstrap,rinse, orrpmstrapwhen installing the system. this argument is ignored for other install methods.--dist=distβ the distribution you wish to install. π--install-method=methodβ the installation method to use. valid methods are:debootstrapcdebootstraprinserpmstrap(deprecated)tar(needs--install-source=tarball.tar)copy(needs--install-source=/path/to/copy/from)
(default value for Debian and Ubuntu: debootstrap)
--install-source=/path/to/tarballβ the source path to use when installing via a copy or tarball installation.--mirror=urlβ sets up the mirror to use when installing viadebootstrap. (default value: mirror used in/etc/apt/sources.listor, for Debian,http://deb.debian.org/debian/and for Ubuntu,http://archive.ubuntu.com/ubuntu/)
the above mentioned Debian mirror hostname automatically tries to choose a more or less close Debian mirror. see http://deb.debian.org/ for details.
--apt_proxy=protocol://hostname:port/β a proxy to be used bydebootstrap, and within the guest. needs the same syntax as APT'sAcquire::http::Proxy. seeapt.conf(5).--template=tmplβ which template file to use when creating the Xen configuration file.
π Networking options
--bridge=brnameβ optionally, set a specific bridge for the new instance. this can be especially useful when running multiple bridges on a dom0.--broadcast=123.456.789.ABCβ sets up the broadcast address for the new instance.--(no)dhcpβ the guest will (not) be configured to fetch its networking details via DHCP.--gateway=gwβ sets up the network gateway for the new instance.--ip=123.456.789.ABCβ sets up the IP address of the machine; multiple IPs are allowed. when specifying more than one IP, the first one is set up as the"system"IP, and the additional ones are added as aliases.
β οΈ note that Xen 3.x supports a maximum of threevifstatements per guest. this option conflicts with--dhcp.
--mac=AA:BB:CC:DD:EE:FFβ tells it which MAC address to slap on a given interface. Heads up tho: this only works for the first IP address you specify, or for DHCP usage. (Like, you can add multiple--ipflags, but the specific MAC address only gets used for the first interface. iykyk. π )--randommacβ literally just makes a random MAC address for you. chaos but cute.--netmask=123.456.789.ABCβ sets up the netmask for the new instance.--nameserver="123.456.789.ABC 123.456.789.DEF"β sets up the nameserver of the machine. You can list multiple ones, space separated, no biggie. β¨ If you don't provide this, Dom0's/etc/resolv.confgets copied over to the guest. so it inherits the vibe.--vifname=vifnameβ optionally sets a specific vif name for the new instance.--vlan=1β this one's OpenvSwitch related π«Ά and optionally lets you specify a vlan where the virtual machine has connectivity.
β¨ Mandatory options β¨
these ones? not optional bestie. you need them.
--dir=/path/to/directoryβ tells it where the output images should go. Subdirectories get created for each guest, one per hostname. If you don't wanna use loopback images, go for--lvm,--evmsor--zpoolinstead. (These four options are mutually exclusive, so pick ONE. π)--evms=lvm2/containerβ specifies the container to save images within, like--evms lvm2/mycontainer. If you don't wanna use EVMS, use--dir,--lvmor--zpoolinstead. (These four options are mutually exclusive.)--hostname=host.example.orgβ sets the hostname of the new guest system. Ideally this should be fully-qualified because several of the hook scripts will expect to be able to parse a domain name out of it for various purposes. so like, give it the whole thing, not just the nickname. π--lvm=vgβ specifies the volume group to save images within. If you don't wanna use LVM, use--dir,--evmsor--zpoolinstead. (These three options are mutually exclusive.)--lvm_thin=thin poolβ specifies the thin pool name on which thin LVM volumes get created. This enables thin provisioned LVM volumes. Fair warning: you need a LVM version that actually supports this, so check first fr fr.--zpool=poolβ specifies the ZFS pool to save images within. A brand new ZFS volume gets created for each guest. If you don't wanna use ZFS, use--dir,--evmsor--lvminstead. (These four options are mutually exclusive.)
πΈ NOTES πΈ
This script is basically a wrapper around three distinct external tools that each handle different aspects of the new system installation. the holy trinity π
xt-install-imageβ installs a new distribution.xt-customize-imageβ runs a collection of hook scripts to customise the freshly installed system.xt-create-xen-configβ creates a Xen configuration file so thatxm/xlcan start the new domain.
The result of invoking these three scripts, plus some minor glue between them, is a simple means of creating new Xen guest domains. iconic behaviour honestly.
π¦ DESCRIPTION π¦
xen-create-image is a simple script that lets you create new Xen instances easily. The new image gets given two volumes, and those volumes are stored upon the host as either loopback files, or LVM logical volumes:
- An image for the system's root disk.
- An image for the system's swap device.
The new virtual installations will be configured with networking, have OpenSSH installed upon it, and have most of its basic files setup correctly. ready to go, no cap.
If you wish you can configure arbitrary partitioning schemes, rather than being restricted to just the two standard volumes. For more details on this please see the later section in this manual "PARTITIONING".
If you wish to install additional packages or do any additional configuration of your new guests, please read the section on "ROLES". π
π CONFIGURATION π
To reduce the length of the command line, each of the supported options may be specified inside a configuration file. because typing out 40 flags is giving carpal tunnel π
The global configuration file read for options is:
/etc/xen-tools/xen-tools.conf
The configuration file may contain comments which begin with the hash # character. Otherwise the format is key = value.
A sample configuration file would look like this:
#
# Output directory. Images are stored beneath this directory, one
# subdirectory per hostname.
#
dir = /home/xen
#
# LVM users should disable the 'dir' setting above, and instead
# specify the name of the volume group to use.
#
# lvm = myvolume
#
# EVMS users should disable the dir setting above and instead specify
# a container. For example, if you have an lvm2 container named box,
# put lvm2/box. This is how it is named in the evms interface.
#
# Warning... this has not been tested with anything but lvm2 but should
# be generalizable.
#
# evms= lvm2/myvolume
#
# Disk and Sizing options.
#
size = 2Gb # Disk image size.
image = full # Allocate the full disk size immediately.
memory = 128Mb # Memory size
maxmem = 512Mb # Memory size
swap = 128Mb # Swap size
fs = ext3 # use EXT3 filesystems
dist = stable # Default distribution to install.
#
# Kernel options.
#
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
#
# Networking options.
#
gateway = 192.168.1.1
broadcast = 192.168.1.255
netmask = 255.255.255.0
#
# Installation method:
# One of "copy", "debootstrap", "cdebootstrap", "rinse", "rpmstrap", or "tar".
#
install-method = debootstrap
Using this configuration file, a new image may be created with the following command:
xen-create-image --hostname=vm03.my.flat --ip=192.168.1.201
This makes use of loopback images stored beneath /home/xen and will be installed via the debootstrap command. so easy it's lowkey unfair. β¨
π NETWORKING AUTO-SETUP π
We've already seen how the "gateway" and "netmask" options can be used to specify the networking options of the freshly created Xen guests.
One other useful shortcut is the use of an automatic IP address. You can specify --ip=auto and the system will choose and use an IP address from those listed in /etc/xen-tools/ips.txt. autopilot mode activated π¦
For example, if you wished to have Xen guests automatically take an address from the range 192.168.1.100-192.168.1.200 you would first prepare the system by running this:
rm /etc/xen-tools/ips.txt
for i in $(seq 100 200) ; do echo 192.168.1.$i >> /etc/xen-tools/ips.txt ; done
Now you can create a guest with the command:
xen-create-image --ip=auto --hostname=blah [--dist=...]
The first time this ran, the machine would receive an IP address from the pool which we've created. This IP would be marked as used, and would no longer be available. If all the IP addresses are taken then the system will fail. π so like, keep an eye on that pool bestie.
π PARTITIONING π
By default, all new guests are created with two "volumes", one for the root filesystem and one for the new system's swap.
If you wish you may specify an alternative partitioning scheme. Simply create a file inside the directory /etc/xen-tools/partitions.d/ specifying your partition layout. (Use the existing file sample-server as a template.)
Now when you create a new image, specify the name of this file as an argument to the --partition option. π
π XEN CONFIGURATION FILE π
Once a new image has been created, an appropriate configuration file for Xen will be saved in the directory /etc/xen by default. However, you may change the output directory with the --output flag.
The configuration file is built up using the template file /etc/xen-tools/xm.tmpl β which is a file processed via the Text::Template perl module. perl module moment, periodt.
If you wish to modify the files which are generated, please make your changes to that input file.
Alternatively, you can create multiple configuration files and specify the one to use with the --template option. β¨
π«Ά LOOPBACK EXAMPLES π«Ά
The following will create a 2Gb disk image, along with a 128Mb swap file, with Debian Stable setup and running via DHCP. a lil baby vm, precious.
xen-create-image --size=2Gb --swap=128Mb --dhcp --dist=stable \
--dir=/home/xen --hostname=vm01.my.flat
This next example sets up a host which has the name vm02.my.flat and IP address 192.168.1.200, with the gateway address of 192.168.1.1:
xen-create-image --size=2Gb --swap=128Mb \
--ip=192.168.1.200 \
--netmask=255.255.255.0
--gateway=192.168.1.1 \
--nameserver=192.168.1.1 \
--dir=/home/xen --hostname=vm02.my.flat
The directory specified for the output will be used to store the volumes which are produced. To avoid clutter, each host will have its images stored beneath the specified directory, named after the hostname. organized queen energy π
For example, the images created above will be stored as:
$dir/domains/vm01.my.flat/
$dir/domains/vm01.my.flat/disk.img
$dir/domains/vm01.my.flat/swap.img
$dir/domains/vm02.my.flat/
$dir/domains/vm02.my.flat/disk.img
$dir/domains/vm02.my.flat/swap.img
The /domains/ subdirectory will be created if necessary.
π LVM EXAMPLE π
If you wish to use an LVM volume group instead of a pair of loopback images as shown above, you can instead use the --lvm argument to specify one.
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat
The given volume group will have two new logical volumes created within it:
${hostname}-swap
${hostname}-disk
The disk image may be mounted, as you would expect, with the following command:
mkdir -p /mnt/foo
mount /dev/myvolumegroup/vm01.my.flat-disk /mnt/foo
π EVMS EXAMPLE π
If you wish to use an EVMS storage container instead of a pair of loopback images as shown above, you can instead use the --evms argument to specify one. The below example assumes an lvm2 container.
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--evms=lvm2/myvolumegroup --hostname=vm01.my.flat
The given storage container will have two new EVMS volumes created within it:
${hostname}-swap
${hostname}-disk
The disk image may be mounted, as you would expect, with the following command:
mkdir -p /mnt/foo
mount /dev/evms/vm01.my.flat-disk /mnt/foo
πΎ INSTALLATION METHODS πΎ
okay so bestie, your new guest images can be installed in a few different ways, and it's giving choose-your-own-adventure:
- Using the
[c]debootstrapcommand, which must be installed and present. - Using the
rpmstrapcommand, which must be installed and present. - using the
rinsecommand, which must be installed and present. - By copying an existing installation.
- By untarring a file containing a previous installation.
These different methods can be selected by either the command line arguments, or settings in the configuration file. Only one installation method may be specified at a time; they are mutually-exclusive. no mixing, babe.
π INSTALLATION SPEEDUPS π
After performing your first installation you can customize it, or use it untouched, as a new installation source. By doing this you'll achieve a significant speedup, even above using the debootstrap caching support. it's giving speedrun strats.
There are two different ways you can use the initial image as source for a new image:
- By tarring it up and using the tar-file as an installation source.
- By mounting the disk image of the first system and doing a literal copy.
Tarring up a pristine, or customised, image will allow you to install with a command such as:
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat \
--install-method=tar --install-source=/path/to/tar.file.tar
The advantage of the tarfile approach is that you'll not need to keep a disk image mounted if you were to use the --copy argument to create a new image using the old one as source:
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat \
--install-method=copy --install-source=/path/to/copy/from
π¦ DEBOOTSTRAP CACHING π¦
When installing new systems with the debootstrap tool there is a fair amount of network overhead. ugh, the bandwidth bills.
To minimize this the .deb files which are downloaded into the new instance are cached by default upon the host, in the directory /var/cache/apt/archives or, if this does not exist, in /var/cache/xen-tools/archives. This can be overridden with the --cache-dir command-line and configuration option.
This feature can be disabled with the command line flag --cache=no, or by the matching setting in the configuration file.
When a new image is created these packages are copied into the new image - before the debootstrap process runs - this should help avoid expensive network reading. iconic behavior, honestly.
If you wish to clean the host's apt cache (/var/cache/apt/archivees) you may do so with apt-get, namely:
apt-get clean
If you set your cache directory to anything else, simply rm the contents of the directory.
π ROLES π
Currently there are some roles scripts included which work for the Debian and Ubuntu distributions only. They are included primarily as examples of the kind of things you could accomplish. cute little starter pack energy.
The supplied scripts are:
builderβ Setup the new virtual images with commonly used packages for rebuilding Debian packages from their source.cfengineβ Installcfengine2on the virtual image and copy the cfengine configuration from Dom0.editorβ Allows generalised editing of files for guests. This script works via a skeleton directory containing smallsedfiles which will contain edits to be applied to an arbitrary tree of files upon the new domU.
For example if we have the following sed file:
/etc/xen-tools/sed.d/etc/ssh/sshd_config.sed
this will be applied to /etc/ssh/sshd_config upon the new guest if it exists. If the file encoded in the name doesn't exist then it will be ignored.
gdmβ Install an X11 server, using VNC and GDMminimalβ Customise the generated images to remove some packages.puppetβ Install puppet on the virtual image and copy the cfengine configuration from Dom0.tmpfsβ Sets up/tmp,/var/runand/var/lockas tmpfs in the DomU.udevβ Install udev in the DomU. Most distributions install udev by default nowadays, so this role is probably only interesting for legacy systems which need udev anyway.xdmβ Install an X11 server, using VNC and XDM
If you'd like to include your own role scripts you'll need to create a file in /etc/xen-tools/role.d, and then specify the name of that file with --role=filename. Additionally you may pass options to your role-script with the --role-args flag.
For example the script /etc/xen-tools/role.d/gdm would be used by executing with --role=gdm.
Role scripts are invoked with the directory containing the installed system as their first argument, and anything passed as a role-arg will be passed along as additional arguments.
NOTE: Role scripts are invoked before the config file generation. If you need access to the config file from within your role, use --finalrole.
NOTE: Multiple role scripts may be invoked if you separate their names with commas.
π THE SKELETON DIRECTORY π
Any files present in the directory /etc/xen-tools/skel will be copied across to each new guest image. The role of this directory is analogous to the /etc/skel directory. it's giving template magic.
A typical use for this would be to copy a public key across to each new system. You could do this by running:
mkdir -p /etc/xen-tools/skel/root/.ssh
chmod -R 700 /etc/xen-tools/skel/root
cp /root/.ssh/id_rsa.pub /etc/xen-tools/skel/root/.ssh/authorized_keys2
chmod 644 /etc/xen-tools/skel/root/.ssh/authorized_keys2
π AUTHORS π
- Steve Kemp,
https://steve.fi/ - Axel Beckert,
https://axel.beckert.ch/ - Dmitry Nedospasov,
http://www.nedos.net/ - Stephane Jourdois
π LICENSE π
Copyright (c) 2005-2009 by Steve Kemp, (c) 2010-2013 by The Xen-Tools Development Team. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The LICENSE file contains the full text of the license.
and that's the tea, bestie π
this was XEN-CREATE-IMAGE(8) from version 4.9.2, dated 2023-02-06. now go make some iconic VMs, mwah πβ¨
π¦ where this page comes from
- debian bookworm: xen-tools 4.9.2-1
- ubuntu noble: xen-tools 4.9.2-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms