<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>About Debian</title>
<link>http://mixinet.net/~sto/blog/debian/</link>
<description>StoWiki</description>
<item>
	
	<title>The FreakyWall (Part 3: Packages)</title>
	
	<guid>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/</guid>
	<link>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/</link>
	
	<pubDate></pubDate>
	<description><![CDATA[<p>In this post I'll describe the changes made to the kernel and some of the
Squeeze packages for the <em>Freaky Wall</em>.</p>

<p>The plan is to submit whishlist bugs to the BTS on the hope of having all what
is needed for this project available on Debian after the Squeeze release, as
my feeling is that a freeze is not the right time to push this changes... ;)</p>

<p>I'm giving access here to all the changes made to the source packages, but if
anyone wants the binary packages (amd64 only) send me an email and I'll give
you the URL of an apt repository that contains all the modified packages (it's
the one at work, that contains other modified packages) or, if there is
interest, I can put them on people.debian.org.</p>

<h1>Kernel</h1>

<p>To be able to build the firewall we need a kFreeBSD kernel with some options
not compiled on the version distributed with Debian.</p>

<p>To compile the kernel I've followed the procedure described on the following
debian-bsd mailing list post:</p>

<p><a href="http://lists.debian.org/debian-bsd/2010/09/msg00023.html">http://lists.debian.org/debian-bsd/2010/09/msg00023.html</a></p>

<p>Basically I've done the following:</p>

<pre><code>    apt-get build-dep kfreebsd-8
    apt-get source kfreebsd-8
    cd kfreebsd-8-8.1
    cat &gt;&gt; debian/arch/amd64/amd64.config &lt;&lt; EOF

    # Add pflog, pfsync, ALTQ and CARP support
    # ----------------------------------------

    # http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/firewalls-pf.html
    device      pf
    device      pflog
    device      pfsync

    options         ALTQ
    options         ALTQ_CBQ        # Class Bases Queuing (CBQ)
    options         ALTQ_RED        # Random Early Detection (RED)
    options         ALTQ_RIO        # RED In/Out
    options         ALTQ_HFSC       # Hierarchical Packet Scheduler (HFSC)
    options         ALTQ_PRIQ       # Priority Queuing (PRIQ)
    options         ALTQ_NOPCC      # Required for SMP build

    # http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/carp.html
    device      carp
    EOF
    vi debian/changelog 
    dpkg-buildpackage -B -uc
</code></pre>

<p>Once the package was built I installed the new kernel package and rebooted the
machine.</p>

<h1>Utilities</h1>

<p>To be able to use some utilities related to <code>pf</code> I have built patched
versions of three packages:</p>

<ul>
<li><p><code>freebsd-utils</code>: I have included <code>pflogd</code> and <code>ftp-proxy</code> on the package and
have added some options to allow the use of additional interface types with
<code>ifconfig</code> (<code>carp</code>, <code>pfsync</code>, <code>lagg</code>, <code>bridges</code>, ...).</p>

<p>There were a lot of changes needed:</p>

<ol>
<li><p>The <code>pflogd</code> and <code>ftp-proxy</code> Makefiles are missing from the original
tarball, I modified the <code>get-orig-source</code> of the <code>debian/rules</code>, but I build
my packages against the original tarball, with the extra files included
directly on the package .diff.gz.</p></li>
<li><p>The <code>pflogd</code> daemon needs a <code>_pflogd</code> user and group and a
<code>/var/run/_pflogd</code> directory, so I've added the directory and the creation
of the user and group to the package post-install.</p></li>
<li><p>The <code>ftp-proxy</code> daemon uses the <code>proxy</code> user when dropping privileges and
I've modified the code to make it use the <code>/var/run/ftp-proxy</code> directory for
the chroot.</p></li>
<li><p>Some C header files that are not available on <code>-dev</code> packages were
missing and I put them on the packages' debian directory. I've created a
<code>debian/include</code> directory and moved there the original <code>debian/net</code>
directory and added the headers  <code>debian/include/net/if_bridgevar.h</code> and
<code>debian/include/net/if_lagg.h</code> to add bridging support to <code>ifconfig</code> and the
<code>debian/include/pcap-config.h</code> and <code>debian/include/pcap-int.h</code> libpcap
private headers to be able to compile the <code>pflogd</code> binary.</p></li>
</ol>

<p>As I'm not familiar with the way people changes code for kFreeBSD some of
the patches are a little bit dirty, but at least things work; besides,
probably I should also have had to include init.d scripts for <code>pf</code>, <code>pflogd</code>
and <code>ftp-proxy</code>, but I have not done it at the package level yet, as what I
got was enough to work with the tools.</p>

<p>The debdiff against the <code>freebsd-utils-8.1-2</code> source package is available
<a href="http://mixinet.net/~sto/blog/debian/./20101130_The_FreakyWall_Part_3/patches/freebsd-utils-8.1-2_to_2.4.patch">here</a> or
<a href="http://web.iti.upv.es/~sto/kfreebsd/patches/freebsd-utils-8.1-2_to_2.4.patch">here</a>. </p></li>
<li><p><code>libpcap</code>: A test had to be removed in order to be able to support <code>pflog</code>
on the library; the debdiff against the <code>libpcap-1.1.1-2</code> package is
available <a href="http://mixinet.net/~sto/blog/debian/./20101130_The_FreakyWall_Part_3/patches/libpcap-1.1.1-2_to_2.1.patch">here</a> or
<a href="http://web.iti.upv.es/~sto/kfreebsd/patches/libpcap-1.1.1-2_to_2.1.patch">here</a>.</p></li>
<li><p><code>tcpdump</code>: The package also had to be modified to include the code to print
the <code>pflogd</code> entries on the <code>pcap</code> file; the debdiff against
<code>tcpdump_4.1.1-1</code> is available <a href="http://mixinet.net/~sto/blog/debian/./20101130_The_FreakyWall_Part_3/patches/tcpdump_4.1.1-1_to_1.1.patch">here</a> or
<a href="http://web.iti.upv.es/~sto/kfreebsd/patches/tcpdump_4.1.1-1_to_1.1.patch">here</a>.</p></li>
</ul>

<p>On the next post I'll describe how I've configured the system, the network
interfaces and the different utilities patched and compiled on this post.</p>
]]></description>
</item>
<item>
	
	<title>libpcap-1.1.1-2 to 2.1.patch</title>
	
	<guid>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/libpcap-1.1.1-2_to_2.1.patch</guid>
	<link>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/libpcap-1.1.1-2_to_2.1.patch</link>
	
	<pubDate></pubDate>
	<description><![CDATA[]]></description>
</item>
<item>
	
	<title>tcpdump 4.1.1-1 to 1.1.patch</title>
	
	<guid>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/tcpdump_4.1.1-1_to_1.1.patch</guid>
	<link>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/tcpdump_4.1.1-1_to_1.1.patch</link>
	
	<pubDate></pubDate>
	<description><![CDATA[]]></description>
</item>
<item>
	
	<title>freebsd-utils-8.1-2 to 2.4.patch</title>
	
	<guid>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/freebsd-utils-8.1-2_to_2.4.patch</guid>
	<link>http://mixinet.net/~sto/blog/debian/20101130_The_FreakyWall_Part_3/patches/freebsd-utils-8.1-2_to_2.4.patch</link>
	
	<pubDate></pubDate>
	<description><![CDATA[]]></description>
</item>
<item>
	
	<title>The Freaky Wall (Part 2: Initial Installation)</title>
	
	<guid>http://mixinet.net/~sto/blog/debian/20101124_The_FreakyWall_Part_2/</guid>
	<link>http://mixinet.net/~sto/blog/debian/20101124_The_FreakyWall_Part_2/</link>
	
	<pubDate></pubDate>
	<description><![CDATA[<p>For the <strong>Freaky Wall</strong> I have installed a <strong>Debian GNU/kFreeBSD</strong> system
using the installer with ZFS support announced on:</p>

<p><a href="http://robertmh.wordpress.com/2010/09/06/debian-installer-with-zfs/">http://robertmh.wordpress.com/2010/09/06/debian-installer-with-zfs/</a></p>

<p>I used the <code>mini.iso</code> found on:</p>

<p><a href="http://people.debian.org/~rmh/zfs/kfreebsd-amd64/monolithic/mini.iso">http://people.debian.org/~rmh/zfs/kfreebsd-amd64/monolithic/mini.iso</a></p>

<p>the 12th of October of 2010; as I had some problems and reported them to
Robert is possible that the current image solves part of them.</p>

<h1>Installation plan</h1>

<p>I did a standard installation on a machine with two hard disks, but only used
the first one from the installer.</p>

<p>The plan was to use ZFS with RAID-1, but current versions of <code>grub</code> do not
support booting from a ZFS + RAID file system, so I had to use the same
technique used for Linux for a long time; three partitions: a swap partition,
a small <code>/boot</code> partition and a big partition for <code>/</code>; <code>/</code> and <code>/boot</code> were
formated to use ZFS.</p>

<h1>First reboot</h1>

<p>After the installation the system failed to boot because of a bug when
building the <code>/boot/grub/grub.cfg</code> (some paths were missing a <code>//@</code> prefix);
to be able to boot Iwe edited the config on the grub prompt and later fixed
the file:</p>

<pre><code>    --- grub.cfg.orig       2010-10-13 16:40:39.000000000 +0200
    +++ grub.cfg    2010-10-13 18:38:47.535436766 +0200
    @@ -64,7 +64,7 @@
            set root='(hd0,1)'
            search --no-floppy --fs-uuid --set a371979bb836d1fe
            echo                    'Loading kernel of FreeBSD 8.1-1-amd64 ...'
    -       kfreebsd                /kfreebsd-8.1-1-amd64.gz
    +       kfreebsd                //@/kfreebsd-8.1-1-amd64.gz
            insmod part_msdos
            insmod zfs
            set root='(hd0,3)'
    @@ -75,7 +75,7 @@
            insmod zfs
            set root='(hd0,1)'
            search --no-floppy --fs-uuid --set a371979bb836d1fe
    -       kfreebsd_module         /zfs/zpool.cache type=/boot/zfs/zpool.cache
    +       kfreebsd_module         //@/zfs/zpool.cache type=/boot/zfs/zpool.cache
            set kFreeBSD.vfs.root.mountfrom=zfs:dkfbf1-ad4s3
            set kFreeBSD.vfs.root.mountfrom.options=rw
     }
</code></pre>

<p>I haven't tested the installer since that day, but I believe that the current
ZFS installer was fixed by Robert to deal with that problem.</p>

<p>Once the system was booted I had to fix a couple of things:</p>

<ul>
<li><p>The keyboard configuration was wrong, but it was easy to fix the Debian Way:</p>

<pre><code>dpkg-reconfigure kbdcontrol
</code></pre></li>
<li><p>The <code>/boot</code> partition was mounted on <code>/target/boot</code>, as that was what was
 recorded on the ZFS file system; to fix it I executed the following commands:</p>

<pre><code> # zfs set mountpoint=/     dkfbf1-ad4s3
 # zfs set mountpoint=/boot dkfbf1-ad4s1
</code></pre>

<p>Where <code>dkfbf1-ad4s3</code> is the root file system and <code>dkfbf1-ad4s1</code> is the
 original <code>/boot</code>.</p>

<p>I reported that to Robert also and I believe it is fixed on the ZFS
 installer now.</p></li>
</ul>

<h1>Adjusting ZFS to do RAID-1</h1>

<p>On the second disk I created the same partitions as the ones on the first disk
using <code>parted</code>; the final result was:</p>

<pre><code>    # parted -l     
    Model: ST3250620NS/3BKS (ide)
    Disk /dev/ad6: 250GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  256MB   255MB   primary
     2      256MB   4256MB  4000MB  primary
     3      4256MB  250GB   246GB   primary

    Model: ST3250620NS/3BKS (ide)
    Disk /dev/ad4: 250GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type     File system     Flags
      1      1049kB  256MB   255MB   primary
      2      256MB   4256MB  4000MB  primary  linux-swap(v1)
      3      4256MB  250GB   246GB   primary
</code></pre>

<p>To use the second partition of both disks as swap I added the following to
<code>/etc/fstab</code>:</p>

<pre><code>    /dev/ad4s2      none            swap    sw              0       0
    /dev/ad6s2      none            swap    sw              0       0
</code></pre>

<p>To configure the mirroring for the root file system I did the following:</p>

<pre><code>    zpool attach dkfbf1-ad4s3 ad4s3 ad6s3
</code></pre>

<p>As the <code>/boot</code> can't work as a replica I adjusted it to make two copies of
every file:</p>

<pre><code>    zfs   set copies=2     dkfbf1-ad4s1
</code></pre>

<p>Leaving the second disk copy alone, although my plan is to configure it to
hold a copy of the <code>/boot</code> partition synchronized with <code>rsync</code> each night.</p>

<p>After all those changes the system didn't boot, as the <code>grub-pc</code> generates a
buggy <code>/boot/grub/grub.cfg</code>; the problem is on the <code>/etc/grub.d/10_kfreebsd</code>
section:</p>

<pre><code>    ### BEGIN /etc/grub.d/10_kfreebsd ###
    menuentry 'Debian GNU/kFreeBSD, with kFreeBSD 8.1-1-amd64' --class debian \
      --class gnu-kfreebsd --class gnu --class os {
          insmod part_msdos
          insmod zfs
          set root='(hd0,1)'
          search --no-floppy --fs-uuid --set a371979bb836d1fe
          echo 'Loading kernel of FreeBSD 8.1-1-amd64 ...'
          kfreebsd /kfreebsd-8.1-1-amd64.gz
          set kFreeBSD.vfs.root.mountfrom=unknown:/dev/ad4s3
          set kFreeBSD.vfs.root.mountfrom.options=rw
    }
    ### END /etc/grub.d/10_kfreebsd ###
</code></pre>

<p>To fix it there has to be a copy of the modules for ZFS on the boot partition
(in my case I moved the <code>/lib/modules</code> directory to <code>/boot</code> and created a
link on the root partition to the new directory):</p>

<pre><code>    cd /boot
    mkdir lib
    mv /lib/modules lib
    cd /lib
    ln -s ../boot/lib/modules
</code></pre>

<p>And instead of fixing the <code>/etc/grub.d/10_kfreebsd</code> code I wrote a new
script (<code>/etc/grub.d/09_zfs_kfreebsd</code>) that creates the right config for my
current configuration on the <code>grub.cfg</code> file:</p>

<pre><code>    #!/bin/sh
    prefix=/usr
    exec_prefix=&#036;{prefix}
    bindir=&#036;{exec_prefix}/bin
    libdir=&#036;{exec_prefix}/lib
    . &#036;{libdir}/grub/grub-mkconfig_lib

    prepare_boot_cache="&#036;(prepare_grub_to_access_device &#036;{GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
    kfreebsd_versions="&#036;(ls /lib/modules/)"
    zfs_root_device="&#036;(zfs list | awk '/\/&#036;/ { print &#036;1 }' | head -1)"

    for kversion in &#036;kfreebsd_versions; do
      cat &lt;&lt; EOF
    # Entry when using ZFS (we have issues with /etc/grub.d/10_kfreebsd)
    menuentry 'Debian GNU/kFreeBSD, with kFreeBSD &#036;kversion and ZFS' --class debian --class gnu-kfreebsd --class gnu --class os {
    &#036;{prepare_boot_cache}
          echo                    'Loading kernel of FreeBSD &#036;kversion ...'
          kfreebsd                //@/kfreebsd-&#036;kversion.gz
          kfreebsd_module_elf     //@/lib/modules/&#036;kversion/opensolaris.ko
          kfreebsd_module_elf     //@/lib/modules/&#036;kversion/zfs.ko
          kfreebsd_module         //@/zfs/zpool.cache type=/boot/zfs/zpool.cache
          set kFreeBSD.vfs.root.mountfrom=zfs:&#036;zfs_root_device
          set kFreeBSD.vfs.root.mountfrom.options=rw
    }
    EOF
    done
</code></pre>

<p>I solved the problem this way to have a working solution that does not break
with squeeze upgrades, assuming that a future <code>grub-pc</code> package will deal well
with my config and I'll be able to remove this script, but I guess I'll have
to install it from backports.</p>

<p>The entry generated by the script when called from <code>update-grub</code> will be
similar to:</p>

<pre><code>    ### BEGIN /etc/grub.d/09_zfs-kfreebsd ###
    # Entry when using ZFS (we have issues with /etc/grub.d/10_kfreebsd)
    menuentry 'Debian GNU/kFreeBSD, with kFreeBSD 8.1-1-amd64 @ ITI' --class debian --class gnu-kfreebsd --class gnu --class os {
          insmod part_msdos
          insmod zfs
          set root='(hd0,1)'
          search --no-floppy --fs-uuid --set a371979bb836d1fe
          echo                    'Loading kernel of FreeBSD 8.1-1-amd64 ...'
          kfreebsd                //@/kfreebsd-8.1-1-amd64.gz
          kfreebsd_module_elf     //@/lib/modules/8.1-1-amd64/opensolaris.ko
          kfreebsd_module_elf     //@/lib/modules/8.1-1-amd64/zfs.ko
          kfreebsd_module         //@/zfs/zpool.cache type=/boot/zfs/zpool.cache
          set kFreeBSD.vfs.root.mountfrom=zfs:dkfbf1-ad4s3
          set kFreeBSD.vfs.root.mountfrom.options=rw
    }
    ### END /etc/grub.d/10_iti-kfreebsd ###
</code></pre>

<p>And after rebooting the machine with this new configuration the system boots
OK.</p>

<p>On my next post I'll continue explaining how to compile a kernel that supports
the use of the OpenBSD Packet Filter and related technologies (CARP, pflog,
etc.).</p>
]]></description>
</item>

</channel>
</rss>

