FreeNAS to Ubuntu: Initial Fileserver Setup with ZFS
Background: I have always loved FreeNAS. It was one of the first servers I ever set up, back in the day in my parent's basement. It was running on a Pentium 3, 933MHz, 256MB of RAM, and about 500GB of storage space. Eventually, it got upgraded to a real piece of server hardware, more drives, etc. When they announced the buyout by iX Systems and the upgrade to version 8 with a complete rewrite, I was skeptical. I've tried their new software, and I wasn't overly impressed. I've been having various issues on v7 as well, mostly related to ZFS and random crashes. v8 is much more enterprise oriented, and dropped the fun bits for home servers, such as torrent server and UPnP, for media streaming. I bought 4 new 2TB drives and an external enclosure, and tried to reinstall FreeNAS to start fresh. No such luck, and after a few hours of crashes on start, I gave up and decided, it's time to go with Ubuntu, like the rest of my house, with ZFS of course.
Goals: To replace FreeNAS, there are a few pieces of software that absolutely have to work. Mainly, they'd be Samba for Windows sharing, NFS for ESXi and Linux sharing, ZFS for the storage pool (file system and redundancy), a web server to stream/download files in the pools, and preferably some type of web administration software. Nice things would be UPnP that actually works with my Xbox (FreeNAS never did), and on the fly encoding (maybe DivX?) to stream my HD movies over the Internet when I'm not at home. We'll get a basic version up in this tutorial, and then the more advanced stuff in the next one.
Installation: Install Ubuntu server like normal. Since this is my main file server, I'm going with Ubuntu 10.04. I don't feel like upgrading this every 18 months when support runs out. Since 10.04 is a LTS (Long Term Service) release, it will be supported until April 2015. You'll also want the 64 bit edition, because ZFS on Linux is better supported by 64 bit. Install like normal. I'm using one drive as the OS disk, and the rest will go into zpools. The only thing to make sure you do is to install OpenSSH server when it asks which server software to install.
Configuration: First off, let's update the server.
sudo apt-get -y -q update && sudo apt-get -y -q upgrade
Next, let's get ZFS installed, since most everything else relies on it. There is a project called ZFS on Linux, which provides a port of the ZFS kernel module for Linux. It can't be included directly in the Linux kernel because of incompatible licenses, but we can put it in ourselves. Versions below 0.60 won't let you mount the ZFS pools (serious problem right?). So we will install the 0.60rc6 straight from the git repo where it is being actively developed. Hold onto your seat! We're going to be compiling directly from source. As rj in the comments pointed out, there is now a PPA with ZFS on Ubuntu, so we'll use that method. You can still get the newest code straight from the repo and compile if you are having problems.
sudo apt-get -y install build-essential gawk zlib1g-dev uuid-dev vim-nox python-software-properties sudo add-apt-repository ppa:zfs-native/stable sudo apt-get update sudo apt-get install ubuntu-zfs # Add zfs modules to be loaded at boot sudo nano /etc/modules --- # Add on: spl zavl znvpair zunicode zcommon zfs --- # Incorporate new modules into the boot files sudo update-initramfs -u # Make init script to mount all the ZPools on boot (isn't fully working on one of my machines) wget -O zfs-init.tar http://osdir.com/ml/attachments/tarUdnnwPCuOh.tar tar xvf zfs-init.tar sudo cp zfs-init/etc/default/zfs /etc/default/zfs sudo cp zfs-init/etc/init/* /etc/init/
Now that we have ZFS installed, we either need to mount existing pools, or create new pools. ZFS allows you to create pools with redundancy such as mirroring, or RAIDZ(x), which allows x amount of drives to die without losing data. For example RAIDZ can lose on drive, RAIDZ2 can lose 2, and RAIDZ3 can lose 3.
Note: all ZFS and ZPool commands must be run as root/sudo
# Let's create a RAIDZ (like RAID 5) pool named storage from 3 disks sudo zpool create storage raidz /dev/sdb /dev/sdc /dev/sdd # Import an existing pool named storage (perhaps created on a previous FreeNAS box) sudo zpool import storage # And then we can create filesystems on the pool, much like folders. We already have a root folder at /mnt/storage/ sudo zfs create storage/Movies sudo zfs create storage/Music sudo zfs create storage/Upload # Now your ZFS should look like this: # /mnt/storage # /Movies # /Music # /Upload
Now that we have the server's pools in order, we need to provide a way to upload/download data. We will start by using SMB, which allows Windows, Linux, and Macs connect. It also allows us to provide public read-only shares, public writable shares, and password protected shares.
# Prepare sharing sudo apt-get -y install samba nfs-kernel-server sudo nano /etc/samba/smb.conf --- # Change # security = user # to security = user # No password, read only share [sharename] comment = This is a share path = /mnt/storage/share browsable = yes guest ok = yes read only = yes create mask = 0755 # No password, writable share [writableshare] comment = This is a writable share path = /mnt/storage/writable guest ok = yes writeable = True create mask = 0744 # Password protected share [passwordsharename] comment = This share requires a password path = /mnt/storage/secret browsable = yes guest ok = no read only = yes create mask = 0755 user = username otheruser # To allow users to connect to password protected shares, run smbpasswd to generate the login password sudo smbpasswd -a username sudo smbpasswd -a otheruser
In my case, this worked without restarting Samba, however it might be a good idea anyway.
sudo reload smbd
You should now be able to connect to the server by going to "smb://serverip" in Nautilus or "\\serverip" in Windows Explorer. Add as many shares as you need.
This gives you a very basic file server. If you want to get a torrent server similar to the FreeNAS one, you can check out the Ubuntu Torrent Server article.
In my next articles, I will explore using NFS to share data to Linux clients, a torrent server, UPnP for streaming to XBox 360/PS3, and a web server to share files over the Internet (hopefully with on the fly encoding), and maybe those sweet beeps that FreeNAS makes on startup/shutdown.
If anything in the tutorial doesn't work for you, make sure to leave a comment and I'll try to fix it! "It worked!" comments are also appreciated!
November 3rd, 2011 - 18:54
Sounds interesting. I am currently using freenas 8 on a HP box and am using an 8G USB drive for the OS.
Would it be possible to reuse my existing freenas zfs array? That would be pretty neat.
November 4th, 2011 - 12:40
Yup you should be able to! That’s what I’m doing, although I went from FreeNAS 7 to Ubuntu. The only thing I could think of is if ZFS is a newer version on FreeNAS than ZFS on Linux. Just follow the import instructions (zfs import poolname) for ZFS rather than the create instructions. You should probably run “zfs export poolname” before shutting down FreeNas though.
November 9th, 2011 - 12:03
Hi, very nice post. It inspired me to install Ubuntu 10.04.3 x64 in an old laptop, and make a raidz with 3x500GB usb external drives (2.5). Cool thing!
I am having a problem regarding the reported size, as I understand it, I should be having something in the 1TB. However zfs list reports 291GB ‘!??
Do you have a clue why this is happening? I created the pool with the following command:
sudo zpool create -f -o ashift=12 datasafe raidz /dev/sdd /dev/sde /dev/sdf
The ashift=12 aligns the blocks to 4K (I am unsure if this was required, but in my oder laptop the speeds I was getting were in the order of 40kilobytes/s, and I though it could be something with being 4K HDD)
root@dell-server:~# zfs list
NAME USED AVAIL REFER MOUNTPOINT
datasafe 291G 0 291G /datasafe
root@dell-server:~# zpool list datasafe
NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT
datasafe 444G 437G 6.94G 98% 1.00x ONLINE -
I just don’t pain get it. Where is the 1TB that I should be having??
THnks
November 14th, 2011 - 21:26
As for the 4K blocks, I’ve only seen that on the newest drives, but it is possible. What does “sudo fdisk -l /dev/sdd” show? It should show a line like “Units = sectors of 1 * 512 = 512 bytes”. The speed could have to do with 3 drives all coming off USB, but it shouldn’t be that bad of performance.
My guess for the small size is something is set up wrong with your disks. Check this link: http://mail.opensolaris.org/pipermail/zfs-discuss/2011-June/049025.html. Again, the fdisk output will help determine the cause.
November 17th, 2011 - 03:19
Hi there,
Followed everything to the letter so far, but i get a 404 file not found getting the zfs-init.
wget -O zfs-init.tar http://osdir.com/ml/attachments/tarUdnnwPCuOh.tar
this line results in a 404, you have an updated link?
November 17th, 2011 - 03:22
here is the console feedback:
xbmc@xbmc:~/behlendorf-zfs-3b1727d$ wget -O zfs-init.tar http://osdir.com/ml/attachments/tarUdnnwPCuOh.tar
–2011-11-17 16:20:51– http://osdir.com/ml/attachments/tarUdnnwPCuOh.tar
Resolving osdir.com… 75.101.227.132
Connecting to osdir.com|75.101.227.132|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2011-11-17 16:20:52 ERROR 404: Not Found.
February 16th, 2012 - 00:29
Josh, looking to do the same thing and go from freenas to my own setup in ubuntu. In my researching phase, came across your site. So a question after reading this article, is why did you choose to build from source when http://zfsonlinux.org/faq.html#HowDoIInstallIt described here you can get everything you need from the repository, seems easier? Just curious if there was a reason behind this so I can make a decision going forward.
February 16th, 2012 - 11:07
I wrote this article shortly after rc6 came out. I’m not sure if there wasn’t a repository at that point or if I missed it, but I saw no other way when I wrote this. Thanks for the tip though! I’ve updated the article accordingly. Currently, I am building from source on my current box to test new patches as they come out, but I wouldn’t recommend that for most people.