Forum archive
Creating OpenVZ templates by leveraging TKLPatch
[UPDATE 16-10-2011] v0.4 minor update - Fixed autoremove bug (commented out autoremove) and reduced patch size (scripted changes to firstboot scripts rather than include them in overlay). Also updated install instructions below (will install v0.4).
[UPDATE 15-10-2011] (Jeremy) Forked Adrian's tklovz patch and did a major update (changelog below). Also repackaged Adrian's tkliso2ovz kit as a TKLPatch.
[edit] Minor Bug: apt-get autoremove runs interactively so the process of conversion is halted (wants to remove a package 'turnkey-sslcerts' - which possibly should be set to manually installed anyway?) as it waits for input (y/n). This isn't a huge issue (just hit y or n during conversion) and can be easily fixed but I'm not going to worry about it just now. - fixed see above.
TKLOVZ patch Changelog:
* Removed lots of cruft (kernel and modules, plus lots of unneeded packages) from templates which significantly reduces the template size (Core OVZ now ~60MB smaller than ISO).
* Fixed - networking issues.
* Fixed/Workaround - getting stuck on interactive firstboot scripts (causing Webmin and other services to not start). Workaround was to only allow the non-interactive scripts run, requires user to manually run an init-script on first boot (to access interactive initialisation scripts) see below.
* Reworked how ssh keys and ssl-certs are created (now uses default TKL inithook firstboot scripts).
* Stopped confconsole from running (wasn't causing issues but wasn't usable anyway).
* Created a init-ovz script to run interactive firstboot scripts manually (eg Hub initialisation, Security updates, etc).
TKLISO2OVZ Changlog:
* Repackaged Adrian's work with the new version of TKLOVZ patch as a complete TKLPatch so it is easy for newbs (and others) to set up an environment for creating OVZ templates.
Install:
These steps are ideally to be used on a clean install of TKL Core at a terminal (local or SSH). Theoretically this could be used on any installed TKL appliance although running services can cause unpredictable results.
apt-get update apt-get install tklpatch wget http://cdn.turnkeylinux.org/files/attachments/tkliso2ovz0.4.tar.gz tklpatch-apply / tkliso2ovz0.4.tar.gz
Usage:
Example of creating an OVZ template of TKL LAMP. Assuming that the ISO is in the local directory.
tkliso2ovz turnkey-lamp-11.2-lucid-x86.iso
This will create an OVZ template called turnkey-lamp-11.2-lucid-x86-ovz.tar.gz in the local directory.
Firstboot of OVZ container:
Some default TKL inithook firstboot scripts run as they would on any other TKL appliance (eg create SSH keys and SSL certificates) but the interactive ones were causing problems so they no longer run. I have worked around this issue by creating an initialisation script. Some aspects of TKL will work ok without running this script and on some appliances you may not even notice that it hasn't been run. However for full functionality it is recommended that you run the script:
init-ovz
[/UPDATE]
[UPDATE 12-01-2011] Preseeding working so that the appliance start ups with default settings/passwords. Polished the patch a bit.
[UPDATE 11-01-2011] Added a pair of lines to make mysql start at boot and holding a package to prevent upgrade failures (as recommended in the guide's comments)
[UPDATE 05-01-2011] I (Adrian) took Jed's work and extend it a bit to make it work. The result was:
1. A tklovz patch that prepares the appliance filesystem to work as an openVZ container.
2. A top level tkliso2ovz script which does the following:
2.1. tklpatch-extract-iso: to get the filesystem
2.2. tklpatch-apply tklovz.tar.gz: the patch must be in the same folder or /usr/local/share/tklpatch/tklovz.tar.gz
2.3. tklpatch-gen-ovztemplate: to compress and get the final template file.
So if any of you wants to experiment with this, you have to options:
- On a system with tklpatch installed, copy both supplied scripts to /usr/local/bin/ and give them execution permissions. Then place tklovz.tar.gz in your working directory and issue the command:
tkliso2ovz /path/to/turnkey-appliance.iso
- Wait a bit for the following release of TKLDevEnv which will include all the commands already configured. I hope to get it out this week.
Any questions, feel free to ask. I've tested with core and revision-control without issues. But redmine is not working. But I'm still testing, as the appliance had an issue while decompressing the original iso which I think it's related to this error. Also, keep in mind:
- Confconsole won't be running when you access to the console of the container. You must run confconsole if you need access to it.
- When using venet, confconsole won't work as intented, because you are managing the ip configuration at another level. If you wish yo use confcosole to work as usual, use veth as your network type. Be sure to check the docs about the differences http://wiki.openvz.org/Differences_between_venet_and_veth
- The template name will be the iso name plus -ovz.tar.gz at the end. So if your going to use it in proxmox, be sure to rename it following their guidelines:
<OS>-<OSVERSION>-<NAME>_<VERSION>_<ARCH>.tar.gz
For Example: "turnkeylinux-10.04-revision-control_11.0_i386.tar.gz"
- The host name ends up being renamed to what you specify in the creation of the container. Also the root password is specified in the creation step. - Inithooks don't get runned. So you must manually execute the command /usr/lib/inithooks/run to complete your appliance setup.
[update 18-12-2010] Further testing has revealed some major issues! :( The templates created are currently unusable.
[Original post] For some time now I've been looking to produce OpenVZ templates of the v11 (Lucid based) release of TKL. However, rather than simply provide instructions as I did for the v2009.x release or even provide precreated templates (as xtrac568 did - also for the 2009.x release) I have been trying to script the conversion or better still leverage TKLPatch to create the templates. That way users can create their own templates and templates of TKLPatched appliances could also be produced by end users. Perhaps it could even be included in Adrian's TKL Dev Environment?
Great news is that the OpenVZ templates seem to build nicely in a chroot so you don't even need a working OpenVZ environment to build in. I've made a minor tweak to the top level TKLPatch script (tklpatch) and coupled it with a specific OVZ creation patch (thus creating a new script-thing I've called tklovz).
[Update] It works! Be warned, I haven't extensively tested it, only on the TKL 11.0RC Core ISO and I have only done arbitrary testing of the resulting OpenVZ template. Also as has been mentioned elsewhere not all appliances will run well under OpenVZ. Apparently Java based apps aren't the greatest, but only way to know for sure if the appliance you want to run in OVZ is to test!
Please find attached the tklovz script and patch. Only the name of the ISO needs to be passed to the scipt (unlike tklpatch which also requires the patch name). Assuming the TKLOVZ.tar.gz and your TKL ISO are in ~ (/root) then you only need to unpack tklovz and run it.Using Core as an example:
tar xzvf TKLOVZ.02.tar.gz ./tklovz turnkey-core-11.0rc-lucid-x86.iso
Assuming that all goes well, you should end up with an OpenVZ template named accordingly (in this instance "turnkey-core-11.0rc-lucid-x86.tar.gz").
What this patch/script does
The scripts and files are more fully detailed in the Dev wiki:
- Extracts the ISO (tklpatch-extract-iso)
- Applys the patch (tkl-patch apply) - the OVZ creation process script (the conf script of the patch)
- Modifys required files & services for OVZ template
- Builds preliminary template with required files
- Recreates required files in prelimary template, cleans logs etc.
- Packages final template
- Instead of recreating an ISO, it copys out the created OpenVZ template (.tar.gz) and names it the same as the original ISO
- Cleans up the temporary .rootfs & .cdroot filesystems.
I anticipate that there will be updates as I try to tweak things a bit, but no promises.
Where
perhaps the leading ~ is causing the problem (because $rootfs should be adequite). It still doesn't explain (to me anyway) why the script doesn't either error or complete. I'll check this when I get home though.
Anone else got any ideas of feedback?