{"id":366,"date":"2009-05-08T13:21:02","date_gmt":"2009-05-08T03:51:02","guid":{"rendered":"http:\/\/www.clearchain.com\/blog\/?p=366"},"modified":"2011-05-04T16:44:26","modified_gmt":"2011-05-04T07:14:26","slug":"booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table","status":"publish","type":"post","link":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table","title":{"rendered":"Booting FreeBSD from a root zfs pool using a standard MBR and partition table"},"content":{"rendered":"<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>\n<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:\/\/blogs.freebsdish.org\/lulf\/2008\/12\/16\/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:\u00a0<a href=\"http:\/\/wiki.freebsd.org\/ZFSOnRoot\">http:\/\/wiki.freebsd.org\/ZFSOnRoot.<br \/>\n<\/a><\/span><\/p>\n<p>Below is the steps required to be able to setup the root zpool<\/p>\n<ol>\n<li>Download a FreeBSD -current fixit cdrom snapshot later than 200901, as these have loader ZFS support<\/li>\n<li>Burn the CD<\/li>\n<li>Boot the CD<\/li>\n<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>\n<li>Select Fixit from the menu, and use the CDrom as a source<\/li>\n<li>Create the pool and install the loader (see below)<\/li>\n<li>Copy the required files to boot (see below)<\/li>\n<\/ol>\n<h2>Creating the root zpool and installing the Loader<\/h2>\n<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>\n<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\r\n<span style=\"white-space: normal;\">kldload .\/opensolaris.ko\r\n<span style=\"white-space: pre;\">\r\nkldload .\/zfs.ko<\/span><\/span><\/span><\/span><\/span><\/pre>\n<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>\n<pre>    zpool create <strong><em>somename<\/em><\/strong> \/dev\/ad4s2<\/pre>\n<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>\n<pre>    # dd if=\/mnt2\/boot\/zfsboot of=\/dev\/da0s1 count=1\r\n    # dd if=\/mnt2\/boot\/zfsboot of=\/dev\/da0s1 skip=1 seek=1024<\/pre>\n<p>The first line installs boot1, the second line installs boot2. \u00a0However, boot2 is responsible for loading boot3 (aka the loader &#8211; found in \/boot\/loader). Hence that must be put in place.<\/p>\n<h2>Copying the required files to boot<\/h2>\n<p>The easiest way to get things to the point where things are ready to boot is to copy all the files from \/dist \u00a0&#8211; 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>\n<p>For instance creating a \/usr and \/var filesystem is often very handy:<\/p>\n<pre>\u00a0\u00a0 \u00a0#zfs create somename\/usr\r\n    #zfs create somename\/var<\/pre>\n<p>Now you can copy the base system:<\/p>\n<pre> \u00a0 \u00a0cp -a \/dist\/* \/somename<\/pre>\n<p>This will install among other things:<\/p>\n<ul>\n<li>\/somename\/boot\/kernel\/kernel \u00a0&#8211; FreeBSD kernel<\/li>\n<li>\/somename\/boot\/kernel\/opensolaris.ko &#8211; zfs dependency<\/li>\n<li>\/somename\/boot\/kernel\/zfs.ko &#8211; module understanding zpools\/zfs<\/li>\n<li>\/somename\/boot\/loader \u00a0&#8211; the FreeBSD loader<span style=\"color: #ff0000;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<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 \/>\nAnd if you have a usb stick copy it in place using:<\/p>\n<pre>   mount_msdos \/dev\/da0s1 \/mnt\r\n   cp \/mnt\/loader \/somename\/boot<\/pre>\n<p>Finally you have to tell FreeBSD where to mount filesystems on a standard boot:<\/p>\n<pre>   zfs set mountpoint=\/var somename\/var\r\n   zfs set mountpoint=\/usr somename\/usr<\/pre>\n<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>\n<pre>   export LD_LIBRARY_PATH=\/mnt2\/lib<\/pre>\n<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>\n<pre>   mkdir \/boot\/zfs\r\n   mkdir \/somename\/boot\/zfs\r\n   cd \/\r\n   zfs export somename\r\n   zfs import -f somename\r\n   cp \/boot\/zfs\/zfs.cache \/somename\/boot\/zfs\/<\/pre>\n<p>Finally we tell the loader where we want to boot from and set the init scripts to automatically start all zfs filesystems:<\/p>\n<pre>\u00a0\u00a0 \u00a0echo 'zfs_enable=\"YES\"' &gt; \/somename\/etc\/rc.conf\r\n    echo 'zfs_load=\"YES\"' &gt; \/somename\/boot\/loader.conf\r\n    echo 'vfs.root.mountfrom=\"zfs:somename\"' &gt;&gt; \/somename\/boot\/loader.conf<\/pre>\n<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>\n<pre>\u00a0\u00a0   zfs set mountpoint=legacy somename<\/pre>\n<p>At this point you can reboot and things should now boot!<br \/>\n<span style=\"text-decoration: underline;\"><em><strong>Update: 20090809<\/strong><\/em><\/span><\/p>\n<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>\n","protected":false},"excerpt":{"rendered":"<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.<a href=\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\"> <font size=-2>[..more..]<\/font><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[200,198,17,19,199,193,196,197,195,194],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-freebsd","tag-booting","tag-btx","tag-dual-boot","tag-mbr","tag-partition","tag-zfs","tag-zfsboot","tag-zfsldrs","tag-zfsonroot","tag-zpool"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Booting FreeBSD from a root zfs pool using a standard MBR and partition table - ClearChain<\/title>\n<meta name=\"description\" content=\"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)\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Close\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\"},\"author\":{\"name\":\"Benjamin Close\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"headline\":\"Booting FreeBSD from a root zfs pool using a standard MBR and partition table\",\"datePublished\":\"2009-05-08T03:51:02+00:00\",\"dateModified\":\"2011-05-04T07:14:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\"},\"wordCount\":689,\"commentCount\":5,\"keywords\":[\"booting\",\"BTX\",\"dual boot\",\"mbr\",\"partition\",\"zfs\",\"zfsboot\",\"zfsldr.S\",\"zfsonroot\",\"zpool\"],\"articleSection\":[\"FreeBSD\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\",\"url\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\",\"name\":\"Booting FreeBSD from a root zfs pool using a standard MBR and partition table - ClearChain\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\"},\"datePublished\":\"2009-05-08T03:51:02+00:00\",\"dateModified\":\"2011-05-04T07:14:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"description\":\"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)\",\"breadcrumb\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.clearchain.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Booting FreeBSD from a root zfs pool using a standard MBR and partition table\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\",\"url\":\"https:\/\/www.clearchain.com\/blog\/\",\"name\":\"ClearChain\",\"description\":\"-= Daily Happenings =-\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\",\"name\":\"Benjamin Close\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"caption\":\"Benjamin Close\"},\"sameAs\":[\"http:\/\/www.clearchain.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Booting FreeBSD from a root zfs pool using a standard MBR and partition table - ClearChain","description":"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)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table","twitter_misc":{"Written by":"Benjamin Close","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#article","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table"},"author":{"name":"Benjamin Close","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"headline":"Booting FreeBSD from a root zfs pool using a standard MBR and partition table","datePublished":"2009-05-08T03:51:02+00:00","dateModified":"2011-05-04T07:14:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table"},"wordCount":689,"commentCount":5,"keywords":["booting","BTX","dual boot","mbr","partition","zfs","zfsboot","zfsldr.S","zfsonroot","zpool"],"articleSection":["FreeBSD"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table","url":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table","name":"Booting FreeBSD from a root zfs pool using a standard MBR and partition table - ClearChain","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/#website"},"datePublished":"2009-05-08T03:51:02+00:00","dateModified":"2011-05-04T07:14:26+00:00","author":{"@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"description":"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)","breadcrumb":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.clearchain.com\/blog\/posts\/booting-freebsd-from-a-root-zfs-pool-using-a-standard-mbr-and-partition-table#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.clearchain.com\/blog"},{"@type":"ListItem","position":2,"name":"Booting FreeBSD from a root zfs pool using a standard MBR and partition table"}]},{"@type":"WebSite","@id":"https:\/\/www.clearchain.com\/blog\/#website","url":"https:\/\/www.clearchain.com\/blog\/","name":"ClearChain","description":"-= Daily Happenings =-","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98","name":"Benjamin Close","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","caption":"Benjamin Close"},"sameAs":["http:\/\/www.clearchain.com"]}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":6,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}