<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>64k &#187; Gentoo</title>
	<atom:link href="http://www.64k-tec.de/tag/gentoo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.64k-tec.de</link>
	<description>Software development and more ...</description>
	<lastBuildDate>Tue, 10 Jan 2012 21:58:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using suppression files with Valgrind</title>
		<link>http://www.64k-tec.de/2010/10/using-suppression-files-with-valgrind/</link>
		<comments>http://www.64k-tec.de/2010/10/using-suppression-files-with-valgrind/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 19:10:22 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[leak check]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[memory checker]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[suppression lists]]></category>
		<category><![CDATA[symbol names]]></category>
		<category><![CDATA[Valgrind]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=1195</guid>
		<description><![CDATA[Valgrind is one of the great tools in the long list of freely available applications for development. Beside several profiling tools it also contains a memory checker. Leaking memory is one of the more common errors a programmer could step into. Basically it means to forget freeing memory (or in a more general sense: any [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://valgrind.org/" target="_blank">Valgrind</a> is one of the great tools in the long list of freely available applications for development. Beside several profiling tools it also contains a memory checker. <a href="http://en.wikipedia.org/wiki/Memory_leak" target="_blank">Leaking memory</a> is one of the more common errors a programmer could step into. Basically it means to forget freeing memory (or in a more general sense: any resource) a program has acquired. If you are a perfect developer, this will never happen to you. If you are a good developer it may happen and that's where Valgrind will save you some trouble. As most of the developers out there are more or less good developers, their programs produce memory leaks, too <img src='http://www.64k-tec.de/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . The right solution for this, is of course to write a bug report. But there are times where this isn't possible or you are in hurry and don't want to see all the errors of a third-party library you link against.</p>
<p>In the following post, I will show how to suppress such unwanted error messages to make it much more easier to analyze the output of Valgrind for your own application.</p>
<h2>Installing Valgrind</h2>
<p>On Mac OS X you can use MacPorts to install Valgrind. You have to use valgrind-devel if you are on Snow Leopard, because Snow Leopard is supported in the current development version only. It's as simply as typing <code>sudo port install valgrind-devel</code>.</p>
<p>On Gentoo it can become a bit harder. The current stable version is 3.5 (like in MacPorts). If you try this version (at least on an unstable Gentoo like mine) with <code>valgrind ls</code>, you will get the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld-linux-x86-64.so.2
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-x86-64.so.2
valgrind:
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.
valgrind:
valgrind:  Cannot continue -- exiting now.  Sorry.</pre></div></div>

<p>The reason is a striped glibc. To work properly, Valgrind needs to overwrite some of the system functions the glibc provide. It does this by getting the symbols by name out of this library. This is of course not possible if all the symbol names are removed. You can prove this by executing <code>nm /lib/ld-linux-x86-64.so.2</code>. Gentoo provides a <em>FEATURE=splitdebug</em>, which adds debug libraries to the installation. Unfortunately setting this feature in <code class="path">/etc/make.conf</code>, means setting it global. Gentoo is known as being configurable as no other distribution out there and of course we can set a feature for one program only. To do so, create a file called <code class="path">glibc</code> in <code class="path">/etc/portage/env/sys-libs/</code> and add the following content to it.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">FEATURES</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;splitdebug&quot;</span></pre></div></div>

<p>After a rebuild of glibc by executing <code>emerge --oneshot glibc</code>, we have a working Valgrind.</p>
<p>As all programs, Valgrind isn't perfect. Version 3.5 shows many false/positive hits on my system, but fortunately the development goes on. Currently there is no newer version available in the Gentoo tree. Anyway it is not necessary to build one yourself, to get a more recent version. Using <strong>layman</strong> and the overlay tree of <a href="http://gentoo-overlays.zugaina.org/flameeyes-overlay/dev-util.html.en" target="_blank">Flameeyes</a> will let you integrate the development version of Valgrind seamlessly into your system. For a general How-to of layman check out this <a href="http://www.gentoo.org/proj/en/overlays/userguide.xml" target="_blank">Users' guide</a>. In short, something like the following should be sufficient:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">layman <span style="color: #660033;">-a</span> flameeyes-overlay
layman <span style="color: #660033;">-s</span> flameeyes-overlay
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;=dev-util/valgrind-9999 **&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>portage<span style="color: #000000; font-weight: bold;">/</span>package.keywords
emerge <span style="color: #c20cb9; font-weight: bold;">valgrind</span></pre></div></div>

<p>Installing the development version of Valgrind is optional of course.</p>
<h2>Know your tools</h2>
<p>One usage of Valgrind could be look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">valgrind</span> <span style="color: #660033;">--leak-check</span>=full <span style="color: #660033;">--leak-resolution</span>=high .<span style="color: #000000; font-weight: bold;">/</span>VirtualBox</pre></div></div>

<p>Beside other errors it also shows this error message on my system:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">==27174==    at 0x4C26C09: memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==27174==    by 0x4C26CB9: posix_memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==27174==    by 0xBA8967F: ??? (in /usr/lib64/libglib-2.0.so.0.2400.2)
==27174==    by 0xBA89E9D: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.2400.2)
==27174==    by 0xBA89F86: g_slice_alloc0 (in /usr/lib64/libglib-2.0.so.0.2400.2)
==27174==    by 0xC204847: g_type_create_instance (in /usr/lib64/libgobject-2.0.so.0.2400.2)
==27174==    by 0xC1EB8A5: ??? (in /usr/lib64/libgobject-2.0.so.0.2400.2)
==27174==    by 0xC1ECE5D: g_object_newv (in /usr/lib64/libgobject-2.0.so.0.2400.2)
==27174==    by 0xC1ED494: g_object_new (in /usr/lib64/libgobject-2.0.so.0.2400.2)
==27174==    by 0x72A495F: ??? (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x72A0D4F: ??? (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x7289264: QGtkStyle::QGtkStyle() (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x7215DB6: QStyleFactory::create(QString const&amp;amp;) (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x6F5B7FC: QApplication::style() (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x6F61DFF: QApplicationPrivate::initialize() (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x6F61E88: QApplicationPrivate::construct(_XDisplay*, unsigned long, unsigned long) (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x6F61FF3: QApplication::QApplication(_XDisplay*, int&amp;amp;, char**, unsigned long, unsigned long, int) (in /usr/lib64/qt4/libQtGui.so.4.6.3)
==27174==    by 0x44BC38: TrustedMain (main.cpp:371)
==27174==    by 0x44C649: main (main.cpp:651)</pre></div></div>

<p>If you analyze the backtrace, you see that something in <em>libQtGui</em> is leaking memory. I don't want to blame someone for it or make a statement if this is right or wrong, I just want to get rid of it, to be able to easily spot errors VirtualBox itself produce. To do so, add <code>--gen-suppressions=all</code> to the Valgrind call. This will produce something similar like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">{
 Memcheck:Leak
 fun:memalign
 fun:posix_memalign
 obj:/usr/lib64/libglib-2.0.so.0.2400.2
 fun:g_slice_alloc
 fun:g_slice_alloc0
 fun:g_type_create_instance
 obj:/usr/lib64/libgobject-2.0.so.0.2400.2
 fun:g_object_newv
 fun:g_object_new
 obj:/usr/lib64/qt4/libQtGui.so.4.6.3
 obj:/usr/lib64/qt4/libQtGui.so.4.6.3
 fun:_ZN9QGtkStyleC1Ev
 fun:_ZN13QStyleFactory6createERK7QString
 fun:_ZN12QApplication5styleEv
 fun:_ZN19QApplicationPrivate10initializeEv
 fun:_ZN19QApplicationPrivate9constructEP9_XDisplaymm
 fun:_ZN12QApplicationC1EP9_XDisplayRiPPcmmi
 fun:TrustedMain
 fun:main
}</pre></div></div>

<p>To let Valgrind ignore this error in the future, copy the text into a file vbox.supp and start Valgrind with <code>--suppressions=vbox.supp</code>. Viola, this specific error isn't shown anymore. The format used there is easy to understand and you can of course tweak this much more. E.g. you could replace some of the <code>fun:</code> entries by "<code>...</code>". This is a placeholder for one or more functions calls with any name. Beside making suppression rules more general you can of course add as much as you like. Adding a name at the top make it easy to identify the different rules. For all the possibilities have a look at the <a href="http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles" target="_blank">documentation</a>. Just for the curious, Valgrind is using such a file itself. Have a look at /usr/lib/valgrind/default.supp. You may also have noted that the function names in the normal error message differ  from the one in the suppression list. The former is in the <a href="http://en.wikipedia.org/wiki/Name_mangling" target="_blank">demangled</a> form  and the later in the saved form. You could force Valgrind to print  mangled function names by adding the <code>--demangle=no</code> parameter to the call. This becomes handy if you manually create suppression lists.</p>
<h2>Conclusion</h2>
<p>By using suppression rules for the own application, unimportant errors could be eliminated in the output of Valgrind. With this is in mind there is no excuse anymore for memory leaks in the self developed applications. Beside memory leaks, Valgrind also finds places where uninitialized variables are in use or where memory is used which isn't allocated by the application. Also these tests could be filtered out by suppression rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/10/using-suppression-files-with-valgrind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Linux on a USB hard disk for the MacBook Pro</title>
		<link>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/</link>
		<comments>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 02:29:11 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[Boot Camp]]></category>
		<category><![CDATA[EFI]]></category>
		<category><![CDATA[FireWire]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[hard disk]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacBook Pro]]></category>
		<category><![CDATA[removable media]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=885</guid>
		<description><![CDATA[One of the features of Mac OS X I love, is the possibility to install Mac OS X on any attached removable media, like a FireWire or USB hard disk. This makes it really easy for me to test VirtualBox on the several versions of Mac OS X we support (formerly Tiger, now Leopard and [...]]]></description>
			<content:encoded><![CDATA[<p>One of the features of Mac OS X I love, is the possibility to install Mac OS X on any attached removable media, like a FireWire or USB hard disk. This makes it really easy for me to test VirtualBox on the several versions of Mac OS X we support (formerly Tiger, now Leopard and Snow Leopard). The advantage of this setup is that I don't waste disk space for operation systems I usually don't use very often. Currently I have a 150GB hard disk in my MacBook Pro which is really not that much if you deal in the virtualization business. There are several test VM's of any kind of guest operation systems and of course the ISO's to install them. The second main OS, I do much of my work, is Linux. For this I have a standard PC with Gentoo on it, which have all that I need. Unfortunately this doesn't really help when I on travel. As I soon be away for some time, I decided I need, at least for testing, the same flexibility mentioned above for a Linux installation. And here the problems start to arise. Of course Apple didn't really support installing other OS's than Mac OS X on Apple hardware. Yes, there is Boot Camp, but this is mainly for Windows, is very inflexible and doesn't really help if you try to install something on another place than the integrated hard disk. There are projects like <a href="http://refit.sourceforge.net/" target="_blank">rEFIt</a>, which even makes Boot Camp superfluous, but this project has really bad USB boot support. In the following I will explain how it is even possible to install Ubuntu 9.10 on a USB hard disk.</p>
<p>The hardware used, as already said, is a MacBook Pro 3,1 and a Western Digital My Passport Essential 500GB USB hard disk. Other combination may work, but I don't guarantee this, as always. Also you should be warned that anything I describe here could destroy your existing installation and I'm not responsible for that. Doing some kind of backup might be a good idea. Time Machine is easy to use <img src='http://www.64k-tec.de/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Before we start, as usual, the credits for some sites I get my information from. This is mainly the <a href="http://www.produnis.de/blog/?p=678" target="_blank">Produnis blog</a>, <a href="http://blog.christophersmart.com/2009/07/23/linux-on-an-apple-xserve-efi-only-machine/" target="_blank">the Blog of Chris</a>, the <a href="https://wiki.ubuntu.com/MactelSupportTeam/CommunityHelpPages" target="_blank">Ubuntu wiki</a> and of course the guys around the <a href="http://grub.enbug.org/TestingOnMacbook" target="_blank">Grub2</a> development.</p>
<h2>Creating the EFI boot loader</h2>
<p>Apple doesn't use the legacy BIOS to boot their machines, they use the <a href="http://en.wikipedia.org/wiki/Extensible_Firmware_Interface" target="_blank"><em>Extensible Firmware Interface</em></a> (EFI). This new way of booting operation systems is very flexible, as the name suggest, but has several drawbacks, like most of the standard operation system doesn't speaks it language. Although Linux can be configured to use EFI directly we will emulate a legacy BIOS in the following. For this we need a connector which makes EFI and Linux happy and let them both work smoothly together. This connector is <a href="http://www.gnu.org/software/grub/" target="_blank">Grub2</a>, which is in development for several years now. It's the successor of Grub and is the standard in many popular Linux distributions these days. We have to build a version our self, for which an existing Linux installation is really helpful. I used my 64-bit Gentoo installation. First you have to find out if the EFI installation on your target Apple machine is 64 or 32-bit. You can do this by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ioreg <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> IODeviceTree <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> firmware-abi</pre></div></div>

<p>This will return EFI64 or EFI32 respectively. In my case I need the 64-bit version, which is a little bit surprising when I consider that my MacBook Pro isn't able to boot a 64-bit Snow Leopard. Anyway, grab the <a href="ftp://alpha.gnu.org/gnu/grub/grub-1.98.tar.gz">latest version</a> of Grub2 and unpack it on the Linux machine. Please note that you need a gcc with multilib support if you are targeting an architecture which isn't the same as the host one. Use the following to configure Grub2 and to build it. Of course you have to adjust the target architecture if it is a different one.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-platform</span>=efi <span style="color: #660033;">--target</span>=x86_64 <span style="color: #660033;">--disable-werror</span>
<span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>When this is finished you create the EFI package by executing<a name="mkimage"></a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>grub-mkimage <span style="color: #660033;">-d</span> . <span style="color: #660033;">-o</span> bootx86.efi <span style="color: #000000; font-weight: bold;">*</span>.mod</pre></div></div>

<p>Here I included all modules which are available. If size matter for you, you could of course make a selective choice on the modules included. I didn't test this myself, so you have to find out yourself which one are important.</p>
<h2>Whipping the USB hard disk into shape</h2>
<p style="text-align: left;">Next we have to prepare the USB hard disk for the new installation. In the following I assume your USB hard disk doesn't contain any valid data and could be reformatted without data lose. Make a backup of your data first if this isn't the case on your side. Apple uses the <a href="http://en.wikipedia.org/wiki/GUID_Partition_Table" target="_blank">GUID Partition Table</a> scheme to organize their partitions on a hard disk. This specification is part of EFI and remove many limitations of the <em><a href="http://en.wikipedia.org/wiki/Master_Boot_Record" target="_blank">Master boot record</a></em> (MBR) scheme, which is widely used in the PC world. That is e.g. the disk size limitation of 2TB or the maximum of 4 primary partitions. You reformat your disk, using the Disk Utility application of Mac OS X. Make sure all existing partitions on the disk are unmounted. When necessary, change the partition scheme from MBR to GUID in the Options dialog of the Partitions window. Select the partitions count you want to use. You need at least 3 partitions to make Linux works fine. My partition scheme looks like in the following: <a href="/wordpress/wp-content/uploads/Disk-Utility.png"><img class="aligncenter size-full wp-image-972" title="GUID Partition Table scheme" src="/wordpress/wp-content/uploads/Disk-Utility.png" alt="" width="188" height="390" /></a>As you can see I have 5 partitions configured. The first one is an additional Snow Leopard installation for testing. I also added a Data partition at the end for making the data transfer between the different operation systems as easy as possibly. LINUXBOOT is a small partition which will contain the EFI boot loader (size it 50MB or something like that). Linux Swap, obviously, will become the swap partition of the Linux installation. DISK1S5 is the Linux root partition itself. The Data partition has to be formated as Mac OS Extended. Don't use the Journaled version of HFS+, cause this makes trouble on the Linux side. The other partitions have to be formatted as MS-DOS (FAT).</p>
<p>After applying the changes we can add the EFI boot loader to the LINUXBOOT partition. The Apple EFI implementation is searching for a file with the efi extensions on all bootable hard disks. Mount LINUXBOOT and create a <code class="path">efi/boot</code> directory on the root path. Copy the <a href="#mkimage">bootx86.efi</a> file into the boot/ directory. As bootx86.efi is a Grub2 boot loader we need a valid Grub2 configuration file. The following <code class="path">grub.cfg</code> shows the configuration for a Ubuntu 9.10 i386 installation. For the 64-bit version or any other version of Ubuntu the settings might be slightly different.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">menuviewer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;text&quot;</span>
<span style="color: #000099;">timeout</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">10</span>
<span style="color: #000099;">default</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
set F1<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">ctrl-x</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro quiet splash noefi video=efifb</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386 single&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro noefi video=efifb single</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386 text&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro noefi vga=normal</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;Mac OS X&quot;</span>
<span style="">&#123;</span>
 search --set -f /usr/standalone/i386/boot.efi
 chainloader /usr/standalone/i386/boot.efi
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;CD&quot;</span>
<span style="">&#123;</span>
 appleloader CD
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;mbr&quot;</span>
<span style="">&#123;</span>
 appleloader HD
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;reboot&quot;</span>
<span style="">&#123;</span>
 reboot
<span style="">&#125;</span></pre></div></div>

<p>You have to change the root UUID to the one the Ubuntu installer will assign to your hard disk after installation. Just check the fstab file when the installation has finished. The first entry boots Linux with a splash image enabled. The second one is for the single user mode in the case something went wrong. Please note the <strong>video=efifb</strong> option, which enables the graphical mode in the boot phase.</p>
<h2>Installing Ubuntu</h2>
<p>Most of the installation process is straight forward and doesn't need any special attention. Download the version of your choice from one of the mirrors, burn it on CD and start the installation. You can select the CD as boot medium by pressing <code class="key">Alt</code> when your Mac starts. When the installer ask for the partition scheme, you have to switch to "manual choice". Select the DISK1S5 (your what it is in your case) as the root / partition and change the filesystem type to ext3. Also remember the path to the system partition, cause you will need it later again. Select the swap partition and change its type to swap. Proceed with the rest of the installation until the last dialog. There select "advanced settings" and change the boot loader target from <code class="path">hd0</code> to <code class="path">/dev/sdXX</code>, where you replace XX to the path you used previously in the partition tool.</p>
<p>If all went right you should be able to select the LINUXBOOT partition by pressing <code class="key">Alt</code> when your Mac starts. After that Grub2 should shows up, you will be able to boot into your freshly installed Ubuntu.</p>
<h2>Conclusion</h2>
<p>In this post I showed how to easily add the possibility to boot Linux on your MacBook Pro. With the external USB hard disk solution, no internal valuable space is wasted. Of course the speed isn't the same as if the OS would be installed on the internal drive, but for testing software on different operation systems this is satisfactory. To increase the speed a little bit more, an external FireWire hard disk could be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FRITZ!Box tuning part 2: Access your home network with OpenVPN</title>
		<link>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/</link>
		<comments>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 18:38:47 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[FritzBox]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[remote access]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=379</guid>
		<description><![CDATA[AVM has built a VPN server into the FRITZ!Box, why should I use some other software for this job, you may ask. The reason is quite simple: the build in one is a piece of closed source software written by AVM and there is only one official client which could be used to connect to [...]]]></description>
			<content:encoded><![CDATA[<p>AVM has built a VPN server into the FRITZ!Box, why should I use some other software for this job, you may ask. The reason is quite simple: the build in one is a piece of closed source software written by AVM and there is only one official client which could be used to connect to it, the FRITZ!VPN software. This client software is only available for the Windows operation system family and so by no means anything useful to me. I'm pretty sure they are using some official protocol like <a href="http://en.wikipedia.org/wiki/IPsec" target="_blank">IPSec</a>, so it might be possible to connect to the FRITZ!Box with other clients as well, but that's something I didn't want to try. <a href="http://openvpn.net" target="_blank">OpenVPN</a> on the other side is a rock solid open source software which could be used from many popular OS's these days. Even graphical clients, like <a href="http://code.google.com/p/tunnelblick/" target="_blank">TunnelBlick</a> for Mac OS X, are available. So here comes the second article of the FRITZ!Box tuning <a href="/?s=FRITZ!Box+tuning">series</a>, which will explain how to convert your FRITZ!Box into a OpenVPN server, where any number of clients can concurrently be connected. I highly recommend to read the <a href="http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/">first part</a> of this series, because this post is build on top of the stuff done there. This count especially for the filesystem layout on the usbstick and the way additional software is started. Also in the following it will be helpful to have ssh access to the FRITZ!Box all the time. As already written in the first part, there is no guarantee that the information presented here will work on your side or that I'm responsible for anything happen to your FRITZ!Box. In preparation of the following you need access to a second OpenVPN installation which will be used to create all necessary certificates and keys and which could be used to test the installation afterward. I'm using a Gentoo Linux host where you could install OpenVPN simply by executing <code>emerge openvpn</code>. Make sure you have the <strong>examples</strong> USE flag set to get all the helper scripts which make the life much more easier.</p>
<h2>The agony of choice</h2>
<p>OpenVPN could be configured in many different ways. So first of all we have to decide which features of OpenVPN we will use. In its simplest variant OpenVPN could be used with one preshared static key. The advantage of this setup type is the easy configuration. The disadvantage is that only one client could be connected at the time. That is not what we want, so we will configure our setup to be using a <a href="http://en.wikipedia.org/wiki/Public_key_infrastructure" target="_blank">Public Key Infrastructure</a> (PKI). This allows more than one client to be connected at the time and it is possible to mark single keys invalid without affecting other client keys. The second question which has to be answered is, if we want use routing or bridging in our setup. Again, routing is simpler to set up and also a little bit faster than bridging. Bridging on the other side allows the tunneling of non IP protocols such as IPX, tunnel all the IP broadcast and make it possible to use the same subnet on the client side as on the server-side. Especially the last point is a nice feature as with routing all hosts on the server-side needs a routing table entry to find the connected clients. But my main reason for preferring bridging over routing is the broadcast feature of the first one. In my home network works a NAS station as a file server. This includes of course simple filesystem sharing with AFP and NFS, but also serves this box audio data with the <a href="http://en.wikipedia.org/wiki/Digital_Audio_Access_Protocol" target="_blank">Digital Audio Access Protocol</a> (DAAP). DAAP is used by Apple in iTunes to share music with other clients in the network and that is what my NAS station does. This protocol, as well AFP, using broadcast messages (ZeroConf) to find some potential clients. So now it should be clear why I want bridging, it allows me to hear music or to simply connect to my file station without any interaction.</p>
<h2>Building up a PKI</h2>
<p>To create all necessary certificates and keys we are using the <em>easy-rsa</em> scripts from OpenVPN. They are located under <code class="path">/usr/share/openvpn/easy-rsa</code>. First we change the <code class="path">vars</code> file. On the bottom of the file are personal information defined which should be changed to fit to your environment. The entries looking as follow on my side (with a pseudo email address).</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">export KEY_COUNTRY<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;DE&quot;</span>
export KEY_PROVINCE<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Sachsen&quot;</span>
export KEY_CITY<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Dresden&quot;</span>
export KEY_ORG<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;64k&quot;</span>
export KEY_EMAIL<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;you@yourdomain.org&quot;</span></pre></div></div>

<p>You could also increase the <strong>KEY_SIZE</strong> from 1024 to 2048 within that file. This should make your keys unbreakable for the next few <span style="text-decoration: line-through;">decades</span> years. Now we are ready to create the master-key and the master certificate of the Certificate Authority (CA) by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> vars
.<span style="color: #000000; font-weight: bold;">/</span>clean-all
.<span style="color: #000000; font-weight: bold;">/</span>build-ca</pre></div></div>

<p>Please be aware that this will delete all previously created keys. Answering all questions with the default values should be sufficient. Next the key for the server has to be created.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key-server server</pre></div></div>

<p>You can again accept all default values. A challenge password is not necessary, but you have to sign the certificate. Now its time for our first client key and certificate. You could the following repeat again and again, for every new client you want allow to access the OpenVPN server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key client</pre></div></div>

<p>Again, don't forget to sign the key. If you ever have to mark a client certificate invalid you could do it with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>revoke-full client</pre></div></div>

<p>This will create or update a Certificate Revocation List (CRL)<em> </em> file which will be later used by the server to verify the certificate integrity of a connecting client. For now we create an empty one with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">KEY_CN</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">KEY_OU</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">KEY_NAME</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">$OPENSSL</span> ca <span style="color: #660033;">-gencrl</span> <span style="color: #660033;">-out</span> keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem <span style="color: #660033;">-config</span> <span style="color: #007800;">$KEY_CONFIG</span></pre></div></div>

<p>The last step in this key building marathon is to create a <a href="http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange" target="_blank">Diffie-Hellman</a> key. This key will be used to initiate the secure channel between the two parties. Its created by:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-dh</pre></div></div>

<h2>Creating the server and client configuration</h2>
<p>We start with the configuration of the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># set the path to the tap device</span>
dev tap
dev-node <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>tap0
mssfix
tun-mtu <span style="color: #000000;">1500</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># TCP or UDP server?</span>
proto udp
port <span style="color: #000000;">1194</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># CA and key files</span>
ca <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
cert <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>server.crt
key <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>server.key
crl-verify <span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem <span style="color: #666666; font-style: italic;"># this is opened after the chroot</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Diffie hellman parameters</span>
<span style="color: #c20cb9; font-weight: bold;">dh</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>dh1024.pem
&nbsp;
<span style="color: #666666; font-style: italic;"># bridge setup</span>
server-bridge 192.168.220.1 255.255.255.0 192.168.220.50 192.168.220.99
mode server
tls-server
push <span style="color: #ff0000;">&quot;dhcp-option DNS 192.168.220.1&quot;</span>
&nbsp;
ifconfig-pool-persist ipp.txt
client-to-client
&nbsp;
<span style="color: #666666; font-style: italic;"># compression?</span>
comp-lzo
&nbsp;
<span style="color: #666666; font-style: italic;"># The maximum number of concurrently connected clients we want to</span>
<span style="color: #666666; font-style: italic;"># allow.</span>
max-clients <span style="color: #000000;">20</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># It's a good idea to reduce the OpenVPN daemon's privileges after</span>
<span style="color: #666666; font-style: italic;"># initialization.</span>
user nobody
group nobody
&nbsp;
<span style="color: #666666; font-style: italic;"># Put openvpn in a jail.</span>
<span style="color: #c20cb9; font-weight: bold;">chroot</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn
&nbsp;
<span style="color: #666666; font-style: italic;"># The persist options will try to avoid accessing certain resources on</span>
<span style="color: #666666; font-style: italic;"># restart that may no longer be accessible because of the privilege</span>
<span style="color: #666666; font-style: italic;"># downgrade.</span>
persist-key
persist-tun
&nbsp;
<span style="color: #666666; font-style: italic;"># where to log</span>
log-append <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>openvpn.log
&nbsp;
<span style="color: #666666; font-style: italic;"># verbose level for debugging</span>
;verb <span style="color: #000000;">4</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># make sure the connection is kept alive</span>
keepalive <span style="color: #000000;">10</span> <span style="color: #000000;">120</span></pre></div></div>

<p>For bridged mode it is essential that OpenVPN uses a TAP device and not the TUN device mode (see <a href="http://en.wikipedia.org/wiki/TUN/TAP" target="_blank">here</a> for the reason). We use UDP as the transport protocol and enable compression. Also we want that OpenVPN drops its privileges after the initialization and chroot into a jail to make it a little bit more secure. As the subnet for clients 192.168.220.0/24 is used. That is the same as my internal network uses. OpenVPN is allowed to use addresses ranging from 192.168.220.50 to 192.168.220.99. You have to make sure that the FRITZ!Box (or any other DHCP server in your network) doesn't serve addresses from that range. Of course you could change some of the settings to your needs, but then you have to make sure they match the configuration of the client.</p>
<p>Next we create the client configuration, which looks as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Specify that we are a client and that we will be pulling certain</span>
<span style="color: #666666; font-style: italic;"># config file directives from the server.</span>
client
&nbsp;
<span style="color: #666666; font-style: italic;"># The hostname/IP and port of the server.</span>
remote xtestx.dyndns.org <span style="color: #000000;">1194</span>
&nbsp;
proto udp
dev tap
&nbsp;
pull
&nbsp;
mssfix
tun-mtu <span style="color: #000000;">1500</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># SSL/TLS parms.</span>
tls-client
ca keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
cert keys<span style="color: #000000; font-weight: bold;">/</span>client.crt
key keys<span style="color: #000000; font-weight: bold;">/</span>client.key
&nbsp;
ns-cert-type server
&nbsp;
<span style="color: #666666; font-style: italic;"># Keep trying indefinitely to resolve the host name of the OpenVPN</span>
<span style="color: #666666; font-style: italic;"># server. Very useful on machines which are not permanently connected</span>
<span style="color: #666666; font-style: italic;"># to the Internet such as laptops.</span>
resolv-retry infinite
&nbsp;
<span style="color: #666666; font-style: italic;"># Don't enable this; It must be disabled for iTunes to find the iTunes</span>
<span style="color: #666666; font-style: italic;"># server and for AFP broadcast in general.</span>
<span style="color: #666666; font-style: italic;">#nobind</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Downgrade privileges after initialization (non-Windows only)</span>
user nobody
group nobody
&nbsp;
<span style="color: #666666; font-style: italic;"># Try to preserve some state across restarts.</span>
persist-key
persist-tun
&nbsp;
<span style="color: #666666; font-style: italic;"># Enable compression on the VPN link.</span>
comp-lzo
&nbsp;
<span style="color: #666666; font-style: italic;"># debug level</span>
;verb <span style="color: #000000;">4</span>
&nbsp;
mute-replay-warnings
mute <span style="color: #000000;">20</span></pre></div></div>

<p>You have to change the <em>remote</em> hostname to your needs. You may also add the full path to the certificates and keys depending on your client OpenVPN installation.</p>
<p>Next we pack all files up for the server and the client respectively. The server needs the following one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server.conf
keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem
keys<span style="color: #000000; font-weight: bold;">/</span>dh1024.pem
keys<span style="color: #000000; font-weight: bold;">/</span>server.crt
keys<span style="color: #000000; font-weight: bold;">/</span>server.key</pre></div></div>

<p>The client needs this one:<a name="client_pack"></a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">client.conf
keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
keys<span style="color: #000000; font-weight: bold;">/</span>client.crt
keys<span style="color: #000000; font-weight: bold;">/</span>client.key
keys<span style="color: #000000; font-weight: bold;">/</span>server.crt</pre></div></div>

<h2>Customizing the FRITZ!Box</h2>
<p>Connect to your FRITZ!Box and copy all the server files to the usbstick. I created a directory <code class="path">openvpn</code> under the <code class="path">/var/media/ftp/FLASH-DISK-01/addons</code> path. Next we need the OpenVPN binary for the FRITZ!Box. You can get it <a href="http://www.cswpro.de/_files/openvpn_kernel_2_6.zip">here</a>. Unpack the file and copy the openvpn binary to <code class="path">/var/media/ftp/FLASH-DISK-01/addons/bin</code> on the FRITZ!Box. Make sure the file mode has the executable bit set for the user. All files are now on the right places, so we can adjust our start script. Add the following code to the <code class="cmd">startup.sh</code> file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Add a nobody user</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'nobody:x:65534:65534:nobody:/:/bin/false'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Add some groups</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'root:x:0:'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>group
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'nobody:x:65534:'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>group
&nbsp;
<span style="color: #666666; font-style: italic;"># Create a tap device for openvpn</span>
<span style="color: #c20cb9; font-weight: bold;">mknod</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>tap0 c <span style="color: #000000;">10</span> <span style="color: #000000;">200</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Start openvpn</span>
<span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>openvpn <span style="color: #660033;">--config</span> <span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>server.conf <span style="color: #660033;">--daemon</span></pre></div></div>

<p>As you see, we add a new <em>nobody</em> user to the Linux system. Then the device node for the TAP device is created and at the end the OpenVPN server is started. As we using the bridged setup, we have to add the new device to a bridge. Fortunately we haven't to create one, cause the FRITZ!Box itself is working in bridged mode. You can confirm this by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brctl show lan</pre></div></div>

<p>To let the system automatically add our TAP device to the <em>lan</em> bridge, we change the internal FRITZ!Box configuration. Edit the <code class="path">/var/flush/ar7.cfg</code> file with nvi and search for the string <em>brinterfaces</em>. There should be one section with the name <em>lan</em>. Simply add the new <em>tap0</em> interface to the interfaces value. The section should then look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">brinterfaces <span style="">&#123;</span>
     <span style="color: #000099;">name</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;lan&quot;</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcp</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> no</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">ipaddr</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.1</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">netmask</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 255.255.255.0</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dstipaddr</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0.0.0.0</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">interfaces</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;eth0&quot;</span>, <span style="color: #933;">&quot;ath0&quot;</span>, <span style="color: #933;">&quot;tap0&quot;</span>, <span style="color: #933;">&quot;wdsup1&quot;</span>, <span style="color: #933;">&quot;wdsdw1&quot;</span>,
                  <span style="color: #933;">&quot;wdsdw2&quot;</span>, <span style="color: #933;">&quot;wdsdw3&quot;</span>, <span style="color: #933;">&quot;wdsdw4&quot;</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpenabled</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> yes</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpstart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.100</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpend</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.200</span><span style="color: #666666; font-style: italic;">;</span>
<span style="">&#125;</span></pre></div></div>

<p>Now, as soon the tap0 interface is created it will be added to the bridge. The last important point in the server setup is to change the internal firewall to allow connections to port 1194 from the outside. Search for <em>forwardrules</em> in the <code class="path">ar7.cfg</code> file and add this new rule:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">forwardrules</span> <span style="color: #000066; font-weight:bold;">=</span>
               <span style="color: #933;">&quot;tcp 0.0.0.0:7777 0.0.0.0:22 0 # SSH-Server&quot;</span>,
               <span style="color: #933;">&quot;udp 0.0.0.0:1194 0.0.0.0:1194 0 # VPN-Server&quot;</span><span style="color: #666666; font-style: italic;">;</span></pre></div></div>

<p>Thats all for the server. A reboot of the FRITZ!Box should start the new OpenVPN server. If you have trouble you should manually start the OpenVPN server and increase the debugging level, as shown in the above configuration with the keyword <em>verb</em>.</p>
<h2>Setting up the client</h2>
<p>On the client side we need the files we packed <a href="#client_pack">above</a>. On Gentoo the OpenVPN configuration is located at <code class="path">/etc/openvpn</code>. Copy the configuration, the certificates and the key file to that place. The OpenVPN start script of Gentoo looks for the configuration file, based on the start script name. So we have to create a link like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> client.conf openvpn.conf</pre></div></div>

<p>By the way, this lets you configure more than one OpenVPN connection at the time. Just create a link in <code class="path">/etc/init.d</code> with the new configuration name and link it to the <code class="path">openvpn</code> start script.</p>
<p>To make a first attempt to start the OpenVPN connection type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>openvpn start</pre></div></div>

<p>If  all goes well you should have a new device <em>tap0</em> when you  execute <code>ifconfig</code>. Also there should be a route set,  which point to the tap0  device when the 192.168.220.0/24 subnet is the  target. Of course now you should be able to connect to any host in your  home network by the IP. I didn't experiment enough with the pushing of  the name server from the OpenVPN server, instead I just added the  FRITZ!Box as an additionally name server to my <code class="path">/etc/resolv.conf</code>. So here is room for further experiments.</p>
<p>To let the OpenVPN client start at boot time add it to the default runlevel by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rc-update add openvpn default</pre></div></div>

<p>Also note that with the above configuration the client always try to  reconnect to the server, even if the FRITZ!Box is rebooted, which is a nice feature.</p>
<h2>Conclusion</h2>
<p>This setup allows you to connect to your home network in a very secure way without loosing any functionality. You are able to browse network shares on the local network or using services like DAAP without any further interaction.  The public key infrastructure make this setup a candidate for small business installations. If an employee leave the company his certificate is simply revoked without affecting the access of other employees.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1754px; width: 1px; height: 1px; overflow: hidden;"><a href="http://www.cswpro.de/Howto/FritzBox_OpenVPN.aspx" target="_blank">http://wwww.cswpro.de</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

