{"id":44,"date":"2010-01-18T16:08:50","date_gmt":"2010-01-18T16:08:50","guid":{"rendered":"http:\/\/poojanwagh.opalstacked.com\/techblog\/?p=44"},"modified":"2011-03-21T18:34:21","modified_gmt":"2011-03-21T18:34:21","slug":"freebsd-samba-with-zfs","status":"publish","type":"post","link":"https:\/\/tech.poojanblog.com\/blog\/unix-linux\/freebsd-samba-with-zfs\/","title":{"rendered":"Freebsd + Samba with ZFS"},"content":{"rendered":"<p>I&#8217;ve just set up my new file server for Windows shares. Unfortunately, OpenSolaris doesn&#8217;t run on my PortWell machine, and I&#8217;ve decided that trying to run Windows within a VirtualBox VM (hosted by OpenSolaris) is a bit too flaky.<\/p>\n<h4>Here&#8217;s the set up:<!--more-->Partitioning<\/h4>\n<p>First, I had to configure my drives to support a raidz configuration. I have a 1TB hard drive (new) and a 250 GB hard drive (old). This was the tricky part. I want a good raidz configuration <em>eventually<\/em>. However, right now, I don&#8217;t have the money to buy 2 extra hard drives. So, I partitioned the 1 TB hard drive into (roughly) 250 GB slices, and set up a raidz configuration with the slices and the separate 250 GB hard drive. This step was a bit tricky. The FreeBSD <code>fdisk<\/code> command wants to partition on cylinder boundaries. Additionally, <code>fdisk<\/code> also thinks the hard drive is built up of 121601 cyls \/ 255 heads \/ 63 sectors. If I need to partition on a cylinder boundary, I want each partition to hold 121601\/4 cylinders = 30\u00a0400 cylinders. Which comes out to 488<span> <\/span>376<span> <\/span>000 sectors. That&#8217;s all good, except <code>fdisk<\/code> throws a wrench in there by adding an unused partition at the beginning of the first partition&#8211;I&#8217;m guessing for the partition table. So, I had to set that first partition to be a little larger (to account for the extra partition). I added 255*63=16065 sectors to the first partition, requesting 488392065 sectors. In the end, my partitions looked like this:<\/p>\n<p>[ccp]<\/p>\n<p>Disk name:\u00a0\u00a0\u00a0\u00a0\u00a0 da0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FDISK Partition Editor<br \/>\nDISK Geometry:\u00a0 121601 cyls\/255 heads\/63 sectors = 1953520065 sectors (953867MB)<\/p>\n<p>Offset\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Size(ST)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End\u00a0\u00a0\u00a0\u00a0 Name\u00a0 PType\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Desc\u00a0 Subtype\u00a0\u00a0\u00a0 Flags<\/p>\n<p>0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 63\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 62\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0 12\u00a0\u00a0\u00a0\u00a0 unused\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0<br \/>\n63\u00a0 488392002\u00a0 488392064\u00a0\u00a0\u00a0 da0s1\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 ext2fs\u00a0\u00a0\u00a0\u00a0\u00a0 131<br \/>\n488392065\u00a0 488376000\u00a0 976768064\u00a0\u00a0\u00a0 da0s2\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 ext2fs\u00a0\u00a0\u00a0\u00a0\u00a0 131<br \/>\n976768065\u00a0 488376000 1465144064\u00a0\u00a0\u00a0 da0s3\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 ext2fs\u00a0\u00a0\u00a0\u00a0\u00a0 131<br \/>\n1465144065\u00a0 488376000 1953520064\u00a0\u00a0\u00a0 da0s4\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 ext2fs\u00a0\u00a0\u00a0\u00a0\u00a0 131<br \/>\n1953520065\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5103 1953525167\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0 12\u00a0\u00a0\u00a0\u00a0 unused\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0<\/p>\n<p>[\/cc]<\/p>\n<h4>ZFS RaidZ<\/h4>\n<p>Originally, I did this:<\/p>\n<code>zpool create tank raidz2 da0s1 da0s2 da0s3 da0s4 da1s1<\/code>\n<p>However, I realized a couple things: I&#8217;m creating a raidz-2 configuration. So, I&#8217;d need at least 3 hard drives for this to be of any use. Even with 3 separate 1 TB\u00a0 hard drives, I&#8217;d only have 1 TB of usable space (the other two hard drives are redundant parity storage). That&#8217;s a bit expensive. So, I decided to throttle down to raidz-1. If a hard drive fails, I should have enough time to replace it before a second hard drive fails. So, I did the following:<\/p>\n<code>zpool create tank raidz da0s1 da0s2 da1s1<\/code>\n<p>Yup: I&#8217;m not using da0s3 nor da0s4. So, there&#8217;s roughly 500 GB of space going unused. This isn&#8217;t that big of a deal, because when I need the space, it&#8217;s probably time to buy an extra hard drive. Also, at the rate my family consumes data, it could be a year before we miss the space. (In retrospect, I probably should have bought two 500 GB hard drives rather than the 1 TB hard drive in the first place.)<\/p>\n<h4>User Storage Areas<\/h4>\n<p>I created a place to house the Windows user directories:<\/p>\n<p>zfs create \/tank\/Users<\/p>\n<p>I then used the following script to create user ZFS filesystems under the \/tank directory, for each user, and with compression on for the <code>Documents<\/code> directory:<\/p>\n<code><\/p>\n<p>#!\/bin\/sh<\/p>\n<p>u=&#8221;$1&#8243;<br \/>\nzfs create tank\/Users\/$u<br \/>\nchown $u:$u \/tank\/Users\/$u<br \/>\nfor d in &#8220;Documents&#8221; &#8220;Music&#8221; &#8220;Videos&#8221; &#8220;Pictures&#8221;; do<br \/>\nzfs create tank\/Users\/$u\/$d<br \/>\nchown $u:$u \/tank\/Users\/$u\/$d<br \/>\ndone<br \/>\nzfs set compression=gzip tank\/Users\/$u\/Documents<br \/>\n<\/code>\n<h4>Samba<\/h4>\n<p>I set up the samba shares to use this <code>\/tank\/Users<\/code> directory rather then the default home directories. I edited the following in <code>\/usr\/local\/etc\/smb.conf<\/code>:<\/p>\n<code><\/p>\n<p>[homes]<br \/>\ncomment = Home Directories<br \/>\nbrowseable = no<br \/>\nwritable = yes<br \/>\npath = \/tank\/Users\/%u\/<\/p>\n<p><\/code>\n<p>After that, a few <code>adduser<\/code> and <code>smbpasswd -a<\/code> commands and things were all set. I&#8217;m now using <a title=\"All Way Sync file synchronizer: synchronizes periodically and upon local changes\" href=\"http:\/\/www.allwaysync.com\/\">Allway Sync<\/a> to synchronize my windows machines to the file server.<\/p>\n<h4>Kernel Tuning<\/h4>\n<p>ZFS requires a lot more memory from the kernel than the default FreeBSD provides. The <a title=\"FreeBSD Wiki: ZFS tuning guide lists necessary tweaks to get ZFS stable\" href=\"http:\/\/wiki.freebsd.org\/ZFSTuningGuide\">tuning guide<\/a> says that I need to rebuild the kernel with <code>KVA_PAGES=512<\/code>. Perhaps. However, for right now, I&#8217;m going to try and get by with the following additions to loader.conf from http:\/\/www.daemonforums.org\/showthread.php?t=4200:<\/p>\n<code>newsystem# cat &gt;&gt; \/boot\/loader.conf &lt;&lt; __EOF__<br \/>\nvfs.zfs.prefetch_disable=0      # enable prefetch<br \/>\nvfs.zfs.arc_max=134217728       # 128 MB<br \/>\nvm.kmem_size=536870912          # 512 MB<br \/>\nvm.kmem_size_max=536870912      # 512 MB<br \/>\nvfs.zfs.vdev.cache.size=8388608 #   8 MB<br \/>\n__EOF__<\/code>\n<div class='wp_likes' id='wp_likes_post-44'><a class='like' href=\"javascript:wp_likes.like(44);\" title='' ><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/tech.poojanblog.com\/blog\/wp-content\/plugins\/wp-likes\/images\/like.png\" alt='' border='0'\/><\/a><span class='text'>Be the first to like.<\/span><\/p>\n<div class='like' ><a href=\"javascript:wp_likes.like(44);\">Like<\/a><\/div>\n<div class='unlike' ><a href=\"javascript:wp_likes.unlike(44);\">Unlike<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I then used the following script to create user ZFS filesystems under the \/tank directory, for each user, and with compression on for the [cci]Documents[\/cci] directory:<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[12,13,3],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-unix-linux","tag-freebsd","tag-samba","tag-zfs"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":14,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/485"}],"wp:attachment":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}