Creating disk templates

From ISPWiki

Jump to: navigation, search


Creating disk templates for FreeBSD

Install the operating system's source that is located in /usr/src

Create a directory to locate the disk template, such as mkdir -p /vs/tsrc/FreeBSD-8-minimal

Set up the world and install it to the newly created directory

cd /usr/src/
make buildworld
make DESTDIR=/vs/tsrc/FreeBSD-8-minimal installworld
make DESTDIR=/vs/tsrc/FreeBSD-8-minimal distribution
cp /etc/resolv.conf /vs/tsrc/FreeBSD-8-minimal/etc/resolv.conf

We have a template of the default system. Edit the configs, add packages, etc. We recommend entering the template and perform all the operations as on a common server. Run the commands below:

mount -t devfs devfs /vs/tsrc/FreeBSD-8-minimal/dev
chroot /vs/tsrc/FreeBSD-8-minimal /bin/csh

When in the template, you may edit whatever you need, set up ports, packages, etc.

Create the file to initialize the virtual server:


it will run while creating the virtual server

example of the .vpsinstall file

echo "${IP}	${HOST}" >> /etc/hosts
echo "hostname=\"$HOST\"" >> /etc/rc.conf

Normally, it is used to customize configs by a certain domain name and IP-addresses, generate SSL-certificates and passwords, initialize databases, etc.

After you have created the template, the exit program will move you from the template.

Create the config with a list of files that are not to be included to the template, such as .history

cd /vs/tsrc/FreeBSD-8-minimal
echo "root/.history" > .uptmp.exclude
echo "tmp/" >> .uptmp.exclude

Run the template archive utility:

/usr/local/ispmgr/sbin/uptmp -C FreeBSD-8-minimal /vs/tsrc/FreeBSD-8-minimal

The current directory contains the following files:

  • VERSION - template name and current version
  • .uptmp - template files (DO NOT DELETE THIS LIST, as it will be used for update)
  • install.tgz - archive from which you can unpack the template

The install.tgz file can be uploaded to your server (ftp or http) to be installed on VDSmanager

scp install.tgz install.tgz.md5
rm install.tgz install.tgz.md5

Go to VDSmanager -> Disk templates (VDSmanager) -> to install the newly created template.

Updating disk templates for FreeBSD

If you want to update something in the disk templates, enter the template and make necessary changes:

mount -t devfs devfs /vs/tsrc/FreeBSD-8-minimal/dev
chroot /vs/tsrc/FreeBSD-8-minimal /bin/csh

If you need to restart the services after update or perform other actions, you need to add thw script


It will be executed on each running virtual server

Then, run the utility to enable update of the template

/usr/local/ispmgr/sbin/uptmp -c /vs/tsrc/FreeBSD-8-minimal

and upload the files to your server

cd /vs/tsrc/FreeBSD-8-minimal
scp update-2.tgz update-2.tgz.md5
rm update-2.tgz update-2.tgz.md5

where 2 is the version' number; it will increase continuously.

Creating XEN disk templates

Actually, a XEN virtual machine is a common server, so the installation should be performed in a usual way (in the HVM mode you may use a standard installer). If a virtual server must run in the VM mode, you need to install special packages, such as udev. The kernel is not required. It should be located near the disk template on dom0 and support xen. You may use a single kernel (two: i386 and amd64) for all the virtual machines. You will hardly find a person who may need separate versions.

FreeBSD in the VM mode is currently not available.

Debian (using debootstrap)

We have the unnconfigured system (i.e. only required files will be unpacked).

mount -o loop <image path> /mnt/debian
/usr/sbin/debootstrap --arch ARCH lenny /mnt/debinst
mount -t proc /proc /mnt/debinst
LANG=C chroot /mnt/debinst /bin/bash
cd /dev
MAKEDEV generic

Edit fstab, it will look like this:

/dev/hda         /             ext3    defaults                 0    1
/dev/hdb         none          swap    sw                       0    0
proc             /proc         proc    defaults                 0    0

Configure the network. Specify hostname in /etc/hostname. Specify hostname in /etc/hosts. Edit /etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

Configure apt. Edit /etc/apt/sources.list:

deb-src lenny main

deb lenny/updates main
deb-src lenny/updates main

Set the root password. Set openssh-server (by default it is not present) + udev (sshd will not work without it).

That's all. Some minor settings are left:

  • Exclude unnecessary packages (e.g. dhcp-client).
  • If you want to have a non-password console, open /etc/inittab and change /sbin/getty into /bin/bash:
1:2345:respawn:/sbin/getty 38400 tty1

Connect to the virtual machine using the command below:

xm console <Virtual server name>

To disconnect from the console, press Ctrl+[

Ubuntu (using debootstrap)

Install debootstrap scripts for Ubuntu. Example for Debian:


# add jaunty repository
cat <<EOF> /etc/apt/sources.list.d/jaunty.list
deb jaunty main restricted
deb-src jaunty main restricted

# update
apt-get update
# install debootstrap
apt-get install -y --force-yes debootstrap
# remove repository
rm /etc/apt/sources.list.d/jaunty.list
apt-get update

Follow the same installation procedures as for Debian.

CentOS, Fedora (using rinse)

debootstrap can install only Debian (to be more exact, the distributions that run via apt). If you want to install something that runs via yum, such as Centos or Fedora, you may use rinse.

apt-get install rinse

Still, there are some problems. Some packages for Centos 5 are not present on the package list. That's why you should add into the file /etc/rinse/centos-5.packages:


A flesh installation of the operating system is required (use the same installation procedure as for Debian)

mount -o loop <image path> /mnt
rinse --arch i386 --distribution centos-5 --directory /mnt
mount -t proc /proc /mnt/proc
LANG=C chroot /mnt /bin/bash
cd /dev
MAKEDEV generic

Edit fstab, it should look like this:

/dev/hda         /             ext3    defaults                 0    1
/dev/hdb         none          swap    sw                       0    0
proc             /proc         proc    defaults                 0    0
none             /dev/pts      devpts  gid=5,mode=620           0    0

Configure the network. Specify hostname in /etc/hosts. Edit /etc/sysconfig/network-scripts/ifcfg-eth0:




If Fedora7 is used, you need to provide passwd.

Set the root password and openssh-server (by default it is not present), add (uncomment) two lines into /etc/ssh/sshd_config:

PermitRootLogin yes
PasswordAuthentication yes

Using xen-tools

To facilitate installation, you may use a xen-tools package (if xen was created manually, some errors may occur, as it will install xen from the repository through dependences). It allows to create the templates easily. For example:

xen-create-image –hostname=hobbiton –dist=etch \
    –ip= –netmask= –gateway= \
    –lvm=lvmxen –debootstrap
 xm create -c hobbiton.cfg

Setting manually

Sometimes it is rather difficult to create a template for automatic installation of an operating system, or detailed configuration may be required, such as partition of the hard disk in a special way or installation of Windows. To do that, you can create a template to install the operating system manually. Use the setup disk image of your operating image.

For example, you have the image for Windows 7 installation (/xen/iso/Windows7.iso).

  1. Add a /xen/template/Windows7 directory.
  2. Add VERSION file there (its content will be displayed as a version on the list of VDSmanager templates)
  3. Add the XEN config template (a file config)
kernel = "/usr/lib64/xen/boot/hvmloader"
name = "__NAME__"
vif = [ 'type=ioemu, ip=__IP__' ]
disk = [ '__TYPE__:__DISK__,hda,w', 'file:/xen/iso/Windows7.iso,hdb:cdrom,r' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
device_model = '/usr/lib64/xen/bin/qemu-dm'

Add a VPS using the Windows 7 template. Once you access it through VNC, install Windows on your VPS.

Scripts called by VDSmanager

setpass <ip> '<mountdir>' < <password>
setname <ip> '<mountdir>' '<name>'
setip <ip> '<network>' '<netmask>' '<gateway>' '<mountdir>'
setsize <path> <size>
getused '<name>'

ip - main IP-address of the server (if the address is not provided in the config, you may specify the VPS name (for example, if working with a virtual server that was not created through VDSmanager)).

mountdir - directory in which the private disk is mounted

network, netmask, gateway - select from the VDSmanager config depending on the IP-address

path - path to the private disk (file or the LVM resource)

size - size in MB

name - host name

password - plaintext password. You may use the utility /usr/local/ispmgr/sbin/crypt for encryption

The directory may also have the following files:

VERSION - template version

image - .tgz archive that contains VPS files; in this case ext3 partition will be created, in which all the files from this archive will be unpacked. If .tgz is not used, it is considered a binary file from VPS.

config - configuration template for the VPS. You can use the macros:

  • __TYPE__ - disk type (for LVM - phy, for files - file)
  • __DISK__ - path to the private disk
  • __IP__ - server IP-address + bridge interface name, if necessary, such as, bridge=eth0
  • __NAME__ - server name
  • __ID__ - VNC id
  • __PASSWD__ - password (plaintext)
  • __TEMPL__ - path to the directory with the template

+ any files that are required for configuring or running the VPS.

The /sbin/xenclient application should be present in the template to check the used disk space.

Creating openVZ disk templates

Following the link to find the templates that can be used to create a new template:

You can create a template via debootstrap. Note, the bugs that may occur might have been already fixed in

  • Download the template, create the directory where it will be locates and unpack the template.

Run the commands with root privileges.

mkdir new_template
tar -xvzpf fedora-13-x86.tar.gz -C new_template
  • Mount procfs
mount -t proc none new_template/proc
  • Create chroot
chroot new_template
  • install the packages and configure the system.
  • to perform any actions while installing the VPS, you need to specify them in the script that will be removed after execution.

For Centos:

  1. Create a shell script/etc/rc3.d/S50vdsinstall
    echo '#!/bin/sh' > /etc/rc3.d/S50vdsinstall
    echo '' >> /etc/rc3.d/S50vdsinstall
    chmod +x /etc/rc3.d/S50vdsinstall
  2. Specify the required actions
  3. At the end of the file specify the command for its deletion:
    echo 'rm -f /etc/rc3.d/S50vdsinstall' >> /etc/rc3.d/S50vdsinstall
    The script will run while starting the system and will be removed after execution.
  • With the template created, exit chroot
  • Unmount proc and kill all the processes that use the files in new_template
fuser -k new_template/
umount new_template/proc
  • Archive the template
tar -czpf fedora-13-my-x86.tar.gz -C net_template .

The file name must start with the distribution name. As openVZ configures the network, hostname, etc. differently depending on the name, the fedora-13-my-x86.tar.gz file on the server is located in the template directory. Normally, this is /vz/template/cache/

Was this helpful? Yes | No
Personal tools