How to create KVM template

Creating KVM Templates

Overview 
From version 1.13.00 a script is supplied on all slave servers to aid you in creating KVM templates.
/scripts/kvmtemplate
KVM templates can be created in two generations (1 or 2). The generations are explained below: 

Generation 1

Generation 1 templates are fixed size byte by byte images. G1 should be used when you need to create a special template that either includes obscure partitions or filesystems that can't be manipulated from the host node. These include but are not limited to FreeBSD (Unix) or logical partitions. G1 templates can still have networking setup by SolusVM, however any filesystem resizing would need to be scripted inside the template.


Generation 2

Generation 2 templates are far more flexible than generation 1 templates in respect to filesystem resizing and configuration. G2 templates should be used if the template operating system is going to be Linux or Windows and uses standard filesystems (ntfs, ext3 or ext4). G2 templates do NOT currently support logical volumes or extended partitions, you would need to use G1 for that.


Creating a Generation 1 Template

When creating G1 templates you need to make sure the source virtual server is as small as possible, however if it's going to be a fixed size template you can ignore that! When the virtual server is prepared and ready to be packaged issue a shutdown and make a note of the virtual servers kvmID (i.e kvm101). On the slave the virtual server is on run the following script:

/scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=1
It may take a while for it to complete. Once it's done you will be given a location and filename for the template. Example:
Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
The next step is to rename the template. Example:
cd /home/solusvm/kvm/template/
mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz linux-centos-5.8-x86_64-custom-gen1-v1.gz
or if it was a windows template:
cd /home/solusvm/kvm/template/
mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz windows-2008-server-r2-custom-x86_64-gen1-v1.gz

 


Creating a Generation 2 Template

The first step when creating a G1 template is to work out what the partition number is that you wan't to resize on creation of a virtual server. You can run the following for the specified kvmID:

/scripts/kvmtemplate --mode=prescan --vmid=kvm101 --generation=2
Example Output:
Name      Type       VFS  Label MBR Size Parent   UUID
/dev/sda1 filesystem ext4 -     -   20G  -        23261380-2181-4fee-bf1a-b7235d2b9ad9
/dev/sda2 filesystem swap -     -   99M  -        d0bc2596-74ae-45b2-b2d4-d59f06b54d07
/dev/sda1 partition  -    -     83  20G  /dev/sda -
/dev/sda2 partition  -    -     82  99M  /dev/sda -
/dev/sda  device     -    -     -   20G  -        -   
From that output we can decipher that partition 1 (/dev/sda1) is the partition to resize. 

Now we can run a prepare on the source virtual server to remove any ssh keys, mac addresses and udev rules. Please note this is not fool proof. You should prepare the virtual server manually to make sure all history is removed and configuration files are clean. You may also need to make sure /etc/fstab is correct and any uuids are removed if this is a linux virtual server. Use vda for virtio and sda for ide. 

You do NOT need to run prepare for windows virtual servers. See Hints on Creating Windows KVM Templates
/scripts/kvmtemplate --mode=prepare --vmid=kvm101 --generation=2
Once the source virtual server is ready to be packaged you simply run the package scripts. Example:
/scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=2
It may take a while for it to complete. Once it's done you will be given a location and filename for the template. Example:
Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
The next step is to rename the template. Example:
cd /home/solusvm/kvm/template/
mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz linux-centos-5.8-x86_64-custom-gen2-v1.gz
or if it was a windows template:
cd /home/solusvm/kvm/template/
mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz windows-2008-server-r2-custom-x86_64-gen2-v1.gz
Just make sure when adding the template to SolusVM you specify the correct generation and partition to resize.

This document is a Work in Progress. It may be updated at any time

Was this answer helpful?

 Print this Article

Also Read

How to re-install Centos yourself remotely

NOTE: This is only for Dedicated Servers. All VPS, go to client area.Assuming you currently have...

Why my drive is slow

First, check to make sure write cache is enabled. On Centos, you type hdparm -I /dev/sda Then...

How can upgrade kernel on xen main node or container too?

Centos:on host node---yum updatecd /usr/local/lxlabs/hypervm/httpdocs/lphp.exe...

How to change cPanel password from command line?

cPanel password of a domain can be changed from command line using cPanel script. Given below are...

Fix WHM/cPanel cPHulk Brute Force Protection Lock Out Via SSH

ssh to the server and login as root then type   mkdir /home/cphulkchmod 777...