NAME
xen-create-image - Easily create new Xen instances with networking and OpenSSH.
SYNOPSIS
xen-create-image --hostname=<hostname> <further options>
EXAMPLES
xen-create-image --hostname=some-domu --dist=wheezy --lvm=vg0
xen-create-image --hostname=some-domu --dist=precise --dir=/srv/xen
See below for more specific examples: LOOPBACK EXAMPLES, LVM EXAMPLE and EVMS EXAMPLE.
OPTIONS
Help Options:--help Show the help information for this script.--manual Read the manual, and examples, for this script.--(no)verbose (Don't) show more of what xen-create-image iscurrently doing.--dumpconfig Show current configuration.--version Show the version number and exit.Size / General options:--(no)accounts(Don't) copy all non-system accounts to the guestimage--admins Specify that some administrators should be created forthis image, using xen-shell.--(no)boot (Don't) boot the new instance after creating it.--cache=bool Cache .deb files on the host when installing the newguest with the debootstrap tool. Accepted values:"yes" (default) and "no".--cachedir=/path/to/cache/directoryOverride the default .deb cache directory. Defaults to/var/cache/apt/archives/ if it exists (i.e. on Debianand Ubuntu) and /var/cache/xen-tools/archives/ else(i.e. on Fedora and CentOS).--config=fileRead the specified file in addition to the globalconfiguration file.--(no)copyhosts(Don't) copy entries from the dom0's /etc/hosts fileto the guest--copy-cmd NOP: Ignored.--debootstrap-cmd=/path/to/commandSpecify which debootstrap command is used. Defaults todebootstrap if both, debootstrap and cdebootstrap areinstalled. Specifying the path is optional.--disk_device=disknameUse specified device name for virtual devices insteadof the default value "xvda".--extension=extSpecify the suffix to give the Xen configurationfile. (Default value: ".cfg")--(no)force (Don't) force overwriting existing images. This willremove existing images or LVM volumes which matchthose which are liable to be used by the newinvocation.--fs=fs Specify the filesystem type to use for the new guest.Valid choices are 'ext2', 'ext3', 'ext4', 'reiserfs','xfs' or 'btrfs'. (Note: pygrub *DOES NOT* supportxfs)--genpass=1 Generate a random root password (default, set to 0 toturn off)--genpass_len=NOverride the default password length of 8 and generatea random password of length N. Note: this only worksin conjunction with --genpass--hash_method=algorithmOverride the default hashing method of sha256 and usethe provided algorithm. Can be : md5, sha256 or sha512--hooks=1 Specify whether to run hooks after the image is created.--ide Use IDE names for virtual devices (i.e. hda not xvda)--image=str Specify whether to create "sparse" or "full" diskimages. Full images are mandatory when using LVM, sothis setting is ignored in that case.--image-dev=/path/to/deviceSpecify a physical/logical volume for the disk image.--initrd=/path/to/initrdSpecify the initial ramdisk. If an image is specifiedit must exist.--install=1 Specify whether to install the guest system or not.--(no)keep (Don't) keep our images if installation fails. Itmaybe unmounted, though.--keyring=/path/to/keyringSet the path to the keyring debootstrap should use.--kernel=/path/to/kernelSet the path to the kernel to use for domU. If akernel is specified it must exist.--memory=sizeSetup the amount of memory allocated to the newinstance. As suffix recognized size units are "M","MB", "G" and "GB" (case does not matter). If there'sno unit given, megabytes are assumed.--maxmem=sizeSetup the maximum amount of memory that can be allocatedto the new instance. As suffix recognized size units are "M","MB", "G" and "GB" (case does not matter). If there'sno unit given, megabytes are assumed.Required for dynamic memory ballooning.--modules=/path/to/modulesSet the path to the kernel modules to use for domU.If modules are specified they must exist.--nohosts Don't touch /etc/hosts on the dom0.--noswap Do not create a swap partition. When this option isused the system will not have a swap entry added toits /etc/fstab file either.--output=dir Specify the output directory to create the xenconfiguration file within.--partitions=fileUse a specific partition layout configuration file.See /etc/xen-tools/partitions.d/sample-server for anexample partitioning configuration. Not supportedwith the image-dev and swap-dev options. Parametersfs, size, swap and noswap are ignored when using thisoption.--password=passphraseSet the root password for the new guest.Note: This overrides --genpass--(no)passwd (Don't) ask for a root password interactively duringsetup. NOTE: This overrides --genpass --password.--(no)pygrub DomU should (not) be booted using pygrub.--role=role Run the specified role script(s) post-install. Rolescripts are discussed later in this manpage. Can bean absolute path. Otherwise it's relative to the valueof --roledir.--role-args="--arg1 --arg2"Pass the named string literally to any role script.This is useful for site-specific roles.--finalrole=roleSimilar to role scripts. Run the specified rolescript(s) after cfg file creation.--roledir=/path/to/directorySpecify the directory which contains the role scripts.This defaults to /etc/xen-tools/role.d/--scsi Use SCSI names for virtual devices (i.e. sda not xvda)--serial_device=serialnameInstall a getty on the specified serial device insteadof the default device.--size=size Set the size of the primary disk image.--swap=size Set the size of the swap partition.--swap-dev=/path/to/deviceSpecify a physical/logical volume for swap usage.--tar-cmd NOP: Ignored.--dontformat Do not format the devices specified for installation.Useful if you want tighter control over the filesystemcreation. Requires the filesystems to be createdbeforehand.--vcpus=numSet the number of vcpus that the new instance willhave instead of the default value of "1".Installation options:--arch=arch Pass the given architecture to debootstrap, rinse, orrpmstrap when installing the system. This argument isignored for other install methods.--dist=dist Specify the distribution you wish to install.--install-method=methodSpecify the installation method to use. Valid methodsare:* debootstrap* cdebootstrap* rinse* rpmstrap (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/tarballSpecify the source path to use when installing viaa copy or tarball installation.--mirror=url Setup the mirror to use when installing viadebootstrap. (Default value: mirror used in/etc/apt/sources.list or for Debian"http://deb.debian.org/debian/" and for Ubuntu"http://archive.ubuntu.com/ubuntu/")The above mentioned Debian mirror hostnameautomatically tries to choose a more or less closeDebian mirror. See http://deb.debian.org/ fordetails.--apt_proxy=protocol://hostname:port/Specify a proxy to be used by debootstrap, and withinthe guest. Needs the same syntax as APT'sAcquire::http::Proxy. See apt.conf(5).--template=tmplSpecify which template file to use when creating theXen configuration file.Networking options:--bridge=brnameOptionally, set a specific bridge for the newinstance. This can be especially useful when runningmultiple bridges on a dom0.--broadcast=123.456.789.ABCSetup the broadcast address for the new instance.--(no)dhcp The guest will (not) be configured to fetch itsnetworking details via DHCP.--gateway=gw Setup the network gateway for the new instance.--ip=123.456.789.ABCSetup the IP address of the machine, multiple IPs areallowed. When specifying more than one IP the firstone is setup as the "system" IP, and the additionalones are added as aliases.Note that Xen 3.x supports a maximum of three vifstatements per guest. This option conflicts with--dhcp.--mac=AA:BB:CC:DD:EE:FFSpecify the MAC address to use for a given interface.This is only valid for the first IP address specified,or for DHCP usage. (ie. you can add multiple --ipflags, but the specific MAC address will only be usedfor the first interface.)--randommac Creates a random MAC address.--netmask=123.456.789.ABCSetup the netmask for the new instance.--nameserver="123.456.789.ABC 123.456.789.DEF"Setup the nameserver of the machine, multiple spaceseparated nameservers are allowed. If not provided,Dom0's /etc/resolv.conf will be copied to guest.--vifname=vifnameOptionally, set a specific vif name for the newinstance.--vlan=1 OpenvSwitch related, optionally you can specify a vlanwhere the virtual machine has connectivity.Mandatory options:--dir=/path/to/directorySpecify where the output images should go.Subdirectories will be created for each guest.If you do not wish to use loopback images specify--lvm, --evms or --zpool. (These four options aremutually exclusive.)--evms=lvm2/containerSpecify the container to save images within,i.e. '--evms lvm2/mycontainer'. If you do not wish touse EVMS specify --dir, --lvm or --zpool. (These fouroptions are mutually exclusive.)--hostname=host.example.orgSet the hostname of the new guest system. Ideallythis will be fully-qualified since several of the hookscripts will expect to be able to parse a domain nameout of it for various purposes.--lvm=vg Specify the volume group to save images within.If you do not wish to use LVM specify --dir, --evms or--zpool. (These three options are mutually exclusive.)--lvm_thin=thin poolSpecify the thin pool name on which thin LVM volumesare created.This enables thin provisioned LVM volumes. Note thatyou need a LVM version which supports this.--zpool=pool Specify the ZFS pool to save images within. A new ZFSvolume will be created for each guest.If you do not wish to use ZFS specify --dir, --evms or--lvm. (These four options are mutually exclusive.)
NOTES
This script is a wrapper around three distinct external tools whichcomplete various aspects of the new system installation.
- xt-install-image Install a new distribution.
- xt-customize-image Run a collection of hook scripts to customise the freshly installed system.
- xt-create-xen-config Create a Xen configuration file in so that xm/xl can start the new domain.
The result of invoking these three scripts, and some minor glue betweenthem, is a simple means of creating new Xen guest domains.
DESCRIPTION
xen-create-image is a simple script which allows you to create newXen instances easily. The new image will be given two volumes. Thesevolumes will be stored upon the host as either loopback files, orLVM logical volumes:1. An image for the systems root disk.2. An image for the systems swap device.The new virtual installations will be configured with networking,have OpenSSH installed upon it, and have most of its basic filessetup correctly.If you wish you can configure arbitrary partitioning schemes, ratherthan being restricted to just the two standard volumes. For moredetails on this please see the later section in this manual "PARTITIONING".If you wish to install additional packages or do any additionalconfiguration of your new guests, please read the section on "ROLES".
CONFIGURATION
To reduce the length of the command line each of the supported optionsmay be specified inside a configuration file.The global configuration file read for options is:/etc/xen-tools/xen-tools.confThe configuration file may contain comments which begin with thehash '#' 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 sizemaxmem = 512Mb # Memory sizeswap = 128Mb # Swap sizefs = ext3 # use EXT3 filesystemsdist = stable # Default distribution to install.## Kernel options.#kernel = /boot/vmlinuz-`uname -r`initrd = /boot/initrd.img-`uname -r`## Networking options.#gateway = 192.168.1.1broadcast = 192.168.1.255netmask = 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 thefollowing command:xen-create-image --hostname=vm03.my.flat --ip=192.168.1.201This makes use of loopback images stored beneath /home/xen andwill be installed via the debootstrap command.
NETWORKING AUTO-SETUP
We've already seen how the "gateway" and "netmask" options canbe used to specify the networking options of the freshly createdXen guests.One other useful shortcut is the use of an automatic IP address.You can specify '--ip=auto' and the system will choose and usean IP address from those listed in /etc/xen-tools/ips.txt.For example if you wished to have Xen guests automaticallytake an address from the range 192.168.1.100-192.168.1.200 youwould first prepare the system by running this:
rm /etc/xen-tools/ips.txtfor 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 addressfrom 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 takenthen the system will fail.
PARTITIONING
By default all new guests are created with two "volumes", onefor 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 with asan argument to the --partition option.
XEN CONFIGURATION FILE
Once a new image has been created an appropriate configuration filefor Xen will be saved in the directory /etc/xen by default. Howeveryou 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 viathe Text::Template perl module.If you wish to modify the files which are generated please make yourchanges to that input file.Alternatively you can create multiple configuration files andspecify the one to use with the --template option.
LOOPBACK EXAMPLES
The following will create a 2Gb disk image, along with a 128Mbswap file with Debian Stable setup and running via DHCP.xen-create-image --size=2Gb --swap=128Mb --dhcp --dist=stable \--dir=/home/xen --hostname=vm01.my.flatThis next example sets up a host which has the name 'vm02.my.flat' andIP address 192.168.1.200, with the gateway address of 192.168.1.1xen-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.flatThe directory specified for the output will be used to store the volumeswhich are produced. To avoid clutter each host will have its imagesstored beneath the specified directory, named after the hostname.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.imgThe '/domains/' subdirectory will be created if necessary.
LVM EXAMPLE
If you wish to use an LVM volume group instead of a pair of loopbackimages as shown above you can instead use the --lvm argument tospecify one.xen-create-image --size=2Gb --swap=128Mb --dhcp \--lvm=myvolumegroup --hostname=vm01.my.flatThe given volume group will have two new logical volumes created within it:${hostname}-swap${hostname}-diskThe disk image may be mounted, as you would expect, with the followingcommand:mkdir -p /mnt/foomount /dev/myvolumegroup/vm01.my.flat-disk /mnt/foo
EVMS EXAMPLE
If you wish to use an EVMS storage container instead of a pair of loopbackimages as shown above you can instead use the --evms argument tospecify one. The below example assumes an lvm2 container.xen-create-image --size=2Gb --swap=128Mb --dhcp \--evms=lvm2/myvolumegroup --hostname=vm01.my.flatThe given storage container will have two new EVMS volumes created within it:${hostname}-swap${hostname}-diskThe disk image may be mounted, as you would expect, with the followingcommand:mkdir -p /mnt/foomount /dev/evms/vm01.my.flat-disk /mnt/foo
INSTALLATION METHODS
The new guest images may be installed in several different ways:1. Using the [c]debootstrap command, which must be installed and present.2. Using the rpmstrap command, which must be installed and present.3. using the rinse command, which must be installed and present.4. By copying an existing installation.5. By untarring a file containing a previous installation.These different methods can be selected by either the command linearguments, or settings in the configuration file. Only one installationmethod may be specified at a time; they are mutually-exclusive.
INSTALLATION SPEEDUPS
After performing your first installation you can customize it, oruse it untouched, as a new installation source. By doing this you'llachieve a significant speedup, even above using the debootstrap cachingsupport.There are two different ways you can use the initial image as sourcefor a new image:1. By tarring it up and using the tar-file as an installation source.2. 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 installwith 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.tarThe advantage of the tarfile approach is that you'll not need tokeep a disk image mounted if you were to use the --copy argumentto 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 isa fair amount of network overhead.To minimize this the .deb files which are downloaded into thenew 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 newimage - before the debootstrap process runs - this should help avoidexpensive network reading.If you wish to clean the host's apt cache (/var/cache/apt/archivees)you may do so with apt-get, namely:apt-get cleanIf you set your cache directory to anything else, simply rm thecontents of the directory.
ROLES
Currently there are some roles scripts included which work forthe Debian and Ubuntu distributions only. They are includedprimarily as examples of the kind of things you could accomplish.The supplied scripts are:
- builder Setup the new virtual images with commonly used packages for rebuilding Debian packages from their source.
- cfengine Install cfengine2 on 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 small sed files 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.sedthis 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 GDM
- minimal 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/run and /var/lock as 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 tocreate a file in /etc/xen-tools/role.d, and then specify thename of that file with "--role=filename". Additionally youmay pass options to your role-script with the --role-argsflag.For example the script /etc/xen-tools/role.d/gdm would be usedby executing with "--role=gdm".Role scripts are invoked with the directory containing theinstalled system as their first argument, and anything passedas 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 theirnames with commas.
THE SKELETON DIRECTORY
Any files present in the directory /etc/xen-tools/skel will be copiedacross to each new guest image. The role of this directory is analogousto the /etc/skel directory.A typical use for this would be to copy a public key across to eachnew system. You could do this by running:
mkdir -p /etc/xen-tools/skel/root/.sshchmod -R 700 /etc/xen-tools/skel/rootcp /root/.ssh/id_rsa.pub /etc/xen-tools/skel/root/.ssh/authorized_keys2chmod 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.