<?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>aisecure.net</title>
	<atom:link href="http://www.aisecure.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aisecure.net</link>
	<description></description>
	<lastBuildDate>Wed, 18 Apr 2012 10:49:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>HAST FreeBSD ZFS with CARP failover</title>
		<link>http://www.aisecure.net/2012/02/07/hast-freebsd-zfs-with-carp-failover/</link>
		<comments>http://www.aisecure.net/2012/02/07/hast-freebsd-zfs-with-carp-failover/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 12:59:47 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[ZFS]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[hast]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=480</guid>
		<description><![CDATA[HAST (Highly Available Storage) is a new concept for FreeBSD and it is under constant development. HAST allows to transparently store data on two physically separated machines connected over the TCP/IP network. HAST operates on block level making it transparent for file systems, providing disk-like devices in /dev/hast directory. In this article we will create two identical HAST nodes, hast1 and hast2. &#8230;]]></description>
			<content:encoded><![CDATA[<p>HAST (Highly Available Storage) is a new concept for FreeBSD and it is under constant development. HAST allows to transparently store data on two physically separated machines connected over the TCP/IP network. HAST operates on block level making it transparent for file systems, providing disk-like devices in <strong><em>/dev/hast</em></strong> directory.</p>
<p>In this article we will create two identical HAST nodes, hast1 and hast2. Both devices will use one NIC connected to a vlan for data synchronization and another NIC will be configured via CARP in order to share the same IP address across the network. The first node will be called &#8220;storage1.hast.test&#8221;, the second &#8220;storage2.hast.test&#8221; and they will both listen to a common IP address which we will bind to &#8220;storage.hast.test&#8221;</p>
<p>HAST binds its resource names according to the machine&#8217;s hostname. Therefore, we will use &#8220;hast1.freebsd.loc&#8221; and &#8220;hast2.freebsd.loc&#8221;  as the machines&#8217;s hostnames so that HAST can operate without complaining.</p>
<p>For starters, lets set up two identical nodes. For this example I have installed FreeBSD 9.0-RELEASE on two deferent instances using a Linux KVM. Both nodes have 512MB of RAM, one SATA drive containing the OS and three SATA drives which will be used to create our shared Raidz1 pool. The final result looks like this:</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2012/02/hast2.png"><img class="alignleft size-medium wp-image-489" title="hast2" src="http://www.aisecure.net/wp-content/uploads/2012/02/hast2-300x272.png" alt="" width="300" height="272" /></a></p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2012/02/hast1.png"><img class="alignleft size-medium wp-image-488" title="hast1" src="http://www.aisecure.net/wp-content/uploads/2012/02/hast1-300x274.png" alt="" width="300" height="274" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>In order for carp to work we don&#8217;t have to compile a new kernel. We can just load it as a module by adding to <strong><em>/boot/loader.conf</em></strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #007800;">if_carp_load</span>=<span style="color: #ff0000;">&quot;YES&quot;</span></pre></div></div>

<p>Our both nodes are set up, it is time to make some adjustments. First a descent <strong><em>/etc/rc.conf</em></strong> for the first node:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">zfs_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###Primary Interface##</span>
<span style="color: #007800;">ifconfig_re0</span>=<span style="color: #ff0000;">&quot;inet 10.10.10.181  netmask 255.255.255.0&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###Secondary Interface for HAST###</span>
<span style="color: #007800;">ifconfig_re1</span>=<span style="color: #ff0000;">&quot;inet 192.168.100.100  netmask 255.255.255.0&quot;</span>
&nbsp;
<span style="color: #007800;">defaultrouter</span>=<span style="color: #ff0000;">&quot;10.10.10.1&quot;</span>
<span style="color: #007800;">sshd_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">hostname</span>=<span style="color: #ff0000;">&quot;hast1.freebsd.loc&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##CARP INTERFACE SETUP##</span>
<span style="color: #007800;">cloned_interfaces</span>=<span style="color: #ff0000;">&quot;carp0&quot;</span>
<span style="color: #007800;">ifconfig_carp0</span>=<span style="color: #ff0000;">&quot;inet 10.10.10.180 netmask 255.255.255.0 vhid 1 pass mypassword advskew 0&quot;</span>
&nbsp;
<span style="color: #007800;">hastd_enable</span>=YES</pre></div></div>

<p>The second node we will also much the first except for the IP addressing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">zfs_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###Primary Interface##</span>
<span style="color: #007800;">ifconfig_re0</span>=<span style="color: #ff0000;">&quot;inet 10.10.10.182  netmask 255.255.255.0&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###Secondary Interface for HAST###</span>
<span style="color: #007800;">ifconfig_re1</span>=<span style="color: #ff0000;">&quot;inet 192.168.100.101  netmask 255.255.255.0&quot;</span>
&nbsp;
<span style="color: #007800;">defaultrouter</span>=<span style="color: #ff0000;">&quot;10.10.10.1&quot;</span>
<span style="color: #007800;">sshd_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">hostname</span>=<span style="color: #ff0000;">&quot;hast2.freebsd.loc&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##CARP INTERFACE SETUP##</span>
<span style="color: #007800;">cloned_interfaces</span>=<span style="color: #ff0000;">&quot;carp0&quot;</span>
<span style="color: #007800;">ifconfig_carp0</span>=<span style="color: #ff0000;">&quot;inet 10.10.10.180 netmask 255.255.255.0 vhid 1 pass mypassword advskew 100&quot;</span>
&nbsp;
<span style="color: #007800;">hastd_enable</span>=YES</pre></div></div>

<p>At this point we have assigned re1 with two IPs for HAST synchronization. We have also assigned two IPs to re0 which in turn we share with a third common IP assigned to carp0.<br />
As a result, re1 is being used for HAST synchronization in a vlan while carp0 which is cloned by re0  used under the same vlan with the rest of our clients.  </p>
<p>In order for HAST to function correctly we have to resolve the correct IPs on every node. We don&#8217;t want to rely on DNS for this because DNS can fail. Instead we will use <strong><em>/etc/hosts</em></strong> same on every node.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">::<span style="color: #000000;">1</span>			localhost localhost.freebsd.loc
127.0.0.1		localhost localhost.freebsd.loc
192.168.100.100		hast1.freebsd.loc hast1
192.168.100.101		hast2.freebsd.loc hast2
&nbsp;
10.10.10.181          	storage1.hast.test storage1
10.10.10.182          	storage2.hast.test storage2
10.10.10.180	      	storage.hast.test  storage</pre></div></div>

<p>Next, we have to create the <strong><em>/etc/hast.conf</em></strong> file. Here we will declare the resources that we want to create. All resources will eventually create devices located under <strong><em>/dev/hast</em></strong> on the primary node. Every resource indicates a physical device specifying a local and remote IP device. The <strong><em>/etc/hast.conf</em></strong> must be exactly the same on every node.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">resource disk1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        on hast1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad1
                remote hast2
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        on  hast2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad1
                remote hast1
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
resource disk2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        on  hast1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad2
                remote hast2
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        on  hast2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad2
                remote hast1
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
resource disk3 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        on  hast1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad3
                remote hast2
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        on  hast2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad3
                remote hast1
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>In this example we are sharing three resources, disk1, disk2 and disk3. Each resource indicates a device the local and the remote IP address. With this configuration in place, we are ready to begin setting up out HAST devices.</p>
<p>Lets start hastd on both nodes first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;">#/etc/rc.d/hastd start</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;">#/etc/rc.d/hastd start</span></pre></div></div>

<p>Now on the primary node we will initialize our resources, create them and finally assign a primary role:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;">#hastctl role init disk1</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl role init disk2</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl role init disk3</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl create disk1</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl create disk2</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl create disk3</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl role primary disk1</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl role primary disk2</span>
hast1<span style="color: #666666; font-style: italic;">#hastctl role primary disk3</span></pre></div></div>

<p>Next, on the secondary node we will initialize our resources, create them and finally assign a secondary role:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;">#hastctl role init disk1</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl role init disk2</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl role init disk3</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl create disk1</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl create disk2</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl create disk3</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl role secondary disk1</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl role secondary disk2</span>
hast2<span style="color: #666666; font-style: italic;">#hastctl role secondary disk3</span></pre></div></div>

<p>There are other ways for creating and assigning roles to each resource. Having repeat this procedure a few times, I saw that this usually always works.   </p>
<p>Now check the status on both nodes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;"># hastctl status</span>
disk1:
  role: primary
  provname: disk1
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada1
  ...
  remoteaddr: hast2
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...
disk2:
  role: primary
  provname: disk2
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada2
  ...
  remoteaddr: hast2
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...
disk3:
  role: primary
  provname: disk3
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada3
  ...
  remoteaddr: hast2
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...</pre></div></div>

<p>The first node looks good. Status is complete.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;"># hastctl status</span>
disk1:
  role: secondary
  provname: disk1
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada1
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...
disk2:
  role: secondary
  provname: disk2
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada2
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...
disk3:
  role: secondary
  provname: disk3
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ada3
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  dirty: <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0B<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  ...</pre></div></div>

<p>So does the second. Like I mentioned earlier there are different ways for doing this the first time.  You have to look for the word <strong>status: complete</strong>. If you get a degraded status you can always repeat the procedure.</p>
<p>Now it is time to create our ZFS pool. The primary node should have a <strong><em>/dev/hast</em></strong> directory containing our resources. This directory appears only at the active node.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;"># zpool create zhast raidz1 /dev/hast/disk1 /dev/hast/disk2 /dev/hast/disk3</span>
hast1<span style="color: #666666; font-style: italic;"># zpool status zhast</span>
 pool: zhast
 state: ONLINE
 scan: none requested
 config:
&nbsp;
	NAME            STATE     READ WRITE CKSUM
	zhast           ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	  raidz1-<span style="color: #000000;">0</span>      ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk1  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk2  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk3  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span></pre></div></div>

<p>We can now use hastctl status on each node to see if everything looks ok. The magic word we are looking for here is: <strong>replication: fullsync</strong></p>
<p>At this point both of our nodes should be available for failover. We have storage1 running as primary and sharing a pool called zhast. Our storage2 is currently in a standby mode. If we have set DNS properly we can ssh to storage.hast.test or by using its carp IP to 10.10.10.180.</p>
<p>In order to perform a failover we have to first export our pool from the first node, change the role of each resource to secondary. Then change the role of each resource to primary on the standby node and import the pool. This procedure will be done manually to test if failover really works. But for a real HA solution we will eventually create a script that will take care of this.</p>
<p>First lets export our pool and change our resources role:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;"># zpool export zhast</span>
hast1<span style="color: #666666; font-style: italic;"># hastctl role secondary disk1</span>
hast1<span style="color: #666666; font-style: italic;"># hastctl role secondary disk2</span>
hast1<span style="color: #666666; font-style: italic;"># hastctl role secondary disk3</span></pre></div></div>

<p>Now, lets reverse the procedure on the standby node:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;"># hastctl role primary disk1</span>
hast2<span style="color: #666666; font-style: italic;"># hastctl role primary disk2</span>
hast2<span style="color: #666666; font-style: italic;"># hastctl role primary disk3</span>
hast2<span style="color: #666666; font-style: italic;"># zpool import zhast</span></pre></div></div>

<p>The roles have successfully changed, lets see our pool status:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;"># zpool status zhast</span>
 pool: zhast
 state: ONLINE
 scan: none requested
 config:
&nbsp;
	NAME            STATE     READ WRITE CKSUM
	zhast           ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	  raidz1-<span style="color: #000000;">0</span>      ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk1  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk2  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
	    hast<span style="color: #000000; font-weight: bold;">/</span>disk3  ONLINE       <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>     <span style="color: #000000;">0</span>
&nbsp;
errors: No known data errors</pre></div></div>

<p>Again, by using <strong><em>hastctl status</em></strong> on each node we can verify that the roles have indeed changed and that the status is complete. This is a sample output from the second node now in charge:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;"># hastctl status</span>
disk1:
  role: primary
  provname: disk1
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad1
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  ...
disk2:
  role: primary
  provname: disk2
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad2
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  ...
disk3:
  role: primary
  provname: disk3
  localpath: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ad3
  ...
  remoteaddr: hast1
  replication: fullsync
  status: <span style="color: #7a0874; font-weight: bold;">complete</span>
  ...</pre></div></div>

<p>It is now time to automate this procedure. When do we want our servers to automatically failover?<br />
One reason would be if the primary node is not responding to the external network thus not being able to serve its clients. Using a devd event we can catch a carp interface going up or down and a state change. </p>
<p>Add the following lines to <strong><em>/etc/devd.conf</em></strong> on both nodes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">notify <span style="color: #000000;">30</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	match <span style="color: #ff0000;">&quot;system&quot;</span> <span style="color: #ff0000;">&quot;IFNET&quot;</span>;
	match <span style="color: #ff0000;">&quot;subsystem&quot;</span> <span style="color: #ff0000;">&quot;carp0&quot;</span>;
	match <span style="color: #ff0000;">&quot;type&quot;</span> <span style="color: #ff0000;">&quot;LINK_UP&quot;</span>;
	action <span style="color: #ff0000;">&quot;/usr/local/bin/failover master&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>;
&nbsp;
notify <span style="color: #000000;">30</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	match <span style="color: #ff0000;">&quot;system&quot;</span> <span style="color: #ff0000;">&quot;IFNET&quot;</span>;
	match <span style="color: #ff0000;">&quot;subsystem&quot;</span> <span style="color: #ff0000;">&quot;carp0&quot;</span>;
	match <span style="color: #ff0000;">&quot;type&quot;</span> <span style="color: #ff0000;">&quot;LINK_DOWN&quot;</span>;
	action <span style="color: #ff0000;">&quot;/usr/local/bin/failover slave&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>;</pre></div></div>

<p>And now lets create the failover script which will be responsible for doing automatically what we did before manually:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Original script by Freddie Cash &lt;fjwcash@gmail.com&gt;</span>
<span style="color: #666666; font-style: italic;"># Modified by Michael W. Lucas &lt;mwlucas@BlackHelicopters.org&gt;</span>
<span style="color: #666666; font-style: italic;"># and Viktor Petersson &lt;vpetersson@wireload.net&gt;</span>
<span style="color: #666666; font-style: italic;"># Modified by George Kontostanos &lt;gkontos.mail@gmail.com&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The names of the HAST resources, as listed in /etc/hast.conf</span>
<span style="color: #007800;">resources</span>=<span style="color: #ff0000;">&quot;disk1 disk2 disk3&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># delay in mounting HAST resource after becoming master</span>
<span style="color: #666666; font-style: italic;"># make your best guess</span>
<span style="color: #007800;">delay</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># logging</span>
<span style="color: #007800;">log</span>=<span style="color: #ff0000;">&quot;local0.debug&quot;</span>
<span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;failover&quot;</span>
<span style="color: #007800;">pool</span>=<span style="color: #ff0000;">&quot;zhast&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># end of user configurable stuff</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
	master<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Switching to primary provider for <span style="color: #007800;">${resources}</span>.&quot;</span>
		<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #800000;">${delay}</span>
&nbsp;
		<span style="color: #666666; font-style: italic;"># Wait for any &quot;hastd secondary&quot; processes to stop</span>
		<span style="color: #000000; font-weight: bold;">for</span> disk <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${resources}</span>; <span style="color: #000000; font-weight: bold;">do</span>
			<span style="color: #000000; font-weight: bold;">while</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span> pgrep <span style="color: #660033;">-lf</span> <span style="color: #ff0000;">&quot;hastd: <span style="color: #007800;">${disk}</span> \(secondary\)&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
				<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
			<span style="color: #666666; font-style: italic;"># Switch role for each disk</span>
			hastctl role primary <span style="color: #800000;">${disk}</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Unable to change role to primary for resource <span style="color: #007800;">${disk}</span>.&quot;</span>
				<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
		<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
		<span style="color: #666666; font-style: italic;"># Wait for the /dev/hast/* devices to appear</span>
		<span style="color: #000000; font-weight: bold;">for</span> disk <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${resources}</span>; <span style="color: #000000; font-weight: bold;">do</span>
			<span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span> jot <span style="color: #000000;">60</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
				<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;/dev/hast/<span style="color: #007800;">${disk}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">break</span>
				<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">0.5</span>
			<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;/dev/hast/<span style="color: #007800;">${disk}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;GEOM provider /dev/hast/<span style="color: #007800;">${disk}</span> did not appear.&quot;</span>
				<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
		<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
		logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Role for HAST resources <span style="color: #007800;">${resources}</span> switched to primary.&quot;</span>
&nbsp;
&nbsp;
		logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Importing Pool&quot;</span>
		<span style="color: #666666; font-style: italic;"># Import ZFS pool. Do it forcibly as it remembers hostid of</span>
                <span style="color: #666666; font-style: italic;"># the other cluster node.</span>
                <span style="color: #007800;">out</span>=<span style="color: #000000; font-weight: bold;">`</span>zpool import <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${pool}</span>&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                    logger <span style="color: #660033;">-p</span> local0.error <span style="color: #660033;">-t</span> hast <span style="color: #ff0000;">&quot;ZFS pool import for resource <span style="color: #007800;">${resource}</span> failed: <span style="color: #007800;">${out}</span>.&quot;</span>
                    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
                logger <span style="color: #660033;">-p</span> local0.debug <span style="color: #660033;">-t</span> hast <span style="color: #ff0000;">&quot;ZFS pool for resource <span style="color: #007800;">${resource}</span> imported.&quot;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
	slave<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Switching to secondary provider for <span style="color: #007800;">${resources}</span>.&quot;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;"># Switch roles for the HAST resources</span>
		zpool list <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-q</span> <span style="color: #ff0000;">&quot;^<span style="color: #007800;">${pool}</span> &quot;</span>
        	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                	<span style="color: #666666; font-style: italic;"># Forcibly export file pool.</span>
                	<span style="color: #007800;">out</span>=<span style="color: #000000; font-weight: bold;">`</span>zpool <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${pool}</span>&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
               		 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                        	logger <span style="color: #660033;">-p</span> local0.error <span style="color: #660033;">-t</span> hast <span style="color: #ff0000;">&quot;Unable to export pool for resource <span style="color: #007800;">${resource}</span>: <span style="color: #007800;">${out}</span>.&quot;</span>
                        	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
                	 <span style="color: #000000; font-weight: bold;">fi</span>
                	logger <span style="color: #660033;">-p</span> local0.debug <span style="color: #660033;">-t</span> hast <span style="color: #ff0000;">&quot;ZFS pool for resource <span style="color: #007800;">${resource}</span> exported.&quot;</span>
        	<span style="color: #000000; font-weight: bold;">fi</span>
		<span style="color: #000000; font-weight: bold;">for</span> disk <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${resources}</span>; <span style="color: #000000; font-weight: bold;">do</span>
			<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$delay</span>
			hastctl role secondary <span style="color: #800000;">${disk}</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Unable to switch role to secondary for resource <span style="color: #007800;">${disk}</span>.&quot;</span>
				<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
			logger <span style="color: #660033;">-p</span> <span style="color: #007800;">$log</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$name</span> <span style="color: #ff0000;">&quot;Role switched to secondary for resource <span style="color: #007800;">${disk}</span>.&quot;</span>
		<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<p>Let&#8217;s try it and see if it works. Log into both the currently active and standby node. Make sure that you are on the active by issuing a <strong><em>hastctl status</em></strong> command. Then force a failover by bringing the interface which is associated with carp0 downL</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;"># ifconfig er0 down</span></pre></div></div>

<p>Watch at the generated messages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast1<span style="color: #666666; font-style: italic;"># tail -f /var/log/debug.log</span>
&nbsp;
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:01:<span style="color: #000000;">41</span> hast1 failover: Switching to secondary provider <span style="color: #000000; font-weight: bold;">for</span> disk1 disk2 disk3.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:01:<span style="color: #000000;">49</span> hast1 hast: ZFS pool <span style="color: #000000; font-weight: bold;">for</span> resource  exported.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:01:<span style="color: #000000;">52</span> hast1 failover: Role switched to secondary <span style="color: #000000; font-weight: bold;">for</span> resource disk1.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:01:<span style="color: #000000;">55</span> hast1 failover: Role switched to secondary <span style="color: #000000; font-weight: bold;">for</span> resource disk2.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:01:<span style="color: #000000;">58</span> hast1 failover: Role switched to secondary <span style="color: #000000; font-weight: bold;">for</span> resource disk3.</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hast2<span style="color: #666666; font-style: italic;"># tail -f /var/log/debug.log</span>
&nbsp;
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">15</span> hast2 failover: Switching to primary provider <span style="color: #000000; font-weight: bold;">for</span> disk1 disk2 disk3.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">19</span> hast2 failover: Role <span style="color: #000000; font-weight: bold;">for</span> HAST resources disk1 disk2 disk3 switched to primary.
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">19</span> hast2 failover: Importing Pool
Feb  <span style="color: #000000;">6</span> <span style="color: #000000;">15</span>:02:<span style="color: #000000;">52</span> hast2 hast: ZFS pool <span style="color: #000000; font-weight: bold;">for</span> resource  imported.</pre></div></div>

<p>Voila! The failover worked like a charm and now hast2 has assumed the primary role.</p>
<p><strong>Further considerations:</strong></p>
<p>What we did today is a basic setup of two nodes sharing a raidz1 pool with automatic role failover in case of a failure that would result in a loss of a carp interface.<br />
Obviously, a similar devd event would be generated in case we loose a HAST replication interface. This is something that needs to be addressed similarly since losing that interface will leave us with no synchronization at all.<br />
Going further, we would have to add scripts that will bring up and down services during a failover.<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2012/02/07/hast-freebsd-zfs-with-carp-failover/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Root on ZFS FreeBSD 9 (non legacy mountpoint &#8211; 4K optimized)</title>
		<link>http://www.aisecure.net/2012/01/16/rootzfs/</link>
		<comments>http://www.aisecure.net/2012/01/16/rootzfs/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 19:29:48 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Root On ZFS]]></category>
		<category><![CDATA[ZFS]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[zfs]]></category>
		<category><![CDATA[zfs@root]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=454</guid>
		<description><![CDATA[In this guide I will demonstrate how you can install a fully functional full root on ZFS FreeBSD9 using a GPT scheme with a non legacy root ZFS mountpoint optimized for 4K drives. We will also use ZFS for SWAP. You can use this as a reference guide for a single or mirror installation. (1) &#8230;]]></description>
			<content:encoded><![CDATA[<p>In this guide I will demonstrate how you can install a fully functional full root on ZFS FreeBSD9 using a GPT scheme with a <strong>non legacy</strong> root ZFS mountpoint <strong>optimized for 4K drives</strong>. We will also use ZFS for SWAP.</p>
<p>You can use this as a reference guide for a single or mirror installation. </p>
<p><strong>(1) Boot from a FreeBSD9 installation DVD or memstick and choose &#8220;Live CD&#8221;.</strong></p>
<p><strong>(2) Create the necessary partitions on the disk(s) and add ZFS aware boot code.</strong></p>
<p>a) For a single disk installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpart create <span style="color: #660033;">-s</span> gpt ada0
gpart add <span style="color: #660033;">-b</span> <span style="color: #000000;">34</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">94</span> <span style="color: #660033;">-t</span> freebsd-boot ada0
gpart add <span style="color: #660033;">-t</span> freebsd-zfs <span style="color: #660033;">-l</span> disk0 ada0
gpart bootcode <span style="color: #660033;">-b</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>pmbr <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>gptzfsboot <span style="color: #660033;">-i</span> <span style="color: #000000;">1</span> ada0</pre></div></div>

<p>b) Repeat the procedure for the second drive if you want a mirror installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpart create <span style="color: #660033;">-s</span> gpt ada1
gpart add <span style="color: #660033;">-b</span> <span style="color: #000000;">34</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">94</span> <span style="color: #660033;">-t</span> freebsd-boot ada1
gpart add <span style="color: #660033;">-t</span> freebsd-zfs <span style="color: #660033;">-l</span> disk1 ada1
gpart bootcode <span style="color: #660033;">-b</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>pmbr <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>gptzfsboot <span style="color: #660033;">-i</span> <span style="color: #000000;">1</span> ada1</pre></div></div>

<p><strong>(3) Align the Disks for 4K and create the pool.</strong></p>
<p>a) For a single disk installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gnop create <span style="color: #660033;">-S</span> <span style="color: #000000;">4096</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0
zpool create <span style="color: #660033;">-o</span> <span style="color: #007800;">altroot</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt <span style="color: #660033;">-o</span> <span style="color: #007800;">cachefile</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>zpool.cache zroot <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0.nop
zpool <span style="color: #7a0874; font-weight: bold;">export</span> zroot
gnop destroy <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0.nop
zpool import <span style="color: #660033;">-o</span> <span style="color: #007800;">altroot</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt <span style="color: #660033;">-o</span> <span style="color: #007800;">cachefile</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>zpool.cache zroot</pre></div></div>

<p>b) For a mirror installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gnop create <span style="color: #660033;">-S</span> <span style="color: #000000;">4096</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0
gnop create <span style="color: #660033;">-S</span> <span style="color: #000000;">4096</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk1
zpool create <span style="color: #660033;">-o</span> <span style="color: #007800;">altroot</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt <span style="color: #660033;">-o</span> <span style="color: #007800;">cachefile</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>zpool.cache zroot mirror <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0.nop <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk1.nop
zpool <span style="color: #7a0874; font-weight: bold;">export</span> zroot
gnop destroy <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0.nop
gnop destroy <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk1.nop
zpool import <span style="color: #660033;">-o</span> <span style="color: #007800;">altroot</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt <span style="color: #660033;">-o</span> <span style="color: #007800;">cachefile</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>zpool.cache zroot</pre></div></div>

<p><strong>(4) Set the bootfs property and checksums. </strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zpool <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">bootfs</span>=zroot zroot
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">checksum</span>=fletcher4 zroot</pre></div></div>

<p><strong>(5) Create appropriate filesystems (feel free to improvise!).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>usr
zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>home
zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>var
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>tmp
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>distfiles
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>packages
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>crash
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>pkg
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>empty
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=<span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp</pre></div></div>

<p><strong>(6) Add swap space and disable checksums. In this case I add 4GB of swap.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zfs create <span style="color: #660033;">-V</span> 4G zroot<span style="color: #000000; font-weight: bold;">/</span>swap
zfs <span style="color: #000000; font-weight: bold;">set</span> org.freebsd:<span style="color: #007800;">swap</span>=on zroot<span style="color: #000000; font-weight: bold;">/</span>swap
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">checksum</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>swap</pre></div></div>

<p><strong>(7) Create a symlink to /home and fix some permissions.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">1777</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>mnt ; <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> usr<span style="color: #000000; font-weight: bold;">/</span>home home
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">1777</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp</pre></div></div>

<p><strong>(8) Instal FreeBSD.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sh</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>freebsd-dist
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DESTDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--unlink</span> <span style="color: #660033;">-xpJf</span> - <span style="color: #660033;">-C</span> <span style="color: #800000;">${DESTDIR:-/}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><strong>(9) Copy zpool.cache (very important!!!)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</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>zpool.cache <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>zfs<span style="color: #000000; font-weight: bold;">/</span>zpool.cache</pre></div></div>

<p><strong>(10) Create the rc.conf, loader.conf and an empty fstab (otherwise the system will complain).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'zfs_enable=&quot;YES&quot;'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'zfs_load=&quot;YES&quot;'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>loader.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'vfs.root.mountfrom=&quot;zfs:zroot&quot;'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>loader.conf
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fstab</pre></div></div>

<p>Reboot, adjust time zone info, add a password for root, add a user and enjoy!!!<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2012/01/16/rootzfs/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Securing hosts with PF</title>
		<link>http://www.aisecure.net/2012/01/15/securing_pf1/</link>
		<comments>http://www.aisecure.net/2012/01/15/securing_pf1/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 00:36:40 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=437</guid>
		<description><![CDATA[PF is OPENBSD&#8217;S default Packet filtering for TCP/IP packets and NAT. PF has been ported to FreeBSD and it is currently at version 4.5 on FreeBSD 9.0-RELEASE. Today, we will see how we can use PF to effectively secure a FreeBSD host on the Internet. Before we even start talking about PF, it is essential &#8230;]]></description>
			<content:encoded><![CDATA[<p>PF is OPENBSD&#8217;S default Packet filtering for TCP/IP packets and NAT. PF has been ported to FreeBSD and it is currently at version 4.5 on FreeBSD 9.0-RELEASE.</p>
<p>Today, we will see how we can use PF to effectively secure a FreeBSD host on the Internet.<br />
Before we even start talking about PF, it is essential to point out a few things about network firewalls.</p>
<ul>
<li>Network firewalls as opposed to packet filtering devices use statefull inspection in order to decide if a packet is allowed to pass or not.</li>
<li>Statefull inspection was inspired by the concept of state and the 3-way handshake which we find only on TCP type base connections.</li>
<li>Statefull inspection has progressed a lot over the time, making it somehow possible to maintain it on stateless protocols such us UDP or ICMP.</li>
</ul>
<p>Network firewalls work mainly on layers 3 and 4 of the OSI model. Therefore, application inspection is not possible since it requires the ability to inspect at the layer 7.</p>
<p style="text-align: center;">General DO &amp; DON&#8217;T</p>
<ul>
<li>Log everything! (except Internet noise)</li>
<li>Be similarly restrictive to inbound and outbound traffic!</li>
<li>Process your most used rules first, respect your CPU and memory!</li>
<li>Don&#8217;t be tempted into using exotic rules that you read somewhere to prevent port scans!</li>
</ul>
<p>Let&#8217;s start by building our first policy for a webserver:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">### macro definitions</span>
ext_if = <span style="color: #ff0000;">&quot;em0&quot;</span>
dns_server = <span style="color: #ff0000;">&quot;123.123.123.123&quot;</span>
webservices = <span style="color: #ff0000;">&quot;{80, 443, 22}&quot;</span>
icmp_types = <span style="color: #ff0000;">&quot;echoreq&quot;</span>
netbios_tcp = <span style="color: #ff0000;">&quot;{445, 137, 138, 139}&quot;</span>
netbios_udp = <span style="color: #ff0000;">&quot;{445, 137, 138, 139}&quot;</span>
tcp_out = <span style="color: #ff0000;">&quot;{5999, 80, 21}&quot;</span></pre></div></div>

<p>First we have define our <a href="http://www.openbsd.org/faq/pf/macros.html#macros" target="_blank">macros</a>. Macros are variables in a sense, holding information regarding our interfaces and tcp / udp ports. It is always a good idea to group port numbers since it can greatly reduce our rules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">### all incoming traffic on external interface is normalized and fragmented</span>
<span style="color: #666666; font-style: italic;">### packets are reassembled.</span>
scrub <span style="color: #000000; font-weight: bold;">in</span> on <span style="color: #007800;">$ext_if</span> all fragment reassemble
&nbsp;
<span style="color: #666666; font-style: italic;">### exercise antispoofing on the external interface, but add the local</span>
<span style="color: #666666; font-style: italic;">### loopback interface as an exception, to prevent services utilizing the</span>
<span style="color: #666666; font-style: italic;">### local loop from being blocked accidentally.</span>
<span style="color: #000000; font-weight: bold;">set</span> skip on lo0
antispoof <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #007800;">$ext_if</span> inet</pre></div></div>

<p>Next we tell the firewall to reassemble all fragmented packets, skip any packet filtering rules for the loopback interface and finally to check for spoofed IP addresses on the external interface.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">### get rid quick of Internet noise like microsoft netbios service.</span>
<span style="color: #666666; font-style: italic;">### This accounts to 80% of dropped traffic. We don't need to log this also</span>
block <span style="color: #000000; font-weight: bold;">in</span> quick on <span style="color: #007800;">$ext_if</span> proto tcp from any to any port <span style="color: #007800;">$netbios_tcp</span>
block <span style="color: #000000; font-weight: bold;">in</span> quick on <span style="color: #007800;">$ext_if</span> proto udp from any to any port <span style="color: #007800;">$netbios_udp</span></pre></div></div>

<p>This part you don&#8217;t usually find in PF rules but I think that it is worth having it.<br />
If you look at the logs on an Internet faced firewall, you will see that most of the dropped traffic is netbios. These are usually Zombie hosts infected by some nasty old windows virus.<br />
By blocking them first without logging this traffic, we relax both our firewall from having to read all the rules before it drops this. We also maintain cleaner logs.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">###clean up rule</span>
block log all</pre></div></div>

<p>Finally, we tell our firewall to block any traffic, inbound and outbound, that doesn&#8217;t much a rule. We also like to log everything.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">### set a rule that allows inbound traffic with synproxy handshaking.</span>
pass <span style="color: #000000; font-weight: bold;">in</span> quick log on <span style="color: #007800;">$ext_if</span> proto tcp from any to any port <span style="color: #007800;">$webservices</span> flags S<span style="color: #000000; font-weight: bold;">/</span>SA synproxy state
pass <span style="color: #000000; font-weight: bold;">in</span> quick log inet proto icmp all icmp-type <span style="color: #007800;">$icmp_types</span> keep-state</pre></div></div>

<p>Like I mentioned earlier, the most used rules should come first. Since this is a web server, we allow http, https and ssh incoming traffic. We also like to be able to ping our server. Notice that I am using the &#8220;s<a href="http://www.openbsd.org/faq/pf/filter.html#stateopts" target="_blank">ynproxy state</a>&#8221; keyword. That way I am instructing the firewall to proxy the 3-way tcp handshake, keeping syn flood attacks away.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">### keep state on any outbound tcp, udp or icmp traffic. modulate the isn of</span>
<span style="color: #666666; font-style: italic;">### outgoing packets. (initial sequence number) broken operating systems</span>
<span style="color: #666666; font-style: italic;">### sometimes don't randomize this number, making it guessable.</span>
pass out quick log on <span style="color: #007800;">$ext_if</span> proto tcp from any to any port <span style="color: #007800;">$tcp_out</span> modulate state
pass out quick log on <span style="color: #007800;">$ext_if</span> proto udp from any to <span style="color: #007800;">$dns_server</span> port domain modulate state
pass out quick log inet proto icmp all icmp-type <span style="color: #007800;">$icmp_types</span> keep-state</pre></div></div>

<p>Finally, I allow my webserver outbound access for http, ftp and cvs. This could and should become stricter and allow this type of communication only to certain destinations.</p>
<p>This is just an example of a host based firewall. A real firewall would have at least two interfaces and would probably perform NAT. The point is that an effective policy is a policy that will not create extra burden, will be clean and easy to read and maintain.</p>
<p>Always start by processing your most used rules first. Group ports and servers and log all interesting traffic.</p>
<p>&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2012/01/15/securing_pf1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automated ZFS incremental Backups over ssh</title>
		<link>http://www.aisecure.net/2012/01/11/automated-zfs-incremental-backups-over-ssh/</link>
		<comments>http://www.aisecure.net/2012/01/11/automated-zfs-incremental-backups-over-ssh/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 15:34:45 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[ZFS]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=411</guid>
		<description><![CDATA[In a previous article we saw how easy is to use ZFS send/receive to perform differential backups using  incremental snapshots. Today, we will see how we can automate the procedure in order to send incremental snapshots to a different machine over ssh. There are two prerequisites for this procedure to work. First, the machine that is receiving the snapshots must &#8230;]]></description>
			<content:encoded><![CDATA[<p>In a previous <a href="http://www.aisecure.net/2011/06/27/zfs-backups-with-differential-snapshots/" target="_blank">article</a> we saw how easy is to use ZFS send/receive to perform differential backups using  incremental snapshots. Today, we will see how we can automate the procedure in order to send incremental snapshots to a different machine over ssh.</p>
<p>There are two prerequisites for this procedure to work. First, the machine that is receiving the snapshots must be running the same or higher ZFS version from the machine that is being backed up. Second, we must either have root access to the receiving machine or an account that has been delegated with create, receive ZFS properties.</p>
<p>First lets prepare both host and target machines. We need to create and send our first full snapshot from our host to a ZFS folder on the target.</p>
<p>The host:</p>
<pre class="qoate-code">
core2duo# zfs snapshot -r zroot/usr/src@-2012-01-10
core2duo# zfs list
NAME USED AVAIL REFER MOUNTPOINT
zroot/usr/src 349M 64.4G 349M /usr/src
zroot/usr/src@-2012-01-10 0 - 349M -
zroot/usr/src/mytest 31K 64.4G 31K /usr/src/mytest
zroot/usr/src/mytest@-2012-01-10 0 - 31K -
</pre>
<p>The target:</p>
<pre class="qoate-code">
hp# zfs create tank/test
hp# zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank/test 40.0K 747G 40.0K /tank/test
</pre>
<p>Now, lets send our first full snapshot:</p>
<pre class="qoate-code">
core2duo# zfs send -R zroot/usr/src@-2012-01-10 | ssh root@hp zfs receive -Fduv tank/test

Password:
receiving full stream of zroot/usr/src@-2012-01-10 into tank/test/usr/src@-2012-01-10
received 732MB stream in 72 seconds (10.2MB/sec)
receiving full stream of zroot/usr/src/mytest@-2012-01-10 into tank/test/usr/src/mytest@-2012-01-10
received 47.4KB stream in 1 seconds (47.4KB/sec)
</pre>
<p>Now, lets create a new snapshot and send them both incremental.</p>
<pre class="qoate-code">
core2duo# zfs snapshot -r zroot/usr/src@-2012-01-11
core2duo# zfs send -R -i zroot/usr/src@-2012-01-10 zroot/usr/src@-2012-01-11 | ssh root@hp zfs receive -Fduv tank/test

receiving full stream of zroot/usr/src@-2012-01-10 into tank/test/usr/src@-2012-01-10
received 732MB stream in 72 seconds (10.2MB/sec)
receiving full stream of zroot/usr/src/mytest@-2012-01-10 into tank/test/usr/src/mytest@-2012-01-10
received 47.4KB stream in 1 seconds (47.4KB/sec)
</pre>
<p>Notice that I am using some special switches in my send/receive commands.<br />
When sending, <strong>-R</strong> allows me to send the snapshots, their children and their properties.<br />
When receiving, <strong>-F</strong> forces a rollback to the most recent snapshot, <strong>-d</strong> maintains my naming scheme and <strong>-u</strong> makes sure that the associated file systems do not get mounted.</p>
<p>Lets now see what we have done so far, first the host:</p>
<pre class="qoate-code">
core2duo# zfs list
NAME USED AVAIL REFER MOUNTPOINT
zroot/usr/src 349M 64.4G 349M /usr/src
zroot/usr/src@-2012-01-11 0 - 349M -
zroot/usr/src/mytest 31K 64.4G 31K /usr/src/mytest
zroot/usr/src/mytest@-2012-01-11 0 - 31K -
</pre>
<p>And the target:</p>
<pre class="qoate-code">
hp# zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank/test 364M 747G 41.3K /tank/test
tank/test/usr 364M 747G 40.0K /tank/test/usr
tank/test/usr/src 364M 747G 364M /tank/test/usr/src
tank/test/usr/src@-2012-01-10 1.33K - 364M -
tank/test/usr/src@-2012-01-11 0 - 364M -
tank/test/usr/src/mytest 65.3K 747G 40.0K /tank/test/usr/src/mytest
tank/test/usr/src/mytest@-2012-01-10 25.3K - 40.0K -
tank/test/usr/src/mytest@-2012-01-11 0 - 40.0K -
</pre>
<p>Looks like it is working. The only thing left is to somehow automate the procedure. Let&#8217;s create a script that will create a snapshot which we will call it <strong>today</strong>, check if there was a snapshot <strong>yesterday</strong> and send them incrementally to a remote <strong>host</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">pool</span>=<span style="color: #ff0000;">&quot;zroot/usr/src&quot;</span>
<span style="color: #007800;">destination</span>=<span style="color: #ff0000;">&quot;tank/test&quot;</span>
<span style="color: #007800;">host</span>=<span style="color: #ff0000;">&quot;10.10.10.4&quot;</span>
&nbsp;
<span style="color: #007800;">today</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;<span style="color: #007800;">$type</span>-%Y-%m-%d&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">yesterday</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-1d</span> +<span style="color: #ff0000;">&quot;<span style="color: #007800;">$type</span>-%Y-%m-%d&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create today snapshot</span>
<span style="color: #007800;">snapshot_today</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$pool</span>@<span style="color: #007800;">$today</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># look for a snapshot with this name</span>
<span style="color: #000000; font-weight: bold;">if</span> zfs list <span style="color: #660033;">-H</span> <span style="color: #660033;">-o</span> name <span style="color: #660033;">-t</span> snapshot <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$snapshot_today</span>$&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; snapshot, <span style="color: #007800;">$snapshot_today</span>, already exists&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; taking todays snapshot, <span style="color: #007800;">$snapshot_today</span>&quot;</span>
zfs snapshot <span style="color: #660033;">-r</span> <span style="color: #007800;">$snapshot_today</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># look for yesterday snapshot</span>
<span style="color: #007800;">snapshot_yesterday</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$pool</span>@<span style="color: #007800;">$yesterday</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> zfs list <span style="color: #660033;">-H</span> <span style="color: #660033;">-o</span> name <span style="color: #660033;">-t</span> snapshot <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$snapshot_yesterday</span>$&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; yesterday snapshot, <span style="color: #007800;">$snapshot_yesterday</span>, exists lets proceed with backup&quot;</span>
&nbsp;
zfs send <span style="color: #660033;">-R</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$snapshot_yesterday</span> <span style="color: #007800;">$snapshot_today</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$host</span> zfs receive <span style="color: #660033;">-Fduv</span> <span style="color: #007800;">$destination</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; backup complete destroying yesterday snapshot&quot;</span>
zfs destroy <span style="color: #660033;">-r</span> <span style="color: #007800;">$snapshot_yesterday</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; missing yesterday snapshot aborting, <span style="color: #007800;">$snapshot_yesterday</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p><strong>pool</strong> is the ZFS pool we want to backup<br />
<strong>destination</strong> is the destination pool that will receive the backup<br />
<strong>host</strong> is our backup host!</p>
<p>With a cronjob in place this would be a nice candidate for a daily ZFS incremental backup policy. Just make sure you use public/private key for ssh authentication.<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2012/01/11/automated-zfs-incremental-backups-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD Update, Upgrade (Part II)</title>
		<link>http://www.aisecure.net/2011/12/05/freebsd-update2/</link>
		<comments>http://www.aisecure.net/2011/12/05/freebsd-update2/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 13:53:05 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=396</guid>
		<description><![CDATA[In the previous article we saw how to update FreeBSD from source. In this article I will add a few steps necessary when upgrading FreeBSD trough a major release. A good example is going from FreeBSD 8.2-RELEASE to FreeBSD 9.0-RELEASE. In reality the steps are more or less the same. First and for most, make sure &#8230;]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.aisecure.net/2011/12/04/freebsd-update/" target="_blank">previous</a> article we saw how to update FreeBSD from source.</p>
<p>In this article I will add a few steps necessary when <strong>upgrading</strong> FreeBSD trough a major release. A good example is going from FreeBSD 8.2-RELEASE to FreeBSD 9.0-RELEASE. In reality the steps are more or less the same.</p>
<p>First and for most, make sure that your ports are up to date. If you are using portupgrade like myself do a:</p>
<pre class="qoate-code"> portsnap fetch update &amp;&amp; portversion -v | grep "&lt;" </pre>
<p>This will so you which ports if any need to be updated. Read /usr/ports/UPDATING for special instructions on ports that might affect you and upgrade all your ports. Follow the instructions you read and after you finish if you are using portupgrade this will do the job:</p>
<pre class="qoate-code"> portupgrade -arR</pre>
<p>At this point you have your sources synchronized and your ports updated. Follow the instructions you read in the previous article with the exception of  running make installworld and mergemaster while in single user mode.</p>
<p>After your system boots it is time to rebuild all of your ports. If you are using portupgrade you will have to start by rubby:</p>
<pre class="qoate-code">
cd /usr/ports/lang/ruby18/
make deinstall &amp;&amp; make install clean</pre>
<pre class="qoate-code">
cd /usr/ports/ports-mgmt/portupgrade/
make deinstall &amp;&amp; make install clean</pre>
<p>Now that portupgrade is done continue with the rest:</p>
<pre class="qoate-code"> portupgrade -af</pre>
<p>This should be enough. Reboot your system and you will have a perfect functional upgraded FreeBSD.<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/12/05/freebsd-update2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FreeBSD Update, Upgrade</title>
		<link>http://www.aisecure.net/2011/12/04/freebsd-update/</link>
		<comments>http://www.aisecure.net/2011/12/04/freebsd-update/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 18:38:52 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=371</guid>
		<description><![CDATA[When I started using FreeBSD, there was only one way to upgrade. The source way. Today, I see that many people have started using the freebsd-update utility. I think it is good that a binary update option is available. But to be honest I have only used it once, out of curiosity mostly. Don&#8217;t get me &#8230;]]></description>
			<content:encoded><![CDATA[<p>When I started using FreeBSD, there was only one way to upgrade. The source way.</p>
<p>Today, I see that many people have started using the <a title="freebsd-update" href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/updating-upgrading-freebsdupdate.html" target="_blank">freebsd-update</a> utility. I think it is good that a binary update option is available. But to be honest I have only used it once, out of curiosity mostly. Don&#8217;t get me wrong I am not the type of person who believes in hard core solutions. I just feel that going source gives you more control. Besides, a relatively descent box will not need more than an hour for the whole procedure of building world &amp;&amp; kernel. Also, freebsd-update can not be used yet for tracking stable.</p>
<p>To all of you who want to go source but are afraid to,  keep reading.</p>
<p style="text-align: center;"><strong>Synchronize Source </strong></p>
<p>The first thing you have to do is to synchronize your sources with the release you want to follow. The <a title="cvsup" href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html" target="_blank">cvsup</a> utility was used for many years for this job. While it is still being described in the <a title="FreeBSD Handbook" href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/index.html" target="_blank">handbook</a> as a method of updating your sources it is considered obsolete and has been replaced by <a href="http://www.freebsd.org/cgi/man.cgi?query=csup&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD+8.2-RELEASE&amp;arch=default&amp;format=html" target="_blank">csup</a> which is integrated in to world. This means that you don&#8217;t need to install any extra packages in order to synchronize your sources.</p>
<p>You need however to use a sup file for the version you are following. In the directory below you will find many examples:</p>
<pre class="qoate-code">
# cd /usr/share/examples/cvsup/ &amp;&amp; ls
README doc-supfile ports-supfile refuse.README standard-supfilecvs-supfile gnats-supfile refuse stable-supfile www-supfile</pre>
<p>From all these files only 2 are the ones that we are interested in.</p>
<p><strong>stable-supfile</strong><br />
<strong> standard-supfile</strong></p>
<p>The first one is used to track stable while the second one is used for release. So, grab a copy of standard and copy it to a directory, I usually keep my sup files under /root</p>
<p>Lets spend a few minutes to examine the important lines here.</p>
<pre class="qoate-code">
# Defaults that apply to all the collections
#
# IMPORTANT: Change the next line to use one of the CVSup mirror sites
# listed at http://www.freebsd.org/doc/handbook/cvsup.html#CVSUP-MIRRORS.
*default host=CHANGE_THIS.FreeBSD.org</pre>
<p>This specifies from where to get the source tree.</p>
<pre class="qoate-code">*default host=cvsup.freebsd.org</pre>
<p>Is usually a good choice although you might consider using a mirror closer to you.</p>
<pre class="qoate-code">
# The following line is for 8-stable. If you want 7-stable, 6-stable,
# 5-stable, 4-stable, 3-stable, or 2.2-stable, change to "RELENG_7",
# "RELENG_6", "RELENG_5", "RELENG_4", "RELENG_3", or "RELENG_2_2"
# respectively.
*default release=cvs tag=RELENG_9_0
*default delete use-rel-suffix</pre>
<p>This is the most important part of the file. It specifies which source tree you wish to follow.<br />
If you are tracking 8-STABLE or 9-STABLE it should read like this:</p>
<pre class="qoate-code">*default release=cvs tag=RELENG_8</pre>
<pre class="qoate-code">*default release=cvs tag=RELENG_9</pre>
<p>If you want to track a RELEASE it should read like this:</p>
<pre class="qoate-code">*default release=cvs tag=RELENG_8_0</pre>
<pre class="qoate-code">*default release=cvs tag=RELENG_9_0</pre>
<p>The first specifies 8.0-RELEASE while the second specifies 9.0-RELEASE respectably.</p>
<p>So, go ahead and adjust your sup file with the mirror you want to grab the source from and the version you want to follow. A typical supfile for the upcoming 8.3-RELEASE will look like this:</p>
<pre class="qoate-code"># Defaults that apply to all the collections
#
# IMPORTANT: Change the next line to use one of the CVSup mirror sites
# listed at http://www.freebsd.org/doc/handbook/cvsup.html#CVSUP-MIRRORS.
*default host=cvsup.FreeBSD.org
*default base=/var/db
*default prefix=/usr
# The following line is for 8-stable. If you want 7-stable, 6-stable,
# 5-stable, 4-stable, 3-stable, or 2.2-stable, change to "RELENG_7",
# "RELENG_6", "RELENG_5", "RELENG_4", "RELENG_3", or "RELENG_2_2"
# respectively.
*default release=cvs tag=RELENG_8_3
*default delete use-rel-suffix</pre>
<p>Now that your supfile is complete, rename it into something memorable e.g release8.3 and fire csup with it.</p>
<pre class="qoate-code"> csup /root/release8.3</pre>
<p>After the process is finished you will have a complete functional source tree that you can use it to build FreeBSD and update your distribution.</p>
<p style="text-align: center;"><strong>UPDATE FREEBSD</strong></p>
<p>The whole procedure is divided into 4 different stages. Build world and kernel, Install kernel, Install world, mergemaster. After a while you will discover that those 4 different stages can be merged in 2. Build world and kernel, install kernel and world and mergemaster.</p>
<p><strong>1) Build everything</strong></p>
<pre class="qoate-code">
cd /usr/src
make -j8 buildworld &amp;&amp; make -j4 buildkernel</pre>
<address>Using the -j flag speeds up the process by assigning more than one make process each time. This is very much depended on the CPU cores that you have and the memory you can spare. I have seen that on a typical dualcore processor a -j6 is a good option.</address>
<p><strong>2) Install the new kernel</strong></p>
<pre class="qoate-code">
make install kernel
shutdown -r now
</pre>
<p><strong>3) Install the new world </strong></p>
<pre class="qoate-code">
cd /usr/src
make install world
</pre>
<p><strong>4) Run mergemaster</strong></p>
<pre class="qoate-code">mergemaster</pre>
<address>During mergemaster you will be asked to either install, delete or keep for later the new versions of configuration files. When in doubt choose keep! Never install new versions of passwd, group and master.passwd files. A good habit is to backup your /etc directory before.</address>
<p>That&#8217;s it, reboot once more and your system will be updated.</p>
<p>As I mentioned earlier there is a faster way of doing this without so many reboots.</p>
<pre class="qoate-code">
cd /usr/src &amp;&amp; make -j6 buildworld &amp;&amp; make -j4 buildkernel
make installkernel
make istallworld
mergemaster
shutdown -r now</pre>
<p>The above procedure is highly unorthodox but if you track STABLE regularly you will see that there are not so many changes in world and kernel.</p>
<p style="text-align: center;"><strong>Troubleshooting</strong></p>
<p>What to do if the world or kernel refuses to compile ?</p>
<p>If you track stable then there is a slight chance that your source tree is partially synchronized  or just happened to hit a bug in the road.</p>
<p>a) Use csup again, there is a chance that you have missed an update that perhaps is stalling the procedure.<br />
b) Check the stable mailing list for any know problems regarding the version you are following.<br />
c) Clean your source tree like this:</p>
<pre class="qoate-code">
chflags -R noschg /usr/obj/usr
rm -rf /usr/obj/usr
cd /usr/src
make cleandir
make cleandir
</pre>
<p>If you are tracking RELEASE then things should run more smoothly.</p>
<p>a) Make sure that you are following the correct RELEASE by checking your supfile.<br />
b) Repeat the above procedure for cleaning up your source tree.<br />
c) Remove any tuning you might have in make.conf</p>
<p style="text-align: center;"><strong>My kernel doesn&#8217;t boot !</strong></p>
<p style="text-align: left;">No problem, you can always boot your previous kernel. FreeBSD automatically saves your kernel in /boot/kernel.old The procedure is fairly easily, just choose command line from the boot menu and:</p>
<pre class="qoate-code">
&gt;unload
ok
&gt;load /boot/kernel.old/kernel.ko
&gt;ok
&gt;boot</pre>
<p><span style="text-decoration: underline;">Notes:</span><br />
In the handbook it is recommended to update the world files while in single user mode. During my involvement with FreeBSD, I saw that there is really no special need for this.</p>
<p>Next, see how to perform a major <a href="http://www.aisecure.net/2011/12/05/freebsd-update2/">UPGRADE</a></p>
<p><a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/12/04/freebsd-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Root on ZFS FreeBSD 9 (Updated)</title>
		<link>http://www.aisecure.net/2011/11/28/root-zfs-freebsd9/</link>
		<comments>http://www.aisecure.net/2011/11/28/root-zfs-freebsd9/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 14:14:04 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Root On ZFS]]></category>
		<category><![CDATA[ZFS]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[zfs]]></category>
		<category><![CDATA[zfs@root]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=353</guid>
		<description><![CDATA[This is an updated guide showing how you can install a full ZFS system using FreeBSD9. In this guide I will demonstrate how you can install a fully functional full ZFS FreeBSD9 using a GPT scheme. We will also use ZFS for SWAP You can use this as a reference guide for a single or &#8230;]]></description>
			<content:encoded><![CDATA[<p>This is an updated guide showing how you can install a full ZFS system using FreeBSD9.</p>
<p>In this guide I will demonstrate how you can install a fully functional full ZFS FreeBSD9 using a GPT scheme. We will also use ZFS for SWAP</p>
<p>You can use this as a reference guide for a single or mirror installation. </p>
<p><strong>(1) Boot from a FreeBSD9 installation DVD or memstick and choose &#8220;Live CD&#8221;.</strong></p>
<p><strong>(2) Create the necessary partitions on the disk(s) and add ZFS aware boot code.</strong></p>
<p>a) For a single disk installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpart create <span style="color: #660033;">-s</span> gpt ada0
gpart add <span style="color: #660033;">-b</span> <span style="color: #000000;">34</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">94</span> <span style="color: #660033;">-t</span> freebsd-boot ada0
gpart add <span style="color: #660033;">-t</span> freebsd-zfs <span style="color: #660033;">-l</span> disk0 ada0
gpart bootcode <span style="color: #660033;">-b</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>pmbr <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>gptzfsboot <span style="color: #660033;">-i</span> <span style="color: #000000;">1</span> ada0</pre></div></div>

<p>b) Repeat the procedure for the second drive if you want a mirror installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpart create <span style="color: #660033;">-s</span> gpt ada1
gpart add <span style="color: #660033;">-b</span> <span style="color: #000000;">34</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">94</span> <span style="color: #660033;">-t</span> freebsd-boot ada1
gpart add <span style="color: #660033;">-t</span> freebsd-zfs <span style="color: #660033;">-l</span> disk1 ada1
gpart bootcode <span style="color: #660033;">-b</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>pmbr <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>gptzfsboot <span style="color: #660033;">-i</span> <span style="color: #000000;">1</span> ada1</pre></div></div>

<p><strong>(3) Create the pool.(ignore any warnings regarding mounting) </strong></p>
<p>a) For a single disk installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zpool create zroot <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0</pre></div></div>

<p>b) For a mirror installation.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zpool create zroot mirror <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk0 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>gpt<span style="color: #000000; font-weight: bold;">/</span>disk1</pre></div></div>

<p><strong>(4) Set bootfs property, checksums and mountpoints. </strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zpool <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">bootfs</span>=zroot zroot
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">checksum</span>=fletcher4 zroot
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">mountpoint</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt zroot</pre></div></div>

<p><strong>(5)) At this point export and import the pool while preserving zroot.cache in /var/tmp.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zpool <span style="color: #7a0874; font-weight: bold;">export</span> zroot
zpool import <span style="color: #660033;">-o</span> <span style="color: #007800;">cachefile</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>zpool.cache zroot</pre></div></div>

<p><strong>(6) Create appropriate filesystems (feel free to improvise!).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>usr
zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>home
zfs create zroot<span style="color: #000000; font-weight: bold;">/</span>var
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>tmp
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>distfiles
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>packages
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>crash
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>pkg
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>empty
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=<span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=off <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run
zfs create <span style="color: #660033;">-o</span> <span style="color: #007800;">compression</span>=lzjb <span style="color: #660033;">-o</span> <span style="color: #007800;">exec</span>=on <span style="color: #660033;">-o</span> <span style="color: #007800;">setuid</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp</pre></div></div>

<p><strong>(7) Add swap space and disable checksums. In this case I add 4GB of swap.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zfs create <span style="color: #660033;">-V</span> 4G zroot<span style="color: #000000; font-weight: bold;">/</span>swap
zfs <span style="color: #000000; font-weight: bold;">set</span> org.freebsd:<span style="color: #007800;">swap</span>=on zroot<span style="color: #000000; font-weight: bold;">/</span>swap
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">checksum</span>=off zroot<span style="color: #000000; font-weight: bold;">/</span>swap</pre></div></div>

<p><strong>(8) Create a symlink to /home and fix some permissions.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">1777</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>mnt ; <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> usr<span style="color: #000000; font-weight: bold;">/</span>home home
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">1777</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp</pre></div></div>

<p><strong>(9) Instal FreeBSD.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sh</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>freebsd-dist
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DESTDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--unlink</span> <span style="color: #660033;">-xpJf</span> - <span style="color: #660033;">-C</span> <span style="color: #800000;">${DESTDIR:-/}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><strong>(10) Copy zpool.cache (very important!!!)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</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>zpool.cache <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>zfs<span style="color: #000000; font-weight: bold;">/</span>zpool.cache</pre></div></div>

<p><strong>(11) Create the rc.conf, loader.conf and an empty fstab (otherwise the system will complain).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'zfs_enable=&quot;YES&quot;'</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'zfs_load=&quot;YES&quot;'</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>loader.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'vfs.root.mountfrom=&quot;zfs:zroot&quot;'</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>loader.conf
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fstab</pre></div></div>

<p><strong>(12) Unmount everything and fix mountpoints for system boot.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">readonly</span>=on zroot<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>empty
zfs <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #660033;">-af</span>
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">mountpoint</span>=legacy zroot
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">mountpoint</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp zroot<span style="color: #000000; font-weight: bold;">/</span>tmp
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">mountpoint</span>=<span style="color: #000000; font-weight: bold;">/</span>usr zroot<span style="color: #000000; font-weight: bold;">/</span>usr
zfs <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">mountpoint</span>=<span style="color: #000000; font-weight: bold;">/</span>var zroot<span style="color: #000000; font-weight: bold;">/</span>var</pre></div></div>

<p>Reboot, adjust time zone info, add a password for root, add a user and enjoy!!!</p>
<p><strong>If you are looking for a 4K optimized guide see my <a href="http://www.aisecure.net/2012/01/16/rootzfs/" target="_blank">next</a> guide!</strong></p>
<p>&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/11/28/root-zfs-freebsd9/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Securing web application servers</title>
		<link>http://www.aisecure.net/2011/09/24/securing-web-application-servers/</link>
		<comments>http://www.aisecure.net/2011/09/24/securing-web-application-servers/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 12:53:20 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=261</guid>
		<description><![CDATA[Contrary to popular belief, firewalls are useless when it comes to securing web applications. I used the general term firewall because most people in the IT field, generally relate to.  But the correct term would be network firewall and that&#8217;s the one I will use in this post from now on. A network firewall like &#8230;]]></description>
			<content:encoded><![CDATA[<p>Contrary to popular belief, firewalls are useless when it comes to securing web applications. I used the general term firewall because most people in the IT field, generally relate to.  But the correct term would be network firewall and that&#8217;s the one I will use in this post from now on.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/osi.jpg"><img class="alignleft size-thumbnail wp-image-262" title="osi" src="http://www.aisecure.net/wp-content/uploads/2011/09/osi-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>A network firewall like the one you have in your company, works in the 3rd and 4th level of the OSI model. That is the network and transport layer. It&#8217;s primary role is to permit or deny packets to flow based upon certain access lists using statefull inspection. It can also detect and prevent certain network attacks .</p>
<p>An application firewall on the other hand works only in the 7th layer of the OSI model. It&#8217;s primary role is to inspect if a request that originates from a client towards the application server is legitimate. The application firewall will determine the legitimacy of that request based upon protocol enforcement and signatures that contain common illegitimate requests.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/firewall.jpg"><img class="alignleft size-thumbnail wp-image-266" title="firewall" src="http://www.aisecure.net/wp-content/uploads/2011/09/firewall-150x116.jpg" alt="" width="150" height="116" /></a></p>
<p>Today, most attacks occur on web applications and web servers that are exposed to the internet. Network firewalls allow incoming traffic to http &amp; https ports which means that our applications are exposed. The more complex an application is the more difficult is to secure it in the code level. Sql injections, code injections and cross site scripting attacks are them most common type of attacks. Here is where web application firewalls come in to give us a helping hand in avoiding this type of attacks. The bad thing is that they don&#8217;t come cheap. Fortunately there is open source software available and a very good and effective.</p>
<h3 style="text-align: center;">Implementing mod_security on FreeBSD</h3>
<p style="text-align: left;"><a title="mod_security" href="http://www.modsecurity.org/" target="_blank">Mod_security</a> started as an IDS for apache and has evolved into a powerful web application firewall that can be deployed in a web server. In FreeBSD it is offered from the ports collection but it is still in version 2.5.13.</p>
<p style="text-align: left;">
<pre class="qoate-code"> cd /usr/ports/www/mod_security/ &amp;&amp; make install clean</pre>
</p>
<p style="text-align: left;">This will install mod_security under <em>/usr/local/etc/apache22/Includes</em>. Contrary to the messages you will receive after the installation assuring you that everything has been configured, mode_security will need some further installation steps before it can work even in log only mode.</p>
<p style="text-align: left;">First you have to download the latest rules. You can grab the latest tarball from <a href="http://sourceforge.net/projects/mod-security/files/modsecurity-crs/0-CURRENT/" target="_blank">here</a>. Extract them and copy everything to <em>/usr/local/etc/apache22/Includes/mod_security2</em>. Your directory should look similar to this:</p>
<p style="text-align: left;">
<pre class="qoate-code">
drwxr-xr-x  9 root  wheel    15B Sep 12 22:18 .
drwxr-xr-x  3 root  wheel    20B Sep 15 14:02 ..
-rw-r--r--  1 root  wheel    27k Nov 29  2010 CHANGELOG
-rw-r--r--  1 root  wheel    17k Nov 29  2010 LICENSE
-rw-r--r--  1 root  wheel    16k Nov 29  2010 README
drwxr-xr-x  2 root  wheel    24B Sep 21 13:49 activated_rules
drwxr-xr-x  2 root  wheel    24B Jul 20 19:42 base_rules
drwxr-xr-x  2 root  wheel    18B Jul 20 19:42 experimental_rules
drwxr-xr-x  2 root  wheel     6B Jul 20 19:42 lua
-rw-r--r--  1 root  wheel     8k Sep 13 12:01 modsecurity_crs_10_config.conf
-rw-r--r--  1 root  wheel   2.7k Nov 29  2010 modsecurity_crs_48_local_exceptions.conf.example
drwxr-xr-x  2 root  wheel    18B Jul 20 19:42 optional_rules
drwxr-xr-x  2 root  wheel    30B Jul 20 19:42 slr_rules
drwxr-xr-x  2 root  wheel     9B Sep 12 19:27 util
</pre>
</p>
<p style="text-align: left;">Now, edit <em>/usr/local/etc/apache22/Includes/mod_security2.conf</em>  and change the values to reflect the location of your configuration files.</p>
<p style="text-align: left;">
<pre class="qoate-code">
Include /usr/local/etc/apache22/Includes/mod_security2/*.conf
Include /usr/local/etc/apache22/Includes/mod_security2/activated_rules/*.conf
</pre>
</p>
<p style="text-align: left;">As you see above there is a directory called <em>/activated_rules</em>. A good practice is to use this directory for all your rules and copy there all rules you wish to enable from other directories. Start by copying the <em>base_rules</em>. That way when you change a rule you can still have the original copy kept.</p>
<p style="text-align: left;">It is time now to navigate and explore the <em>modsecurity_crs_10_config.conf</em> located in the base directory of mod_security installation which is located under: <em>/usr/local/etc/apache22/Includes/mod_security2/</em></p>
<p style="text-align: left;">This file contains the core configuration of mod_security and it is pretty well commented so it is worth browsing it for a while. Keep backups and start adjusting the values to suit your needs. However, like I mentioned earlier, the default configuration doesn&#8217;t block anything so once you are comfortable with it you will have to make a few adjustments.</p>
<p style="text-align: center;"><strong>WARNING WARNUNG ADVERTENCIA</strong></p>
<p style="text-align: left;">The following changes will put mod_security in blocking mode. Try them on a testing environment before putting them into production.</p>
<p style="text-align: left;">Activate rules</p>
<pre class="qoate-code">
SecRuleEngine On
SecDefaultAction log,auditlog,pass,status:403,phase:2,t:lowercase</pre>
<p>Enable the audit engine for relevant traffic only. Don&#8217;t forget to rotate the logs later.</p>
<pre class="qoate-code">
SecAuditEngine RelevantOnly
SecAuditLog /var/log/httpd-audit.log</pre>
<p>Restart apache, check that your sites are working and keep an eye on <em>httpd-error.log</em> . That is where mode_security logs all denied traffic. One thing is for sure, you will get a few false positives. The good thing is that you can catch them very fast if you have someone trying to access all the applications that you serve.</p>
<p>The files that according to my experience will create the most false positives are:</p>
<ul>
<li>modsecurity_crs_20_protocol_violations.conf</li>
</ul>
<ul>
<li>modsecurity_crs_41_sql_injection_attacks.conf</li>
</ul>
<p>The error logs will tell you the type of violation, the file and the line. So, you can act accordingly. If you feel that this is legit traffic then just comment the rule.</p>
<p>With mod_security the sky is the limit. You can create your own rules, create exceptions for certain applications, use rules that are specific to popular open source CMS.</p>
<p style="text-align: center;"><strong>Effective defense</strong></p>
<p>Mod_security is only a tool to protect you against malicious attacks. Installing a web application firewall does not make you immune to hackers.</p>
<ul>
<li>Keep your access and errors logs for at least for a week. Make a habit of examining the error logs daily and combine them with access logs. That way you will know better how an intruder is targeting your site(s).</li>
</ul>
<ul>
<li>Research the offensive IPs. Just a simple whois can reveal valuable information. You will often find that a certain type of attack originates from many different IPs. Look for a pattern, most likely they will come from the same ISP or from ISPs that belong to a certain country or area.</li>
</ul>
<ul>
<li>Port scanning is considered illegitimate and should not be used without prior approval. However, you have every right to use it against offensive IPs. In most cases it will reveal that your attackers are <a href="http://en.wikipedia.org/wiki/Zombie_%28computer_science%29" target="_blank">zombies. </a></li>
</ul>
<ul>
<li>Finally, use your network firewall to block those IPs before they reach your web server.</li>
</ul>
<p>&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD"/></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/09/24/securing-web-application-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OS X Lion when will it snow&#8230;</title>
		<link>http://www.aisecure.net/2011/09/21/os-x-lion-when-will-it-snow/</link>
		<comments>http://www.aisecure.net/2011/09/21/os-x-lion-when-will-it-snow/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 19:25:10 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[apple]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=218</guid>
		<description><![CDATA[I use a MacBook since late 2007 when I realized that Linux, is not my OS choice and FreeBSD needs a lot of time to spend, in order to keep your ports up to date.  My desktop needs are not that demanding. Email, web and terminal are my basic daily needs, although a word processor &#8230;]]></description>
			<content:encoded><![CDATA[<p>I use a MacBook since late 2007 when I realized that Linux, is not my OS choice and FreeBSD needs a lot of time to spend, in order to keep your ports up to date.  My desktop needs are not that demanding. Email, web and terminal are my basic daily needs, although a word processor usually comes in handy every once in a while.</p>
<p>At that time the 13 inch 2.2GH Intel Core2Duo MacBook with 1Gb Ram looked very promising.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/macbook.jpg"><img class="alignleft size-thumbnail wp-image-222" title="macbook" src="http://www.aisecure.net/wp-content/uploads/2011/09/macbook-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>Bundled with Leopard, the successor of Tiger, it run really well and covered almost all of my needs. I used to get 4 hours of real battery time and I was very happy. Although I always though that the hardware was overpriced. I got so used to that thing that I decided to upgrade the memory because I wanted to run a couple of virtual machines as well. I must admit that with 2Gb Ram the MacBook became really fast. I started installing new software, got mac ports working too!</p>
<p>&nbsp;</p>
<p>And then came Snow Leopard.  I was a bit skeptical to upgrade because there weren&#8217;t many new features. But it turned out that this was a <em>good thing</em>. In fact, you could say that Snow Leopard was the perfect continuation of Leopard. The OS became much faster, more reliable and less memory hungry. It was for me the ultimate OS one could pay for.</p>
<p>In the mean time, Apple started making tons of money and saw their stock price go high, by selling cell phones. Well, they called them smartphones but if you think about it for a while they are just overpriced cell phones. Those cell phones were based on a closed source hybrid darwin kernel with many bugs. Apple thinks that this new type of software should be passed on to personal computers as well. So, OS X Lion was born&#8230;</p>
<p style="text-align: center;"><strong>Why Lion Sucks</strong></p>
<p style="text-align: center;"><em>Some features that supposedly will change the way you work:</em></p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/icon_gestures.png"><img class="size-full wp-image-225 alignleft" title="icon_gestures" src="http://www.aisecure.net/wp-content/uploads/2011/09/icon_gestures.png" alt="" width="60" height="60" /></a></p>
<p>&nbsp;</p>
<p>Multi-Touch Gestures</p>
<p>It is so useless that I wouldn&#8217;t even mention anything about this. Except Apple who things that is so cool that it has to be the number one new feature in their web side about Lion.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/fullscreen.png"><img class="alignleft size-full wp-image-228" title="fullscreen" src="http://www.aisecure.net/wp-content/uploads/2011/09/fullscreen.png" alt="" /></a></p>
<p>&nbsp;</p>
<p>Full-Screen Apps</p>
<p>That was something missing (?) Most OS can run an application in full screen and they don&#8217;t need to brag about it. With a Mac it is different because many applications refuse to resize properly in full screen mode. Unfortunately for Lion, and for you, if you try this you will soon end up searching how to escape from this mode. It is so annoying and complicated that I only used it once.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/missoncontrol.png"><img class="alignleft size-full wp-image-231" title="missoncontrol" src="http://www.aisecure.net/wp-content/uploads/2011/09/missoncontrol.png" alt="" /></a></p>
<p>&nbsp;</p>
<p>Mission Control</p>
<p>A better version of  &#8220;expose&#8221;. Nothing fancy, but nice to have.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/appstore.png"><img class="alignleft size-full wp-image-232" title="appstore" src="http://www.aisecure.net/wp-content/uploads/2011/09/appstore.png" alt="" /></a></p>
<p>&nbsp;</p>
<p>Mac App Store</p>
<p>This is hardly a Lion feature. The App Store is available for Snow Leopard as well.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/launchpad.png"><img class="alignleft size-full wp-image-235" title="launchpad" src="http://www.aisecure.net/wp-content/uploads/2011/09/launchpad.png" alt="" /></a></p>
<p>&nbsp;</p>
<p>Launchpad</p>
<p>I don&#8217;t really need a Iphone style application menu. But again it is good to have.</p>
<p><a href="http://www.aisecure.net/wp-content/uploads/2011/09/resume.png"><img class="alignleft size-full wp-image-238" title="resume" src="http://www.aisecure.net/wp-content/uploads/2011/09/resume.png" alt="" /></a></p>
<p>&nbsp;</p>
<p>Resume</p>
<p>Here things begin to get ugly. You open your wordproccessor and suddenly the last document you were working on appears. Hey, I am not that lazy, if I need that document I will open it again. It really sucks though when I have to close it just because Apple thinks I will work on it again.</p>
<p style="text-align: center;"> <em><strong>Some facts that will definitely change the way you work:</strong></em></p>
<ul>
<li> If you have 2Gb of Ram then you can just forget about it. Lion does very bad memory management and you soon end up drained, swaping for some memory.</li>
</ul>
<ul>
<li>Your battery will drain very quick. I have read a few discussions regarding how Lion needs better battery calibration. Sorry but this is BS. The only reason why the battery time is reduced is because your CPU will work more intensively and your load averages will increase. When this happens the CPU temperature also rises and as a result the fans start spinning like hell. And it all come down to higher energy consumption.</li>
</ul>
<ul>
<li>Be prepared to use the disk utility quite often since you will have to repair disk permissions very often.</li>
</ul>
<ul>
<li>If you happen to own a NAS (Network Area Storage) to store and share your documents you might experience some issues with Samba protocol. AFP seems to be working without problems.</li>
</ul>
<ul>
<li>Generally, you will have to be more patient as it will take more time for your applications to load. But don&#8217;t worry you can always get to watch the apple mouse spinning ball while you wait. Sometimes they might even crash also.</li>
</ul>
<p><em>to be continued &#8230;</em> (till then I switched back to Snow Leopard)<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD"/></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/09/21/os-x-lion-when-will-it-snow/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>FreeBSD and OS X Lion Time machine</title>
		<link>http://www.aisecure.net/2011/08/02/freebsd-and-os-x-lion-time-machine/</link>
		<comments>http://www.aisecure.net/2011/08/02/freebsd-and-os-x-lion-time-machine/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 12:24:42 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=204</guid>
		<description><![CDATA[Time machine for Mac OSX was introduced in Leopard 10.5.0 and it is certainly a very nice feature for maintaining backups of your MAC. But until today you had to use an external disk or Apple&#8217;s Time Capsule in order for this to work. There have been some workarounds for using a NAS over CIFS &#8230;]]></description>
			<content:encoded><![CDATA[<p>Time machine for Mac OSX was introduced in Leopard 10.5.0 and it is certainly a very nice feature for maintaining backups of your MAC. But until today you had to use an external disk or Apple&#8217;s Time Capsule in order for this to work. There have been some workarounds for using a NAS over CIFS or Samba but those where not officially supported by Apple.</p>
<p>In OS X Lion 10.7.0 there is finally the option to use TimeMachine over your network as long as your storage supports <a href="http://en.wikipedia.org/wiki/Apple_Filing_Protocol" target="_blank">AFP</a> the Apple Filing Protocol.  Apple still recommends that you run OS X Lion server but as we will see it works pretty well with FreeBSD so now you can use your NAS to keep those backups, or even create a central repository for all the clients.</p>
<ul>
<li>First you have to install the AFP protocol provided by NetATalk.</li>
</ul>
<p><span style="color: #ff0000;">Important!!! Make sure that you only select APPLETALK and remove ZEROCONF from the options!</span></p>
<pre class="qoate-code">cd /usr/ports/net/netatalk/ &amp;&amp; make install clean</pre>
<ul>
<li>Next edit /usr/local/etc/AppleVolumes.default and adjust to your needs:</li>
</ul>
<pre class="qoate-code">/tank/apple/ Time Machine allow:gkontos options:tm,usedots</pre>
<ul>
<li>Add the following to your rc.conf:</li>
</ul>
<pre class="qoate-code">netatalk_enable="YES"
cnid_metad_enable="YES"
afpd_enable="YES"</pre>
<ul>
<li>Start the service</li>
</ul>
<pre class="qoate-code">/usr/local/etc/rc.d/netatalk start</pre>
<p>And you are ready to connect, afp://xxx.xxx.xxx.xxx</p>
<p>Now open your Time Machine preferences and select your new volume as the backup volume. You should be able to run Time machine and backup your files.  Some extra configuration is needed in order to be able to perform a full restore with the boot DVD.<strong><br />
</strong></p>
<ul>
<li>Install Apple&#8217;s mDNSResponder:</li>
</ul>
<pre class="qoate-code">cd /usr/ports/net/mDNSResponder &amp;&amp; make install clean</pre>
<ul>
<li>Create the file /usr/local/etc/rc.d/mdnsadv with the following content:</li>
</ul>
<pre class="qoate-code">
#!/bin/sh

# PROVIDE: mdnsadv
# REQUIRE: LOGIN mdnsd
#
# Add the following lines to /etc/rc.conf to enable the mDNSResponder service advertising:
#
# mdnsadv_enable="YES"

. /etc/rc.subr

name="mdnsadv"
rcvar=${name}_enable

command="/usr/local/bin/mDNSResponderPosix"

load_rc_config $name

: ${mdnsadv_enable="NO"}

command_args="-f /usr/local/etc/mdnsadv.conf &gt;/dev/null 2&gt;&amp;1 &amp;"

run_rc_command "$1"</pre>
<ul>
<li>Don&#8217;t forget to make the file executable by issuing:</li>
</ul>
<pre class="qoate-code">chmod ugo+x /usr/local/etc/rc.d/mdnsadv</pre>
<ul>
<li>Create the advertising configuration file /usr/local/etc/mdnsadv.conf with the following contents:</li>
</ul>
<pre class="qoate-code">AFP Server
_afpovertcp._tcp
548
title='File Server'

TM Volume
_adisk._tcp
9
sys=waMA=XX:XX:XX:XX:XX:XX,adVF=0x100
dk0=adVF=0x83,adVN=Backup</pre>
<p>XX:XX:XX:XX:XX:XX is your storage mac address.</p>
<ul>
<li>Add to /etc/rc.conf the following line:</li>
</ul>
<pre class="qoate-code">mdnsadv_enable="YES"</pre>
<p>Now start mdnsadv service and you will be able to do a full restore from Apple&#8217;s boot DVD.</p>
<p><strong>UPDATE</strong> <em>October 2011</em></p>
<p>It looks like this will also work with Snow Leopard at least in version 10.6.8<br />
&nbsp;<br />
<a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD"/></a><br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2011/08/02/freebsd-and-os-x-lion-time-machine/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

