<?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>ClearChain &#187; zfs</title>
	<atom:link href="http://www.clearchain.com/blog/tags/zfs/feed" rel="self" type="application/rss+xml" />
	<link>http://www.clearchain.com/blog</link>
	<description>-= Daily Happenings =-</description>
	<lastBuildDate>Tue, 17 Aug 2010 06:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Booting FreeBSD from a root zfs pool using a standard MBR and partition table</title>
		<link>http://www.clearchain.com/blog/posts/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table</link>
		<comments>http://www.clearchain.com/blog/posts/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#comments</comments>
		<pubDate>Fri, 08 May 2009 03:51:02 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[booting]]></category>
		<category><![CDATA[BTX]]></category>
		<category><![CDATA[dual boot]]></category>
		<category><![CDATA[mbr]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[zfs]]></category>
		<category><![CDATA[zfsboot]]></category>
		<category><![CDATA[zfsldr.S]]></category>
		<category><![CDATA[zfsonroot]]></category>
		<category><![CDATA[zpool]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=366</guid>
		<description><![CDATA[This page documents the current state of play for booting the root filesystem (/) off a zfs zpool under FreeBSD, using a standard master boot record (MBR) and a standard partition table. The aim was to be able to have a dual boot system for my laptop using the standard FreeBSD quick selection boot loader. [...]]]></description>
			<content:encoded><![CDATA[<p>This page documents the current state of play for booting the root filesystem (/) off a zfs zpool under FreeBSD, using a standard master boot record (MBR) and a standard partition table. The aim was to be able to have a dual boot system for my laptop using the standard FreeBSD quick selection boot loader.</p>
<p><span style="color: #0000ff;">Note, this does not cover using the gpt based partition tables. If you want to use these, please refer to the following page: </span><span style="color: #0000ff;"><a href="http://lulf.geeknest.org/blog/freebsd/Setting_up_a_zfs-only_system/">http://lulf.geeknest.org/blog/freebsd/Setting_up_a_zfs-only_system/</a> or booting zfs as root using a small ufs boot partition as provided by the instructions at: <a href="http://wiki.freebsd.org/ZFSOnRoot">http://wiki.freebsd.org/ZFSOnRoot.<br />
</a></span></p>
<p>Below is the steps required to be able to setup the root zpool</p>
<ol>
<li>Download a FreeBSD -current fixit cdrom snapshot later than 200901, as these have loader ZFS support</li>
<li>Burn the CD</li>
<li>Boot the CD</li>
<li>Setup any partitions you want &#8211; <span style="color: #ff0000;">note you must setup the &#8216;a&#8217; partition to cover the entire device as the loader will use this.</span></li>
<li>Select Fixit from the menu, and use the CDrom as a source</li>
<li>Create the pool and install the loader (see below)</li>
<li>Copy the required files to boot (see below)</li>
</ol>
<h2>Creating the root zpool and installing the Loader</h2>
<p>The fixit cd has everything required to create a zpool, however by default none of the required modules are loaded. Hence they need to be loaded first:</p>
<pre style="padding-left: 30px;"><span style="font-family: Georgia; line-height: 19px; white-space: normal;"><span style="font-family: times new roman,times;"><span style="line-height: 18px; white-space: pre;">cd /mnt2/boot/kernel
<span style="white-space: normal;">kldload ./opensolaris.ko
<span style="white-space: pre;">
kldload ./zfs.ko</span></span></span></span></span></pre>
<p>Once the modules have been loaded all the zfs tools (zpool,zfs,zdb) should now work. Let assume you want to install FreeBSD to /dev/ad4s2 (second partition on a sata disk). You can do this using:</p>
<pre>    zpool create <strong><em>somename</em></strong> /dev/ad4s2</pre>
<p>Where <span style="text-decoration: underline;">somename</span> is the name of the pool you want to create. This creates a single zfs filesystem and a zfs pool of storage. To install the boot loader you need to do:</p>
<pre>    # dd if=/mnt2/boot/zfsboot of=/dev/da0s1 count=1
    # dd if=/mnt2/boot/zfsboot of=/dev/da0s1 skip=1 seek=1024</pre>
<p>The first line installs boot1, the second line installs boot2.  However, boot2 is responsible for loading boot3 (aka the loader &#8211; found in /boot/loader). Hence that must be put in place.</p>
<h2>Copying the required files to boot</h2>
<p>The easiest way to get things to the point where things are ready to boot is to copy all the files from /dist  - the live distribution. Before you do this, you might like to take advantage of zfs and create some subfilesystems so you can snapshot, monitor space, etc.</p>
<p>For instance creating a /usr and /var filesystem is often very handy:</p>
<pre>    #zfs create somename/usr
    #zfs create somename/var</pre>
<p>Now you can copy the base system:</p>
<pre>    cp -a /dist/* /somename</pre>
<p>This will install among other things:</p>
<ul>
<li>/somename/boot/kernel/kernel  - FreeBSD kernel</li>
<li>/somename/boot/kernel/opensolaris.ko &#8211; zfs dependency</li>
<li>/somename/boot/kernel/zfs.ko &#8211; module understanding zpools/zfs</li>
<li>/somename/boot/loader  - the FreeBSD loader<span style="color: #ff0000;"><br />
</span></li>
</ul>
<p>At this point you need to replace the loader with one that understands zfs. You can download the loader from: (To be advise &#8211; see cavet below)<br />
And if you have a usb stick copy it in place using:</p>
<pre>   mount_msdos /dev/da0s1 /mnt
   cp /mnt/loader /somename/boot</pre>
<p>Finally you have to tell FreeBSD where to mount filesystems on a standard boot:</p>
<pre>   zfs set mountpoint=/var somename/var
   zfs set mountpoint=/usr somename/usr</pre>
<p>At this point any command you type will now probably fail indicating it&#8217;s missing some shared library. This is because /usr has now changed. You can get around this by telling the loader where to find valid libraries:</p>
<pre>   export LD_LIBRARY_PATH=/mnt2/lib</pre>
<p>Next we need to build the zfs cache. This is used by zfs mount to automatically mount zfs filesystems by /etc/rc.d/zfs at boot time. It&#8217;s also used to determine if a filesystem is local to the system or belongs to an exported pool.</p>
<pre>   mkdir /boot/zfs
   mkdir /somename/boot/zfs
   cd /
   zfs export somename
   zfs import -f somename
   cp /boot/zfs/zfs.cache /somename/boot/zfs/</pre>
<p>Finally we tell the loader where we want to boot from and set the init scripts to automatically start all zfs filesystems:</p>
<pre>    echo 'zfs_enable="YES"' &gt; /somename/etc/rc.conf
    echo 'zfs_load="YES"' &gt; /somename/boot/loader.conf
    echo 'vfs.root.mountfrom="zfs:somename"' &gt;&gt; /somename/boot/loader.conf</pre>
<p>And set the root filesystem to a legacy mountpoint (so zfs mount -a won&#8217;t try and mount an already mounted filesystem)</p>
<pre>     zfs set mountpoint=legacy somename</pre>
<p>At this point you can reboot and things should now boot!<br />
<span style="text-decoration: underline;"><em><strong>Update: 20090809</strong></em></span></p>
<p>There has been a lot of updates to instructions along the way. There are now official ZFS on Root instructions available using GPT/MBR/other available at: <a href="http://wiki.freebsd.org/RootOnZFS">http://wiki.freebsd.org/RootOnZFS</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
