{"id":142,"date":"2013-02-01T23:38:52","date_gmt":"2013-02-01T22:38:52","guid":{"rendered":"\/wordpress\/?p=142"},"modified":"2013-03-12T09:53:12","modified_gmt":"2013-03-12T08:53:12","slug":"installing-freebsd-9-1-using-root-on-zfs-and-gpt-disks","status":"publish","type":"post","link":"\/wordpress\/zfs-2\/installing-freebsd-9-1-using-root-on-zfs-and-gpt-disks\/","title":{"rendered":"Installing FreeBSD 9.1 using root on ZFS and GPT disks"},"content":{"rendered":"<p><em>This is partly based on the excellent guide at <a href=\"http:\/\/daemon-notes.com\/articles\/system\/install-zfs\/begin\">http:\/\/daemon-notes.com\/articles\/system\/install-zfs\/begin<\/a>.<\/em><\/p>\n<p>Boot with FreeBSD 9.1 installer and select <em>Live CD<\/em> when the installer starts.<br \/>\n<a href=\"\/wordpress\/wp-content\/uploads\/2013\/02\/welcome.jpg\"><img loading=\"lazy\" src=\"\/wordpress\/wp-content\/uploads\/2013\/02\/welcome-300x166.jpg\" alt=\"welcome\" width=\"300\" height=\"166\" class=\"alignright size-medium wp-image-156\" srcset=\"\/wordpress\/wp-content\/uploads\/2013\/02\/welcome-300x166.jpg 300w, \/wordpress\/wp-content\/uploads\/2013\/02\/welcome.jpg 721w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Identify the disks you want to install to. SATA disks are named \/dev\/adaX and USB pendrives and SCSI drives are named \/dev\/daX.<\/p>\n<pre><code>dmesg|egrep (ada|da)<\/code><\/pre>\n<p>Of which output could look like this:<\/p>\n<pre><code>da0 at mpt0 bus 0 scbus2 target 0 lun 0\r\nda0: &lt;VMware Virtual disk 1.0&gt; Fixed Direct Access SCSI-2 device \r\nda0: 320.000MB\/s transfers (160.000MHz, offset 127, 16bit)\r\nda0: Command Queueing enabled\r\nda0: 8192MB (16777216 512 byte sectors: 255H 63S\/T 1044C)\r\nda1 at mpt0 bus 0 scbus2 target 1 lun 0\r\nda1: &lt;VMware Virtual disk 1.0&gt; Fixed Direct Access SCSI-2 device \r\nda1: 320.000MB\/s transfers (160.000MHz, offset 127, 16bit)\r\nda1: Command Queueing enabled\r\nda1: 8192MB (16777216 512 byte sectors: 255H 63S\/T 1044C)\r\n<\/code><\/pre>\n<h3>Partitioning the drives using GPT<\/h3>\n<p>Create the partitions on the disk, making sure to properly align them using 4k blocks. The first partition containing the bootblock won&#8217;t need that.<\/p>\n<pre><code>gpart create -s gpt ada0\r\ngpart add -b 34 -s 64k -t freebsd-boot ada0\r\ngpart add -s 2G -a 4k -t freebsd-swap -l swap0 ada0\r\ngpart add -a 4k -t freebsd-zfs -l disk0 ada0\r\n<\/code><\/pre>\n<p>Then do the same for the second disk.<\/p>\n<pre><code>gpart create -s gpt ada1\r\ngpart add -b 34 -s 64k -t freebsd-boot ada1\r\ngpart add -s 2G -a 4k -t freebsd-swap -l swap1 ada1\r\ngpart add -a 4k -t freebsd-zfs -l disk1 ada1\r\n<\/code><\/pre>\n<p>Verify the disks are partitioned correctly.<\/p>\n<pre><code>gpart show<\/code><\/pre>\n<p>They should now look like this:<\/p>\n<pre><code>=&gt;      34  16777149  da0  GPT  (8.0G)\r\n        34       128    1  freebsd-boot  (64k)\r\n       162         6       - free -  (3.0k)\r\n       168   4194304    2  freebsd-swap  (2.0G)\r\n   4194472  12582704    3  freebsd-zfs  (6G)\r\n  16777176         7       - free -  (3.5k)\r\n\r\n=&gt;      34  16777149  da1  GPT  (8.0G)\r\n        34       128    1  freebsd-boot  (64k)\r\n       162         6       - free -  (3.0k)\r\n       168   4194304    2  freebsd-swap  (2.0G)\r\n   4194472  12582704    3  freebsd-zfs  (6G)\r\n  16777176         7       - free -  (3.5k)\r\n<\/code><\/pre>\n<p>Add bootcode to the disks.<\/p>\n<pre><code>gpart bootcode -b \/boot\/pmbr -p \/boot\/gptzfsboot -i 1 ada0\r\ngpart bootcode -b \/boot\/pmbr -p \/boot\/gptzfsboot -i 1 ada1\r\n<\/code><\/pre>\n<h3>Creating the ZFS filesystems<\/h3>\n<p>Set up the disks as two-way mirror, essentially raid-1.<\/p>\n<pre><code>zpool create -o altroot=\/mnt -o cachefile=\/var\/tmp\/zpool.cache zroot mirror \/dev\/gpt\/disk0 \/dev\/gpt\/disk1<\/code><\/pre>\n<p>The zpool then looks like this:<\/p>\n<pre><code>  pool: zroot\r\n state: ONLINE\r\n  scan: none requested\r\nconfig:\r\n\r\n\tNAME           STATE     READ WRITE CKSUM\r\n\tzroot          ONLINE       0     0     0\r\n\t  mirror-0     ONLINE       0     0     0\r\n\t    gpt\/disk0  ONLINE       0     0     0\r\n\t    gpt\/disk1  ONLINE       0     0     0\r\n\r\nerrors: No known data errors\r\n<\/code><\/pre>\n<p>ZFS filesystems<\/p>\n<pre><code>zfs create -o compression=on -o setuid=off zroot\/tmp\r\nchmod 1777 \/mnt\/tmp\r\nzfs create zroot\/usr\r\nzfs create zroot\/usr\/home\r\ncd \/mnt\r\nln -s usr\/home home\r\ncd -\r\nzfs create zroot\/usr\/local\r\nzfs create -o compression=on -o exec=off -o setuid=off zroot\/usr\/src\r\nzfs create zroot\/var\r\nzfs create -o exec=off -o setuid=off zroot\/var\/backups\r\nzfs create -o compression=on -o exec=off -o setuid=off zroot\/var\/crash\r\nzfs create -o exec=off -o setuid=off zroot\/var\/db\r\nzfs create -o compression=on -o exec=on -o setuid=off zroot\/var\/db\/pkg\r\nzfs create -o exec=off -o setuid=off zroot\/var\/empty\r\nzfs create -o compression=on -o exec=off -o setuid=off zroot\/var\/log\r\nzfs create -o compression=on -o exec=off -o setuid=off zroot\/var\/mail\r\nzfs create -o exec=off -o setuid=off zroot\/var\/run\r\nzfs create -o compression=on -o setuid=off zroot\/var\/tmp\r\nchmod 1777 \/mnt\/var\/tmp\r\n<\/code><\/pre>\n<p>In my environment \/usr\/ports is mounted via NFS from a package building server. For a local \/usr\/ports the following need also to exist.<\/p>\n<pre><code>zfs create -o compression=on -o setuid=off zroot\/usr\/ports\r\nzfs create -o exec=off -o setuid=off zroot\/usr\/ports\/distfiles\r\nzfs create -o exec=off -o setuid=off zroot\/usr\/ports\/packages\r\n<\/code><\/pre>\n<p>Then set it bootable and copy the important zpool.cache onto the filesystem, that it will find the zpool upon boot.<\/p>\n<pre><code>zpool set bootfs=zroot zroot\r\nmkdir -p \/mnt\/boot\/zfs\r\ncp -p \/var\/tmp\/zpool.cache \/mnt\/boot\/zfs\/zpool.cache\r\n<\/code><\/pre>\n<h3>Install FreeBSD<\/h3>\n<p>Extract the distfiles.<\/p>\n<pre><code>cd \/mnt\r\nfor dist in base.txz kernel.txz lib32.txz; do\r\n  tar -xzf \/usr\/freebsd-dist\/$dist\r\ndone<\/code><\/pre>\n<p>Create a couple of necessary configuration files<\/p>\n<pre><code>cat << EOF > \/mnt\/boot\/loader.conf\r\nzfs_load=\"YES\"\r\nvfs.root.mountfrom=\"zfs:zroot\"\r\nEOF\r\necho 'zfs_enable=\"YES\"' >> \/mnt\/etc\/rc.conf\r\n<\/code><\/pre>\n<p>Only the swap devices need to exist in the <code>\/etc\/fstab<\/code>. All other filesystems are mounted by zfs.<\/p>\n<pre><code>cat << EOF > \/mnt\/etc\/fstab\r\n# Device         Mountpoint  FStype  Options  Dump    Pass\r\n\/dev\/gpt\/swap0   none        swap    sw       0       0\r\n\/dev\/gpt\/swap1   none        swap    sw       0       0\r\nEOF\r\n<\/code><\/pre>\n<pre><code>zfs set readonly=on zroot\/var\/empty\r\nshutdown -r now<\/code><\/pre>\n<p>You now have a mirrored ZFS-only FreeBSD system with GPT disks!<br \/>\n<a href=\"\/wordpress\/wp-content\/uploads\/2013\/02\/boot.jpg\"><img loading=\"lazy\" src=\"\/wordpress\/wp-content\/uploads\/2013\/02\/boot.jpg\" alt=\"boot\" width=\"722\" height=\"399\" class=\"alignright size-full wp-image-158\" srcset=\"\/wordpress\/wp-content\/uploads\/2013\/02\/boot.jpg 722w, \/wordpress\/wp-content\/uploads\/2013\/02\/boot-300x165.jpg 300w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is partly based on the excellent guide at http:\/\/daemon-notes.com\/articles\/system\/install-zfs\/begin. Boot with FreeBSD 9.1 installer and select Live CD when the installer starts. Identify the disks you want to install to. SATA disks are named \/dev\/adaX and USB pendrives and SCSI drives are named \/dev\/daX. dmesg|egrep (ada|da) Of which output could look like this: da0 <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"\/wordpress\/zfs-2\/installing-freebsd-9-1-using-root-on-zfs-and-gpt-disks\/\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,6],"tags":[31,19,38,2,9,39],"_links":{"self":[{"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/posts\/142"}],"collection":[{"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":20,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":201,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/posts\/142\/revisions\/201"}],"wp:attachment":[{"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.strahlert.net\/wordpress\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}