Virtkick Docs

Documentation and information to Virtkick your business

How to Create Your Own Custom Virtkick Templates

Have you ever wanted to create your own Virtkick templates? This guide will walk you through the process of doing just that!

1. Create a machine

First, you will want to log in to your Virtkick panel as an admin. Once you have logged in, create a plan with just 5 GB of storage, we will use this as a base for our new template.

After the plan has been created, make a new machine using this plan, be sure to select the distribution you want your template to be based off of.

With the machine created you can now log in to the machine.

2. Make your changes

Now that you have access to the machine you will want to all of the changes you want. For example, if you want a template that comes with Nginx installed, you can install Nginx and configure it now.

Not sure what to do? Here are a few ideas:

  • LAMP stack
  • MEAN stack
  • Wordpress installation
  • Ghost installation
  • Minecraft server

You can configure just about anything you want.

Once you have configured the machine with the software you want, you can move on to the next step.

3. Clean up

With your machine configured you'll want to do a bit of clean up. This will make the template feel like it is brand new and eliminate things like your bash history.

First, remove your logs and bash history using these commands:

unset HISTFILE
rm -rf .ssh .bash_history .viminfo .lesshst
find /var/log -type f -exec rm {} \;
rm -rf /etc/ssh/*key*

Next, wipe your root password (a new one will be generated by Virtkick when a new machine is created):

sed -i "/^root:/ s#:[^:]*#:*#" /etc/shadow

Now clear the package manage cache, the exact commands for CentOS and Debian based systems are provided below, if you use a different package manager you'll want to look at the documentation for the exact command:

# This is for CentOS
yum clean all

# This is for Debian/Ubuntu
apt-get clean all

With the machine cleaned you should now shut down the machine through the panel and move on to the next step.

4. Create the template

The next step is to log in to your hypervisor directly. You will need to get the name of the virtual machine you have configured, to do this you can run virsh list --all as the root user. You can find the machine you created by looking for the name you provided in the panel, the format is:

Number_NameFromPanel_UUID

Match NameFromPanel with the name you provided earlier, note the full name as shown in virsh list --all.

With the name you can now start creating the template. Run the following commands to do that:

qemu-img snapshot -c "NAME_OF_MACHINE" /home/virtkick/hdd/NAME_OF_MACHINE.qcow2
qemu-img convert -f qcow2 -O qcow2 -s "NAME_OF_MACHINE" /home/virtkick/hdd/NAME_OF_MACHINE.qcow2 /home/virtkick/template/NAME_OF_TEMPLATE.qcow2
sync
qemu-img snapshot -d "NAME_OF_MACHINE" /home/virtkick/hdd/NAME_OF_MACHINE.qcow2

Substitute NAME_OF_MACHINE with the name you found earlier (from virsh), replace NAME_OF_TEMPLATE with any name you want to give this template.

Next, compress your template and generate a checksum using the following commands:

qemu-img resize NAME_OF_TEMPLATE.qcow2 100T
sha512sum /opt/templates/NAME_OF_TEMPLATE.qcow2
gzip -2 /opt/templates/NAME_OF_TEMPLATE.qcow2

Note the checksum, you will need this later!

You should now have a file called NAME_OF_TEMPLATE.gz and the checksum (this would have been printed to your console).

5. Start using your new template

The last step is twofold - you will need to upload your template (the .gz version) to a web server. This is necessary so all of your hypervisors can get the template quickly an easily.

Once the template is on a web server you can add the template to your panel using the steps shown in our custom ISO guide.

After the template has been added to your Virtkick panel you are all set to test it!

Have any questions or problems? Just let us know - we are happy to help!

Back to the list ยป

avatar
Joe Pettit
Developer @ Virtkick
comments powered by Disqus