1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating custom templates

Discussion in 'Proxmox VE 1.x: Installation and configuration' started by jburleson, Jun 23, 2008.

  1. jburleson

    jburleson New Member

    Joined:
    Apr 29, 2008
    Messages:
    29
    Likes Received:
    0
    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.
     
    #1 jburleson, Jun 23, 2008
    Last edited: Nov 22, 2010
  2. Erwin123

    Erwin123 Member

    Joined:
    May 14, 2008
    Messages:
    207
    Likes Received:
    0
    This should be a sticky or a wiki entry.
     
  3. Erwin123

    Erwin123 Member

    Joined:
    May 14, 2008
    Messages:
    207
    Likes Received:
    0
    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:
     
  4. chopeta

    chopeta Member

    Joined:
    Sep 11, 2008
    Messages:
    45
    Likes Received:
    0
    Great post.
    Thanks Joe.
    Regards,
    Chopeta
     
  5. thefool808

    thefool808 Member

    Joined:
    Jun 24, 2008
    Messages:
    59
    Likes Received:
    0
    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.
     
  6. Erwin123

    Erwin123 Member

    Joined:
    May 14, 2008
    Messages:
    207
    Likes Received:
    0
    Hi Fool,

    That was exactly the information I missed!
    Thanks, all is working now!
     
  7. manzano

    manzano New Member

    Joined:
    Sep 22, 2008
    Messages:
    7
    Likes Received:
    0
    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
     
  8. chopeta

    chopeta Member

    Joined:
    Sep 11, 2008
    Messages:
    45
    Likes Received:
    0
    Try renaming the template name from:
    centos_test-5.1-i386-default-image
    to:
    centos-5.1-i386-default-test-image
     
  9. manzano

    manzano New Member

    Joined:
    Sep 22, 2008
    Messages:
    7
    Likes Received:
    0
    I tried with new name centos-5.1-i386-default-test-image.tar.gz but still no luck.
     
  10. manzano

    manzano New Member

    Joined:
    Sep 22, 2008
    Messages:
    7
    Likes Received:
    0
    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?
     
  11. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    15,030
    Likes Received:
    142
    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?
     
  12. manzano

    manzano New Member

    Joined:
    Sep 22, 2008
    Messages:
    7
    Likes Received:
    0
    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?
     
  13. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    15,030
    Likes Received:
    142
    Oh, you found a bug! Sorry - i did not saw that problem first.

    I will fix that for the next release.

    - Dietmar
     
  14. manzano

    manzano New Member

    Joined:
    Sep 22, 2008
    Messages:
    7
    Likes Received:
    0
    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.
     
  15. RenatoMN

    RenatoMN Member

    Joined:
    Oct 1, 2008
    Messages:
    48
    Likes Received:
    0
    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)
     
  16. RenatoMN

    RenatoMN Member

    Joined:
    Oct 1, 2008
    Messages:
    48
    Likes Received:
    0
    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
     
  17. Marcos

    Marcos New Member

    Joined:
    Sep 4, 2010
    Messages:
    5
    Likes Received:
    0
    Thanks!!
     

Share This Page