{"id":150,"date":"2009-02-03T18:29:19","date_gmt":"2009-02-04T01:29:19","guid":{"rendered":"http:\/\/www.kernelcrash.com\/blog\/?p=150"},"modified":"2009-06-23T16:32:34","modified_gmt":"2009-06-23T23:32:34","slug":"openvz-and-asterisk-and-pae","status":"publish","type":"post","link":"https:\/\/www.kernelcrash.com\/blog\/openvz-and-asterisk-and-pae\/2009\/02\/03\/","title":{"rendered":"OpenVZ and Asterisk and PAE"},"content":{"rendered":"<p>This post started out as a simple howto for installing <a href=\"http:\/\/www.asterisk.org\">Asterisk<\/a> in an <a href=\"http:\/\/wiki.openvz.org\/Main_Page\">OpenVZ<\/a> container on <a href=\"http:\/\/www.debian.org\/releases\/testing\/\">Debian Lenny<\/a>. It all started out well, as a test box I used my core2duo server running Debian Lenny, did an apt-get of the openvz kernel image that is already in the Lenny standard repository, downloaded an OpenVZ template for\u00a0 a minimal Lenny virtual machine (VM), got a VM running, installed asterisk using apt-get inside the VM, got it configured, then worked out how to install the zaptel modules (usiing the debian repository&#8217;s zaptel-source) in the host machine using module-assistant, and then getting the zaptel stuff recognised within the VM. And it all worked.<\/p>\n<p>However, setting it up on the core2duo box was just a test. I really wanted to set it up on my old Thinkpad T42. It&#8217;s been gathering dust since I bought the Macbook, and it seemed such a shame to have it doing nothing. I&#8217;ve had an old Thinkpad 600X running Asterisk for a while now. It runs natively (ie. not in a VM) and does the job, but it has a hand compiled kernel and Asterisk &#8230; and that kind of set up tends to put me off doing proper updates on it. Hence why I was liking Debian Lenny; modern kernel and Asterisk 1.4.x in the standard repository. And the T42 had a bit of horsepower with a 1GB of RAM and a 100GB drive, so I thought something like Asterisk could be virtualised on it.<\/p>\n<p>So step 1, install Lenny from CD on the T42 and &#8216;apt-get update&#8217; , &#8216;apt-get upgrade&#8217;, then step 2 ; install the openvz kernel image;<\/p>\n<blockquote><p>apt-get install linux-image-2.6.26-1-openvz-686<\/p><\/blockquote>\n<p>And reboot &#8230; and nothing. It would not boot. Obviously my Thinkpad did not like this kernel. It turns out that the Debian Lenny OpenVZ kernel is compiled with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Physical_Address_Extension\">PAE<\/a> support compiled in. A core2duo has PAE support. The Pentium M in the Thinkpad does not support PAE.<\/p>\n<p>So what to do? I could go on about the other virtualisation techniques I tried here &#8230; but ultimately I liked the idea of OpenVZ; Simple kernel mod, light overhead, don&#8217;t need dedicated raw files on disk for VMs. I also liked that Lenny had a standard OpenVZ kernel in it&#8217;s repository, which ultimately meant &#8216;easy kernel updates&#8217;.<\/p>\n<p>So I thought I&#8217;d have\u00a0 a go at trying to recompile the Debian OpenVZ kernel with PAE turned off &#8230; in a supportable way. To me the easy way is to get a vanilla kernel from kernel.org, and add the patches from openvz.org. But I wanted to have a kernel closely approximating the latest apt-get&#8217;able Debian OpenVZ kernel.<\/p>\n<p>I&#8217;ve used make-kpkg to make my own debian kernels before, but that didn&#8217;t really work in this case.<\/p>\n<p>So here&#8217;s what I did (I got a lot of ideas from <a href=\"http:\/\/it.toolbox.com\/blogs\/locutus\/easily-build-a-debian-xen-kernel-package-without-pae-22254\">this post about Xen without PAE<\/a>);<\/p>\n<blockquote><p># get the source<br \/>\ncd \/usr\/src<br \/>\napt-get source linux-image-2.6.26-1-openvz-686<\/p><\/blockquote>\n<p>Now you should end up with a \/usr\/src\/linux-2.6-2.6.26 directory. It looks like a normal kernel extraction directory, but with a debian directory.<\/p>\n<blockquote><p>cd \/usr\/src\/linux-2.6-2.6.26\/debian\/config\/i386<br \/>\nvi config.686-bigmem<\/p><\/blockquote>\n<p>Now I just searched for PAE in the partial config file and turned it off, as well as disabled the 64GB setting and enabled the 4GB one. Mine looks like this:<\/p>\n<blockquote><p>CONFIG_HIGHMEM4G=y<br \/>\nCONFIG_HIGHMEM64G=n<br \/>\n## end choice<br \/>\nCONFIG_X86_PAE=n<\/p><\/blockquote>\n<p>Save that. Now do all the steps to apply patches, build the config, and compile to generate the kernel image and headers deb<\/p>\n<blockquote><p>cd \/usr\/src\/linux-2.6-2.6.26<br \/>\nfakeroot debian\/rules debian\/build debian\/stamps<\/p>\n<p># Removing these ABI files below is a cheap hack workaround to errors that are normally produced at the end of the compile<\/p>\n<p>rm debian\/abi\/2.6.26-1\/*<br \/>\nfakeroot make -f debian\/rules.gen binary-arch_i386_openvz_686<\/p><\/blockquote>\n<p>That last fakeroot command will take ten bazillion years to complete. Once complete you should end up with two deb files in \/usr\/src;<\/p>\n<blockquote><p>linux-headers-2.6.26-1-openvz-686_2.6.26-13_i386.deb<br \/>\nlinux-image-2.6.26-1-openvz-686_2.6.26-13_i386.deb<\/p><\/blockquote>\n<p>Now install both of these;<\/p>\n<blockquote><p>cd \/usr\/src<br \/>\ndpkg -i linux-headers-2.6.26-1-openvz-686_2.6.26-13_i386.deb<br \/>\ndpkg -i linux-image-2.6.26-1-openvz-686_2.6.26-13_i386.deb<\/p><\/blockquote>\n<p>And make sure you have the OpenVZ tools installed;<\/p>\n<blockquote><p>apt-get install vzctl<\/p><\/blockquote>\n<p>And try rebooting<\/p>\n<p>This time it worked for me.<\/p>\n<p>And now (finally) we set up a virtual machine and install Asterisk in it.<\/p>\n<p>Download an OpenVZ template for Lenny from <a href=\"http:\/\/openvz.org\/download\/template\/cache\">http:\/\/openvz.org\/download\/template\/cache<\/a>;<\/p>\n<blockquote><p>debian-5.0-i386-minimal.tar.gz<\/p><\/blockquote>\n<p>You just put the tar.gz file in \/var\/lib\/vz\/template\/cache (ie. don&#8217;t extract it).<\/p>\n<p>Then its a case of picking a unique id for your VM (eg. 101) and doing\u00a0 something like;<\/p>\n<blockquote><p>vzctl create 101 &#8211;ostemplate debian-5.0-i386-minimal &#8211;config vps.basic<br \/>\nvzctl set 101 &#8211;onboot yes &#8211;save<br \/>\nvzctl set 101 &#8211;hostname testmachine &#8211;save<br \/>\nvzctl set 101 &#8211;ipadd 10.1.2.3 &#8211;save<br \/>\nvzctl set 101 &#8211;nameserver 1.2.3.4 &#8211;save<br \/>\nvzctl start 101<\/p><\/blockquote>\n<p>The VM should start quickly and to get a sort of console you enter;<\/p>\n<blockquote><p>vzctl enter 101<\/p><\/blockquote>\n<p>One thing that confused me initially is how networking works. The basic example above uses venet networking. I wasnt sure whether the IP address I specified should be on a seperate subnet or on the same subnet as my host machine. In the end, I used an IP address that was on the same subnet as my host machine. It doesn&#8217;t use brctl style bridging, but it effectively bridges the interface onto your network. I must admit I couldn&#8217;t find a decent explanation\/diagram of how OpenVZ networking works.<\/p>\n<p>Install asterisk in the VM;<\/p>\n<blockquote><p>apt-get install asterisk<\/p><\/blockquote>\n<p>The install worked fine, but because of problems with Music On Hold in the past I wanted to set up ztdummy properly. This can be done.<\/p>\n<p>In the host machine I <a href=\"https:\/\/www.saruman.biz\/wiki\/index.php\/Installing_and_configuring_Zaptel\">installed the zaptel modules per this debian howto<\/a><\/p>\n<blockquote><p>apt-get install zaptel-source<br \/>\nmodule-assistant prepare<br \/>\nmodule-assistant auto-install zaptel<\/p><\/blockquote>\n<p>Afer you do that, do a &#8216;modprobe ztdummy&#8217;. The first time I tried this it didn&#8217;t work, because Lenny had downloaded the &#8216;official&#8217; package for the OpenVZ kernel headers rather than the one that I generated. If that happens to you, dpkg -r the old package, and then install the headers deb that you created earlier. Then run the auto-install above again and double check that the ztdummy modules inserts cleanly. If you do a dmesg now, you should see something like;<\/p>\n<blockquote><p>ztdummy: High resolution Timer started, good to go<\/p><\/blockquote>\n<p>So that gets ztdummy working from the host machine. We need to make it accessible from within the virtual machine. I looked at the following two howtos;<\/p>\n<p><a href=\"http:\/\/wiki.openvz.org\/Asterisk_in_VE_with_debian_stable\">http:\/\/wiki.openvz.org\/Asterisk_in_VE_with_debian_stable<\/a><br \/>\n<a href=\"http:\/\/wiki.openvz.org\/Asterisk_from_source\">http:\/\/wiki.openvz.org\/Asterisk_from_source<\/a> (I just used the vzctl example commands they have)<\/p>\n<p>The big test of whether the ztdummy stuff is working from inside the virtual machine is to run zttest and hit ctrl-c after a few lines of output. Here&#8217;s how mine runs;<\/p>\n<p>root@lenny:\/# zttest<br \/>\nOpened pseudo zap interface, measuring accuracy&#8230;<br \/>\n99.996582% 99.975983% 99.984177% 99.983887% 99.984070% 99.984467% 99.984375%<br \/>\n99.984177% 99.979492% 99.984467% 99.981735% 99.983208% 99.984581% 99.982819% 99.983978%<br \/>\n99.982811% 99.977448% 99.983971% 99.983971% ^C<br \/>\n&#8212; Results after 19 passes &#8212;<br \/>\nBest: 99.997 &#8212; Worst: 99.976 &#8212; Average: 99.983484, Difference: 99.983484<\/p>\n<p>So the only bit remaining for me was to configure asterisk. I just copied files over from my old Asterisk server and got it going. The only issues I had;<\/p>\n<ul>\n<li>I needed to use the <a href=\"http:\/\/asterisk.hosting.lv\/\">g729 codec from http:\/\/asterisk.hosting.lv\/<\/a>. That just requires dropping the library file in the right directory and restarting asterisk.<\/li>\n<\/ul>\n<ul>\n<li> I found I had to change the asterisk.conf file so that it had the following change;astdatadir =&gt; \/usr\/share\/asterisk<br \/>\nDebian seems to put all the sounds and music on hold data under \/usr\/share\/asterisk (instead of \/var\/lib\/asterisk). I had some ulaw and g729 sounds on the old server, so I copied those into \/usr\/share\/asterisk\/sounds<\/li>\n<\/ul>\n<p>And that is pretty much it. What an endeavour. In hindsight, if I had counted the cost of all the effort put in to get this working on a non-PAE CPU, it would have been easier to just buy a newer system with a PAE CPU.<\/p>\n<p>UPDATE: I used the simple venet networking when I initially set up the Asterisk virtual machine. Unfortunately, the VM would work for a few hours and then either lose its default route or be unable to get responses to DNS requests &#8230; so I ended up converting the VM to veth networking using the notes <a href=\"http:\/\/wiki.openvz.org\/Using_veth_and_brctl_for_protecting_HN_and_saving_IP-adresses\">here<\/a> and <a href=\"http:\/\/wiki.openvz.org\/Virtual_Ethernet_device\">here<\/a>. It now works much better.<\/p>\n<p>UPDATE: I noticed after doing this, that an apt-get update\/upgrade may end up trying to download a kernel with the same name as the one I compiled. There should be a way around this, but for now I&#8217;m doing the following to prevent my kernel and headers being overwritten (NB: You may have to undo the change below in order to install a new self-compiled kernel. You probably just need to change &#8216;hold&#8217; to &#8216;install&#8217; to undo the change below);<\/p>\n<blockquote><p># echo &#8220;linux-headers-2.6.26-1-openvz-686 hold&#8221; | dpkg &#8211;set-selections<br \/>\n# echo &#8220;linux-image-2.6.26-1-openvz-686 hold&#8221; |dpkg &#8211;set-selections<\/p><\/blockquote>\n<p>UPDATE: I had problems with DNS lookups occasionally hanging from within the OpenVZ virtual machine. If I did a &#8216;cat \/proc\/user_beancounters&#8217; from inside the virtual machine, the failcnt column would have a non-zero number against the dgramrcvbuf.\u00a0 Apparently this has something to do with udp buffers. As a quick workaround I did this to double the barrier limit for that parameter;<\/p>\n<blockquote>\n<pre>sudo vzctl set 102 --dgramrcvbuf $((262144*2)) --save<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This post started out as a simple howto for installing Asterisk in an OpenVZ container on Debian Lenny. It all started out well, as a test box I used my core2duo server running Debian Lenny, did an apt-get of the openvz kernel image that is already in the Lenny standard repository, downloaded an OpenVZ template [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,3],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-asterisk","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":35,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":180,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions\/180"}],"wp:attachment":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}