Creating VPS under KVM from empty template (VDSmanager)

From ISPWiki

Jump to: navigation, search

Creating an "empty" virtual machine

  1. Boot the "empty" template.
  2. Create a VPS using the "empty-img" template. Provide "" and IP-address10.1.1.2 as hostname.
  3. Configure the disk subsystem:

If you need additional hard drives for VPS, or you need to use the iso-image as a CD-ROM, edit the "filesystem" file in /kvm/machines/

/kvm/machines is the path to the default virtual machines' images.

The "filesystem" file looks like as follows:


For example, once a VPS has been created from the "empty-img" template, the filesystem file will look like as follows:


This means that the VPS is connected to one hard drive, which image is located in /kvm/machines/ You can resize the disk by altering the file size (a user can himself change the partitions' size). Hard drive is a boot disk. hda is the main disk.

Using a standard method you can define as many as four hard drives. For example, in order to connect one more hard drive, you need to specify the following line:


In this case a new hard drive will be created either as lvm, or as the image-file (depending on whether there is free disk space in the lvm partition). size = size, disk name: /kvm/machines/ for the image-file and /dev/kvm00/ for lvm.

Alternately, you can create a partition manually

kvm-img create <filename> <size>M

The last letter stands for a resize type.

  • n - no resize
  • r - changing the file or lvm-partition's size
  • c - "copy" - create a new image, mount the old one and copy all the files to the new image.
  • extend - "extend" the image and send a message to the guest system,
  • inner-copy - inner copy of the data of the gust system OS(for FreeBSD).

When changing the image size, the image specified in root=... will be changed.

If you enable cdrom=..., the iso-image will be connected as cd/dvd-rom. Please note, cdrom is connected as a secondary master (i.e. hdc-disk). Thus, you cannot use hdc-disk along with the cdrom image.

In order to boot from the iso-image, you need to change "boot=c" into "boot=d".

The filesystem file will look like as follows:


A 200 MB hda disk will be created again.

We have created the boot partition as primary master boot. The main root-disk is connected as hdb, edit root=hdb for the system to know where configuration files are located on the virtual machine.

Run the VPS, enter vnc (I use vinagre ), provide host, the VDSmanager IP-address + " :id" , where id is a virtual machine identifier (you can locate it in the first column of the table in VDSmanager). Install the operating system and configure the network.

Our virtual machine is up and running.

Creating a disk template for KVM (VDSmanager)

If you wish to convert a KVM-based virtual machine into a template, mind the followings,:

  1. Follow the instructions below to install a template
    1. Copy the template's content into the directory that holds the virtual machine (normally, it is /kvm/machines/NAME/ )
    2. Execute the /kvm/machines/NAME/install script (the parameter is a path to the directory with the virtual machine)
    3. Process the filesystem file
    4. Send messages to the guest system (VDSTools must be installed on the guest system)

To make the system boot correctly, install two hard drives on the system: the first disk is a boot drive with the mount point /boot, the second one is the main drive with the mount point /.

For example, we have created a VPS with two hard drives, such as hda - /kvm/machines/ 200 MB in size, and hdb - /kvm/machines/ 4Gb in size. Its name is, its IP-address is Its operating system is Fedora-12-i386. Information on how to create and connect additional hard drives can be found in the article Content of filesystem (VDSmanager)

With the system installed, you need to make it work as a template:

  1. Edit /boot/grub/grub.conf, /etc/fstab
  2. Disable selinux
  3. Download, unzip and install VDSTools from [1] using

Please note, that the hard drive partition that was created during the installation process will be called /dev/sdb1 If you want to re-create the partitions from vds-manager and change their size, you need to change /dev/sdb1 into /dev/sdb on the guest virtual machine.

fdisk -lu /kvm/machines/

Then, mount the root disk image into the /tmp/mnt directory.

mount -o loop,offset=32256 /kvm/machines/ /tmp/mnt

offset stands for the address of the partition's beginning (normally, it is sector 63, the size of a sector is 512 byte).

Execute the following command to find the information about partitions

fdisk -lu /kvm/machines/

You do not need to provide the offset parameter, if the partition was created via VDSmanager,

Archive the disk content:

tar -czpf /kvm/machines/ -C /tmp/mnt .
umount /tmp/mnt

Create a directory for the template

mkdir /kvm/template/TEMPLATE-NAME

Copy the machine into that directory

cp /kvm/machines/* /kvm/template/TEMPLATE-NAME

Delete the old disk

rm /kvm/template/TEMPLATE-NAME/


mv /kvm/template/TEMPLATE-NAME/ /kvm/machines/

If the boot partition is created as lvm, add the command

dd if=/dev/kvm00/ of=/kvm/template/TEMPLATE-NAME/boot.img

Delete the old machine from vds-manager.

Edit the filesystem file:


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

disktemplate "TEMPLATE-NAME" {
	Path /kvm/template/TEMPLATE-NAME
	Status ok

The template is ready to use.

Was this helpful? Yes | No
Personal tools