Creating disk templates for KVM (VDSmanager)

From ISPWiki

Jump to: navigation, search


Creating a template for KVM (Linux-based system)

The peculiarity of this template is that the file system can be saved as archive by creating a hard drive image while creating the guest machine. The template will consist of a boot disk (with /boot and the loader) and file archive.

Preliminary stage

Create a directory on the server

mkdir /kvm/is

download the installation image:


Create a VPS called "debian.en" with "empty" template

go to /kvm/machines/debian.en

Once the guest system has been created, hard drive images will locate in the /kvm/machines/your_VPS directory. If LVM is set up and the VolumeGroupName parameter is specified in VDSmanager, the images will be created as LVM volumes.

Following is the example with the LVM set up in the system. If not, use the -j loop option to mount images from files:

Create the boot.img file in the /kvm/machines/ directory (it will be the boot disk)

kvm-img create boot.img 100M

edit the filesystem file:





Installing the operating system

Start your VPS through VDSmanager

Access it through VNC-viewer. An Address is your server address, a monitor number is the id provided by VDSmanager.

Install the system according to your needs:

Choose "Configure network manually"

An IP address is the IP-address provided by VDSmanager

All other network parameters can be found in the Network parameters module

Disk partitions:

boot.img (100M) 
 - primary partition, mount-point = "/boot" fs = "ext3"

 - primary partition, mount-point = "/", fs = "ext3" 

You do not need to create swap, but if you want, create a separate disk or use the same disk with boot.

Once installation is complete, edit the filesystem file:


Restart the VPS through VDSmanager, check it and add required software.

Start the server.

Creating a template

Create the directory for a template and paste the contents:

mkdir /kvm/template/debian
cp /kvm/machines/* /kvm/template/debian/

Mount the main disk and take all the file from it

  • Following is our system in the lvm-volume
fdisk /dev/kvm0/ -lu
Disk /dev/kvm0/ 4294 MB, 4294967296 bytes 
255 heads, 63 sectors/track, 522 cylinders, total 8388608 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Disk identifier: 0x000842f8 
                           Device Boot      Start         End      Blocks   Id  System 
/dev/kvm0/              63     8385929     4192933+  83  Linux 
  • Create the directory for mounting
mkdir /tmp/mnt

  • mount (63*512 id the start block number * block size)
mount /dev/kvm0/ /tmp/mnt/ -o offset=$((63*512))

When creating the guest machine from the template with tgz archive, VDSmanager will create a disk image and format it without partitioning. That's why you need to specify /dev/hdb instead of /dev/hdb1 in the /etc/fstab files.

edit /tmp/mnt/etc/fstab


/dev/hdb1       /               ext3    errors=remount-ro 0       1 


/dev/hdb        /               ext3    errors=remount-ro 0       1 

take the files

tar -czpf /kvm/template/debian/content.tgz -C /tmp/mnt/ .


umount /tmp/mnt/

Edit the grub config in /boot located in boot.img

Mount boot.img

mount /kvm/template/debian/boot.img /tmp/mnt/ -o loop,offset=$((512*63)) 

use the same numbers. The difference is that you need to mount from the file, thus the loop option

edit /tmp/grub/menu.lst, locate /dev/hdb1 to change into и меняем на /dev/hdb


umount /tmp/mnt/

Edit filesystem:


Pay attention to hdb=tar:content.tgz:500:c

  • tar - container type, in our case it is tar.gz
  • content.tgz - archive file
  • 500 - minimum disk image size
  • с - method on how to change the disk size

You may delete the VPS. Now you have your template configured.

Edit /usr/local/ispmgr/etc/vdsmgr.conf


disktemplate "debian" { 
	 Path /kvm/template/debian 
	 Status ok 

Restart VDSmanager:

killall vdsmgr

You have successfully created the template. Configure the template as follows

Installing VDSTools into the template

Download VDStools:

Select the latest version

go to the /kvm/template/debian directory

cd /kvm/template/debian

Unzip the archive:

mkdir content
tar -xzpf content.tgz -C content/

Paste vdstools (mind its bitness):

cp /kvm/tools/vdstools-0.7-Linux-i386.tgz content/root

create chroot into this directory

mount --bind /dev content/dev
mount --bind /proc content/proc
chroot content

go to the root directory, unzip and install:

cd /root
tar -xzf vdstools-0.7-Linux-i386.tgz


umount content/dev
umount content/proc

refresh the archive that contains the template

rm content.tgz
tar -czpf content.tgz -C content/ .

Delete the "content" directory

rm -rf content

The template is ready to use.

Creating a FreeBSD template

Perform the following actions to resize the disk:

  • create a virtual disk of a required size to connect to a VPS as secondary slave.
  • The virtual server will copy the file system into a new disk.
  • The old disk will be removed, the new one used as the main disk.

Preliminary steps

1. Create a machine called tpl-free64.boom with the empty-img template (in order to create a disk in the form of a file) 2. Edit filesystem (you are supposed to have the ISO disk):

cdrom= /kvm/iso/FreeBSD-8.1-RELEASE-amd64-disc1.iso 

Installing the operating system

3. Start and install FreeBSD. Use one disk (500MB is enough) for root partition «/»

4. Stop the server

Creating a template

5. Edit filesystem


6. Start, check settings, configure, if necessary.

  • Configure network settings
  • Configure ssh (root access privileges)

7. go to HOST, copy VDSTools into our server

scp /kvm/tools/vdstools-0.7-FreeBSD-8.0-amd64.tgz guest-ip-addr:/root

8. go to:

ssh guest-ip-addr

9. install VDSTools

cd /root
tar -xzf vdstools-0.7-FreeBSD-8.0-amd64.tgz

10. restart the machine; check connection between HOST and GUEST, stop it

halt -p

You have successfully created the template.

Create the /kvm/template/new-template-name directory to copy the files from /kvm/machines/tpl-free64.boom/

cp /kvm/machines/tpl-free64.boom/* /kvm/template/new-template-name/

Edit filesystem:


Refresh vdsmgr.conf : add

disktemplate "new-template-name" {  
	Path /kvm/template/new-template-name
	Status ok 

restart VDSmanager

killall vdsmgr
Was this helpful? Yes | No
Personal tools