Creating custom templates

jburleson

Member
Apr 29, 2008
31
0
6
Jonesboro, AR
Thought I would throw this out for those who are interested. I am by no means an expert, so if there are any comments or improvements I welcome them. This is the method I use for creating custom templates.

As of Proxmox 1.4, template naming must conform to the following schema:
<OS>-<OSVERSION>-<NAME>_<VERSION>_<ARCH>.tar.gz
For Example: "ubuntu-8.04-standard_8.04-1_i386.tar.gz"

Note: Watch the usage of "-" and "_" in the naming schema.


Architecture

  • 32-bit templates should use i386 for ARCH
  • 64-bit templates should use amd64 for ARCH


Step 1) Create a virtual machine using whatever template you like.
Step 2) enter the virtual machine (vzctl enter CTID)
where CTID is the ID of the virtual machine
Step 3) Install/remove any software you want
Step 4) Exit out of the virtual machine (but do not stop it)
Step 5) remove the ip address from the virtual machine
vzctl set CTID --ipdel all --save
or use the web interface to remove the ip address
Step 6) Stop the virtual machine
vzctl stop CTID
or use the web interface
Step 7) change directory to the virtual machines directory
cd /var/lib/vz/private/CTID
Step 8) tar the directory
tar –czvf /var/lib/vz/template/cache/<template name>.tar.gz .
Note: the commands ends with a space followed by a period
Make sure you are in the directory for the virtual container
(/var/lib/vz/private/CTID)

Now you have a new template to use.

These instructions are largely borrowed from:
http://wiki.openvz.org/Centos_template

If you use yum to install software make sure to run "yum clean all" before you stop the virtual machine. Also if you want to exclude certain directories you can use the -X options with tar.
I exclude the following directories:
.bash_history
lost+found
tmp/*
src/*
usr/src/*

Be careful to set the directory path correctly when using an exclude file. You want to make sure that they are all pointing to CTID directory not the directories that are in the host system.

Hope this helps.
 
Last edited:
This should be a sticky or a wiki entry.
 
This should be a sticky or a wiki entry.

Erhm perhaps with the addition on how to solve the 'no conf file found' error wich leaves you with a very minimal install with no connection :rolleyes:
 
Erhm perhaps with the addition on how to solve the 'no conf file found' error wich leaves you with a very minimal install with no connection :rolleyes:

You have to make sure you name the new template correctly so that it matches with the conf files in /etc/vz/dists.

Let me give you an example:
If you look into the /etc/vz/dists dir you will see (among others) debian-4.0.conf, debian-3.1.conf, debian-3.0.conf, and debian.conf. If you name your new template debian-3.0.some_stuff.other_things.tar.gz then it will match up with debian-3.0.conf, but if you named it debian.some_stuff.tar.gz it would match up with debian.conf. However, if you named it my_new_template.tar.gz and there's no my_new_template.conf file in the /etc/vz/dists directory then tha template will not create a very functional container.
 
Hi Fool,

That was exactly the information I missed!
Thanks, all is working now!
 
I followed the steps above and cp centos.conf to centos_test.conf but I still have a non sense disk quota error:

Code:
/usr/bin/pvectl vzcreate 102 --disk 12 --ostemplate centos_test-5.1-i386-default-image.tar.gz --hostname test --nameserver 192.168.1.254 --searchdomain toto.com --onboot yes --userpasswd root:test123 --ipset 192.168.1.202 --swap 1 --mem 512 --cpus 1

unable to create VE 102: command 'vzctl create 102 --ostemplate centos_test-5.1-i386-default-image --config pve.auto' failed with exit code 48:

tar: ./lib/modules/2.6.18-53.1.19.el5xen/extra/mISDN_dsp.ko: Wrote only 9216 of 10240 bytes
tar: ./lib/modules/2.6.18-53.1.19.el5xen/extra/xhfc.ko: Cannot write: Disk quota exceeded ...
(many more lines not pasted here)

The container runs fine on itself. When started, it uses 8.58% of 12GB.
I tried by removing the swap as stated in another post on this forum, but no luck.

Thanks for your help:p
 
Try renaming the template name from:
centos_test-5.1-i386-default-image
to:
centos-5.1-i386-default-test-image
 
FIXED.
vzsplit -n 10 -f default
vzctl create 102 --ostemplate centos-5.1-i386-default-test-image --config default

Now I need to tweak the config file to make Proxmox manage it.

It looks like a problem of double quota (size and number of files) set too low in pve.auto for my template (1.75GB when deployed).
I wonder where to set up inodes in proxmox VM creation page?
 
When you create ne VE you specify the disk size. Inodes are computed

max_inodex = $disksize(GB) * 200000;

which is basically unlimited.

To set the disk size you can use the following command:

pvectl vzset VMID --disk SIZE

(Size in GB)

Does that work?
 
Hi dietmar
Thanks for your help on this subject.

IMHO your command is for an existing container, may be I'm wrong?

I still have trouble with another (bigger) template made from a real machine (328000 files). same message from disk quota.

Since it stops during the copy, it doesn't rm -fR /var/lib/vz/private/1XX.tmp (feel free to implement in next release).

I need to understand something:
at VM creation from the web page pvectl vzcreate doesn't change ve-pve.auto.conf-sample (at least on my machine), so how does it passes the disk (and computed inodes) size to vzctl create?
 
I need to understand something:
at VM creation from the web page pvectl vzcreate doesn't change ve-pve.auto.conf-sample (at least on my machine), so how does it passes the disk (and computed inodes) size to vzctl create?

Oh, you found a bug! Sorry - i did not saw that problem first.

I will fix that for the next release.

- Dietmar
 
You're welcome.
Your proxmox is wonderful and is really appreciated.

I thought my question was a noob one, but I'm happy I spot a bug :D

I just wonder why it wasn't seen before, since it happens as soon as you try to work with tweaked templates and migrated machines (bigger than default templates I mean).

BTW, it was a good (but long) way to learn how it works.
 
After step 7, do:

echo \# > ./etc/network/interfaces
echo \# > ./etc/network/interfaces.template

PLEASE NOTE THERE's A DOT BEFORE /etc

this will avoid the connection problems on custom templates ;)

(took a couple hours to understand it.. :p)
 
Sorry the double post (just remembered a thing):

after step 7, you also need to delete some files:

rm ./etc/hosts
rm ./etc/hostname
rm ./etc/resolv.conf

THE SAME NOTE AGAIN: don't forget the dot before /etc or you will mess your proxmox server and will lose connection to it!

(dietmar/tom, why Edit post feature is disabled on the forums?)

Regards
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!