<?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, 19 Jun 2013 11:19:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Hetzner Hacked!</title>
		<link>http://www.aisecure.net/2013/06/06/hetzner-hacked/</link>
		<comments>http://www.aisecure.net/2013/06/06/hetzner-hacked/#comments</comments>
		<pubDate>Thu, 06 Jun 2013 16:35:55 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Hetzner]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=675</guid>
		<description><![CDATA[I have been complaining about Hetzner regarding their retarded support system as well as their bandwidth and security issues. I remember once that when I asked for remote console they gave me another customer&#8217;s server. I could reboot it, mount my own ISO and change the root password. Now comes this: Dear Client At the &#8230;]]></description>
				<content:encoded><![CDATA[<p>I have been complaining about Hetzner regarding their retarded support system as well as their bandwidth and security issues.</p>
<p>I remember once that when I asked for remote console they gave me another customer&#8217;s server. I could reboot it, mount my own ISO and change the root password.</p>
<p>Now comes this:</p>
<blockquote><p>Dear Client</p>
<p>At the end of last week, Hetzner technicians discovered a &#8220;backdoor&#8221; in one<br />
of our internal monitoring systems (Nagios).</p>
<p>An investigation was launched immediately and showed that the administration<br />
interface for dedicated root servers (Robot) had also been affected. Current<br />
findings would suggest that fragments of our client database had been copied<br />
externally.</p>
<p>As a result, we currently have to consider the client data stored in our Robot<br />
as compromised.</p>
<p>To our knowledge, the malicious program that we have discovered is as yet<br />
unknown and has never appeared before.</p>
<p>The malicious code used in the &#8220;backdoor&#8221; exclusively infects the RAM. First<br />
analysis suggests that the malicious code directly infiltrates running Apache<br />
and sshd processes. Here, the infection neither modifies the binaries of the<br />
service which has been compromised, nor does it restart the service which has<br />
been affected.</p>
<p>The standard techniques used for analysis such as the examination of checksum<br />
or tools such as &#8220;rkhunter&#8221; are therefore not able to track down the malicious<br />
code.</p>
<p>We have commissioned an external security company with a detailed analysis of<br />
the incident to support our in-house administrators. At this stage, analysis<br />
of the incident has not yet been completed.</p>
<p>The access passwords for your Robot client account are stored in our database<br />
as Hash (SHA256) with salt. As a precaution, we recommend that you change your<br />
client passwords in the Robot.</p>
<p>With credit cards, only the last three digits of the card number, the card type<br />
and the expiry date are saved in our systems. All other card data is saved<br />
solely by our payment service provider and referenced via a pseudo card number.<br />
Therefore, as far as we are aware, credit card data has not been compromised.</p>
<p>Hetzner technicians are permanently working on localising and preventing possible<br />
security vulnerabilities as well as ensuring that our systems and infrastructure<br />
are kept as safe as possible. Data security is a very high priority for us. To<br />
expedite clarification further, we have reported this incident to the data<br />
security authority concerned.</p>
<p>Furthermore, we are in contact with the Federal Criminal Police Office (BKA) in<br />
regard to this incident.</p>
<p>Naturally, we shall inform you of new developments immediately.</p>
<p>We very much regret this incident and thank you for your understanding and<br />
trust in us.</p>
<p>A special FAQs page has been set up at<br />
<a href="http://wiki.hetzner.de/index.php/Security_Issue/en" target="_blank">http://wiki.hetzner.de/index.php/Security_Issue/en</a> to assist you with further<br />
enquiries.</p>
<p>Kind regards</p>
<p>Martin Hetzner</p>
<p>Hetzner Online AG<br />
Stuttgarter Str. 1<br />
91710 Gunzenhausen / Germany<br />
Tel: +49 (9831) 61006-1<br />
Fax: +49 (9831) 61006-2<br />
<a href="mailto:security-mailing@hetzner.de">security-mailing@hetzner.de</a><br />
<a href="http://www.hetzner.com/" target="_blank">http://www.hetzner.com</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2013/06/06/hetzner-hacked/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tunneling IPv4 over IPv6 VPN</title>
		<link>http://www.aisecure.net/2013/02/03/tunneling-ipv4-over-ipv6-vpn/</link>
		<comments>http://www.aisecure.net/2013/02/03/tunneling-ipv4-over-ipv6-vpn/#comments</comments>
		<pubDate>Sun, 03 Feb 2013 14:45:44 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[ipv6]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=637</guid>
		<description><![CDATA[Tunnels are often used to encapsulate IPv6 traffic over IPv4 links. This time we are going to do the reverse. Imagine that you have native IPv6 on two endpoints. Behind those two endpoints you also have non routable IPv4 addresses. We are going to create a IPv6 tunnel for IPv4 traffic and we are going &#8230;]]></description>
				<content:encoded><![CDATA[<p>Tunnels are often used to encapsulate IPv6 traffic over IPv4 links. This time we are going to do the reverse.<br />
Imagine that you have native IPv6 on two endpoints. Behind those two endpoints you also have non routable IPv4 addresses. We are going to create a IPv6 tunnel for IPv4 traffic and we are going to add IPsec.</p>
<p>Let us start by creating the tunnel.</p>
<p><strong>Endpoint1</strong><br />
IPv6 address: fd58:0c86:b78c:d09a::86<br />
IPv4 network: 10.10.10.0/24</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#ifconfig gif0 create</span>
<span style="color: #666666; font-style: italic;">#ifconfig gif0 ipv6 tunnel fd58:0c86:b78c:d09a::86 fd85:af00:29c1:f685::2093</span>
<span style="color: #666666; font-style: italic;">#ifconfig gif0 alias 10.10.10.4 10.1.1.3</span></pre></td></tr></table></div>

<p><strong>Endpoint2</strong><br />
IPv6 address: fd85:af00:29c1:f685::2093<br />
IPv4 network: 10.1.1.0/24</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#ifconfig gif0 create</span>
<span style="color: #666666; font-style: italic;">#ifconfig gif0 ipv6 tunnel fd85:af00:29c1:f685::2093 fd58:0c86:b78c:d09a::86</span>
<span style="color: #666666; font-style: italic;">#ifconfig gif0 alias 10.1.1.3 10.10.10.4</span></pre></td></tr></table></div>

<p>At this point the tunnel should be up and endpoint1 can ping endpoint2</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ping</span> 10.1.1.3
PING 10.1.1.3 <span style="color: #7a0874; font-weight: bold;">&#40;</span>10.1.1.3<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #000000;">56</span> data bytes
<span style="color: #000000;">64</span> bytes from 10.1.1.3: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">0</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">64</span> <span style="color: #007800;">time</span>=<span style="color: #000000;">187.772</span> ms
<span style="color: #000000;">64</span> bytes from 10.1.1.3: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">64</span> <span style="color: #007800;">time</span>=<span style="color: #000000;">184.516</span> ms
<span style="color: #000000;">64</span> bytes from 10.1.1.3: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">2</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">64</span> <span style="color: #007800;">time</span>=<span style="color: #000000;">185.563</span> ms</pre></td></tr></table></div>

<p>Time to add IPsec into the game. For this you will need to compile your KERNEL adding the following options:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">OPTIONS      IPSEC
DEVICE       crypto</pre></td></tr></table></div>

<p>Now, install ipsec-tools on both endpoints:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>security<span style="color: #000000; font-weight: bold;">/</span>ipsec-tools <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></td></tr></table></div>

<p>I usually keep all my configuration files in /usr/local/etc/racoon This directory does not exist so you will need to create it.</p>
<p><strong>Working configuration for endpoint1:</strong></p>
<p><strong>psk.conf</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">fd58:0c86:b78c:d09a::<span style="color: #000000;">86</span> averystrongsecret</pre></td></tr></table></div>

<p><strong>setkey.conf</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">flush;
spdflush;
spdadd fd85:af00:29c1:f685::<span style="color: #000000;">2093</span> fd58:0c86:b78c:d09a::<span style="color: #000000;">86</span> any <span style="color: #660033;">-P</span> out ipsec esp<span style="color: #000000; font-weight: bold;">/</span>transport<span style="color: #000000; font-weight: bold;">//</span>require;
spdadd fd58:0c86:b78c:d09a::<span style="color: #000000;">86</span> fd85:af00:29c1:f685::<span style="color: #000000;">2093</span> any <span style="color: #660033;">-P</span> <span style="color: #000000; font-weight: bold;">in</span> ipsec esp<span style="color: #000000; font-weight: bold;">/</span>transport<span style="color: #000000; font-weight: bold;">//</span>require;</pre></td></tr></table></div>

<p><strong>racoon.conf</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">path include <span style="color: #ff0000;">&quot;/usr/local/etc/racoon&quot;</span> ;
path    pre_shared_key  <span style="color: #ff0000;">&quot;/usr/local/etc/racoon/psk.txt&quot;</span>; <span style="color: #666666; font-style: italic;">#location of pre-shared key file</span>
log     notify;	<span style="color: #666666; font-style: italic;">#log verbosity setting: set to 'notify' when testing and debugging is complete</span>
&nbsp;
padding	<span style="color: #666666; font-style: italic;"># options are not to be changed</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        maximum_length  <span style="color: #000000;">20</span>;
        randomize       off;
        strict_check    off;
        exclusive_tail  off;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
timer	<span style="color: #666666; font-style: italic;"># timing options. change as needed</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        counter         <span style="color: #000000;">5</span>;
        interval        <span style="color: #000000;">20</span> sec;
        persend         <span style="color: #000000;">1</span>;
<span style="color: #666666; font-style: italic;">#       natt_keepalive  15 sec;</span>
        phase1          <span style="color: #000000;">30</span> sec;
        phase2          <span style="color: #000000;">15</span> sec;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
listen	<span style="color: #666666; font-style: italic;"># address [port] that racoon will listening on</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        isakmp          fd85:af00:29c1:f685::<span style="color: #000000;">2093</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">500</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
remote  fd58:0c86:b78c:d09a::<span style="color: #000000;">86</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">500</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        exchange_mode   main,aggressive;
        doi             ipsec_doi;
        situation       identity_only;
        lifetime        <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #000000;">8</span> hour;
        passive         off;
        proposal_check  obey;
<span style="color: #666666; font-style: italic;">#       nat_traversal   off;</span>
        generate_policy off;
&nbsp;
                        proposal <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                                encryption_algorithm    blowfish;
                                hash_algorithm          md5;
                                authentication_method   pre_shared_key;
                                lifetime <span style="color: #000000; font-weight: bold;">time</span>           <span style="color: #000000;">30</span> sec;
                                dh_group                <span style="color: #000000;">1</span>;
                        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
sainfo anonymous 	<span style="color: #666666; font-style: italic;"># address $network/$netmask $type address $network/$netmask $type ( $type being any or esp)</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>								<span style="color: #666666; font-style: italic;"># $network must be the two internal networks you are joining.</span>
        pfs_group       <span style="color: #000000;">1</span>;
        lifetime        <span style="color: #000000; font-weight: bold;">time</span>    <span style="color: #000000;">36000</span> sec;
        encryption_algorithm    blowfish,3des,des;
        authentication_algorithm        hmac_md5,hmac_sha1;
        compression_algorithm   deflate;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><strong>The same but opposite configuration should be applied to endpoint2!</strong></p>
<p>Modify /etc/rc.conf</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">ipsec_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">ipsec_file</span>=<span style="color: #ff0000;">&quot;/usr/local/etc/racoon/setkey.conf&quot;</span>
<span style="color: #007800;">racoon_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">racoon_flags</span>=<span style="color: #ff0000;">&quot;-l /var/log/racoon.log&quot;</span></pre></td></tr></table></div>

<p>Assuming there is no firewall running at both endpoints you can start ipsec and racoon and all communication from endpoint1 to endpoint2 will be encrypted.<br />
&nbsp;<br />
The following is a minimal PF configuration that will allow this to happen:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">pass <span style="color: #000000; font-weight: bold;">in</span> log on <span style="color: #007800;">$ext_if</span> proto esp from <span style="color: #007800;">$vpn_gateway</span> 
pass <span style="color: #000000; font-weight: bold;">in</span> log on <span style="color: #007800;">$ext_if</span> proto ah from <span style="color: #007800;">$vpn_gateway</span>
pass <span style="color: #000000; font-weight: bold;">in</span> log on <span style="color: #007800;">$ext_if</span> proto ipencap from <span style="color: #007800;">$vpn_gateway</span>
pass <span style="color: #000000; font-weight: bold;">in</span> log on <span style="color: #007800;">$ext_if</span> inet6 proto udp from <span style="color: #007800;">$vpn_gateway</span> to any port <span style="color: #000000;">500</span></pre></td></tr></table></div>

<p><strong>At this point all traffic should be traveling encrypted!</strong><br />
&nbsp;<br />
Finally modify again your /etc/rc.conf so that the tunnel comes up after a reboot:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">cloned_interfaces</span>=<span style="color: #ff0000;">&quot;gif0&quot;</span>
<span style="color: #007800;">gif_interfaces</span>=<span style="color: #ff0000;">&quot;gif0&quot;</span>
<span style="color: #007800;">ifconfig_gif0_ipv6</span>=<span style="color: #ff0000;">&quot;inet6 tunnel fd85:af00:29c1:f685::2093 fd58:0c86:b78c:d09a::86&quot;</span>
<span style="color: #007800;">ifconfig_gif0</span>=<span style="color: #ff0000;">&quot;alias 10.10.10.4 10.1.1.3&quot;</span></pre></td></tr></table></div>

<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;<br />
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2013/02/03/tunneling-ipv4-over-ipv6-vpn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPv6 Facts</title>
		<link>http://www.aisecure.net/2012/09/17/ipv6-facts/</link>
		<comments>http://www.aisecure.net/2012/09/17/ipv6-facts/#comments</comments>
		<pubDate>Mon, 17 Sep 2012 15:47:15 +0000</pubDate>
		<dc:creator>gkontos</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ipv6]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.aisecure.net/?p=552</guid>
		<description><![CDATA[The IPv6 world launch day has come and gone. But how ready are we for IPv6? According to google we are not that ready yet. The fact is that goolge is not fully ready either! Their ads do not display over an IPv6 only network. This post is the beginning of a series regarding a full dual stack implementation &#8230;]]></description>
				<content:encoded><![CDATA[<div id=ipv6_enabled_www_test_logo></div>
<p><script language="JavaScript" type="text/javascript">
    	var Ipv6_Js_Server = (("https:" == document.location.protocol) ? "https://" : "http://");
	document.write(unescape("%3Cscript src='" + Ipv6_Js_Server + "www.ipv6forum.com/ipv6_enabled/sa/SA1.php?id=3392' type='text/javascript'%3E%3C/script%3E"));
</script><br />
The IPv6 world launch day has come and gone. But how ready are we for IPv6?</p>
<p>According to <a title="IPv6 Statistics" href="http://www.google.com/ipv6/statistics.html" target="_blank">google</a> we are not that ready yet. The fact is that goolge is not fully ready either! Their ads do not display over an IPv6 only network.</p>
<p>This post is the beginning of a series regarding a full dual stack implementation using FreeBSD as a dual stack Web Server, Mail server and DNS server. We will also cover the basic topics on how to implement a full dual stack network using FreeBSD as a IPv4 &amp; IPv6 router/firewall.</p>
<p>For the time being, aisecure.net is a full dual stack web site. Meaning that it uses dual stack DNS servers, dual stack Web Server and dual stack mail server.</p>
<p>Most sites that get an IPv6 validation would not work if IPv4 was completely gone! Why? Because they rely on IPv4 only DNS servers that simply have AAAA records.</p>
<p>First of all lets see some interesting facts about IPv6:</p>
<p><strong>IPsec</strong></p>
<p>IPSec, is a framework of open standards that define policies for secure communication in a network. In addition, these standards also describe how to enforce these policies. Some of the interesting features of IPsec are:</p>
<ul>
<li>AH (Authentication Header) that provides authenticity guarantee for transported packets.</li>
<li>ESP (Encapsulating Security Payload) that provides encryption of packets.</li>
</ul>
<p>The most interesting feature is ESP which provides confidentiality. In other words, by using ESP all traffic between 2 hosts is encrypted.</p>
<p>When IPv6 was designed IPsec was supposed to be mandatory. Every IP communication used by IPv6 must use IPsec. Unfortunately, recent RFCs have changed the word &#8220;must&#8221; to &#8220;should&#8221;.  See <a href="http://www.ripe.net/ripe/docs/current-ripe-documents/ripe-554" target="_blank">here</a> for more details.</p>
<p>In FreeBSD if we want to take advantage of the IPsec we still need to compile a new KERNEL as described in the <a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ipsec.html" target="_blank">handbook</a>. I personally find this to be very disturbing and I believe that this option should be default.</p>
<p><strong>IPv6 address space</strong></p>
<p>The 128 bits of IPv6 addresses mean the size of the IPv6 address space is, quite literally, astronomical, like the numbers that describe the number of stars in a galaxy or the distance to the furthest pulsars, the number of addresses that can be supported in IPv6 is mind-boggling.</p>
<p>Since IPv6 addresses are 128 bits long, the theoretical address space if all addresses were used is 2<sup>128</sup> addresses. This number, when expanded out, is 340,282,366,920,938,463,463,374,607,431,768,211,456, which is normally expressed in scientific notation as about 3.4*10<sup>38</sup> addresses.</p>
<p><strong>Types and categories</strong></p>
<p>The type of a IPv6 address is identified by the high-order bits of the address.</p>
<p>Three categories of IP addresses are supported in IPv6:</p>
<ul>
<li>Unicast</li>
</ul>
<p>An identifier for a single interface. A packet sent to a unicast address is delivered to the interface identified by that address. It can be link-local scope, site-local scope, or global scope.</p>
<ul>
<li>Multicast</li>
</ul>
<p>An identifier for a group of interfaces (typically belonging to different nodes). A packet sent to a multicast address is delivered to all interfaces identified by that address.</p>
<ul>
<li>Anycast</li>
</ul>
<p>An identifier for a group of interfaces (typically belonging to different nodes). A packet sent to an anycast address is delivered to the closest member of a group, according to the routing protocols&#8217; measure of distance.</p>
<div></div>
<p>&nbsp;</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/2012/09/17/ipv6-facts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1#</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>hastd start</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2#</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>hastd start</pre></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1#</span>hastctl role init disk1
<span style="color: #666666;">hast1#</span>hastctl role init disk2
<span style="color: #666666;">hast1#</span>hastctl role init disk3
<span style="color: #666666;">hast1#</span>hastctl create disk1
<span style="color: #666666;">hast1#</span>hastctl create disk2
<span style="color: #666666;">hast1#</span>hastctl create disk3
<span style="color: #666666;">hast1#</span>hastctl role primary disk1
<span style="color: #666666;">hast1#</span>hastctl role primary disk2
<span style="color: #666666;">hast1#</span>hastctl role primary disk3</pre></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2#</span>hastctl role init disk1
<span style="color: #666666;">hast2#</span>hastctl role init disk2
<span style="color: #666666;">hast2#</span>hastctl role init disk3
<span style="color: #666666;">hast2#</span>hastctl create disk1
<span style="color: #666666;">hast2#</span>hastctl create disk2
<span style="color: #666666;">hast2#</span>hastctl create disk3
<span style="color: #666666;">hast2#</span>hastctl role secondary disk1
<span style="color: #666666;">hast2#</span>hastctl role secondary disk2
<span style="color: #666666;">hast2#</span>hastctl role secondary disk3</pre></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1# </span>hastctl status
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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2# </span>hastctl status
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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1# </span>zpool create zhast raidz1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>hast<span style="color: #000000; font-weight: bold;">/</span>disk1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>hast<span style="color: #000000; font-weight: bold;">/</span>disk2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>hast<span style="color: #000000; font-weight: bold;">/</span>disk3
<span style="color: #666666;">hast1# </span>zpool status zhast
 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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1# </span>zpool <span style="color: #7a0874; font-weight: bold;">export</span> zhast
<span style="color: #666666;">hast1# </span>hastctl role secondary disk1
<span style="color: #666666;">hast1# </span>hastctl role secondary disk2
<span style="color: #666666;">hast1# </span>hastctl role secondary disk3</pre></td></tr></table></div>

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

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

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

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2# </span>zpool status zhast
 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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2# </span>hastctl status
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></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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 </span>
<span style="color: #666666; font-style: italic;"># Modified by Michael W. Lucas </span>
<span style="color: #666666; font-style: italic;"># and Viktor Petersson </span>
<span style="color: #666666; font-style: italic;"># Modified by George Kontostanos </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;">&amp;</span>gt; <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;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<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;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <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;
		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;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<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;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<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;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1# </span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> er0 down</pre></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast1# </span><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>debug.log
&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></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">hast2# </span><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>debug.log
&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></td></tr></table></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.</p>
<p><a href="http://www.barebsd.com"><img src="/wp-content/uploads/2011/11/hosting.gif" alt="Powered by BareBSD" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aisecure.net/2012/02/07/hast-freebsd-zfs-with-carp-failover/feed/</wfw:commentRss>
		<slash:comments>27</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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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>55</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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">###clean up rule</span>
block log all</pre></td></tr></table></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"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></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>3</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"><table><tr><td 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></td></tr></table></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>21</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>1</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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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"><table><tr><td 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></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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>60</slash:comments>
		</item>
	</channel>
</rss>
