Prepare a virtual server with a limited amount of disk space. For example to create a template of a minimal install of CentOS 2GB of disk is enough.
At the partitioning stage create the main / (slash) partition as a primary ext3 or ext4 as large as you can only leaving a few MB on the disk.
Use the existing space as swap creating it as a primary volume.
You should now have a / partition (sda1) and a swap partition (sda2).
Follow the rest of of the install/setup process making sure you set the networking as DHCP until it is complete.
The next step is to make sure the source virtual server is shutdown and ready for packaging. You will also need to know the KVMID and logical volume group name.
On the host node you will need to mount the virtual servers partitions:
This has now mounted the / partition on the host to /mnt.
/etc/fstab inside the virtual server needs to be modified to reflect the correct partitions:
It needs to look like this:
Next lets remove any bash history:
Some distros need the following to get networking working:
Unmount the virtual server:
The next step is worth doing as libguestfs will then compress the swap partition. If you don't do this it will make your template a lot larger:
Remove the mappings:
Sysprep the virtual server:
The last thing to do is package the template: