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
# If you aren't using the PPA (installing from source), you'll need your own init script, so ZFS pools are mounted at startup. The script (from the PPA) looks like this:
sudo nano /etc/init.d/zfs
-----
#!/bin/sh
#
# chkconfig: 2345 01 99
#
### BEGIN INIT INFO
# Provides: zvol zfs
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop ZFS subsystem.
# Description: ZFS is an advanced filesystem designed to simplify managing
# and protecting your data. This service mounts the ZFS
# filesystems and starts all related zfs services.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
. /lib/init/vars.sh
[ -f /etc/default/zfs ] && . /etc/default/zfs
do_start() {
log_begin_msg "Starting ZFS subsystem"
log_progress_msg "filesystems"
zfs mount -a
RET=$?
if [ $RET != 0 ] ; then
log_end_msg $RET
exit $RET
fi
log_end_msg 0
log_begin_msg "Exporting ZFS filesystems"
zfs share -a
log_end_msg $?
}
do_stop() {
log_begin_msg "Stopping ZFS subsystem"
log_progress_msg "filesystems"
zfs umount -a
RET=$?
if [ $RET != 0 ] ; then
log_end_msg $RET
fi
log_end_msg 0
}
do_status() {
zpool status
echo ''
zpool list
true
}
case "$1" in
start)
[ -z "$ZFS_MOUNT" ] && exit 0
do_start
;;
stop)
[ -z "$ZFS_UNMOUNT" ] && exit 0
do_stop
;;
status)
do_status
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop|status}"
exit 3
;;
esac
-----
chmod 755 /etc/init.d/zfs
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!
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.
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.
Pingback: Replace FreeNAS with Ubuntu « 0ddn1x: tricks with *nix
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
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.
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?
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.
Pingback: Run ZFS on your file server (Ubuntu) « 0ddn1x: tricks with *nix
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.
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.
Pingback: Links 19/2/2012: Raspberry Pi Coming on Sale, HUD Interface Coming to Next Ubuntu | Techrights
Hey Josh, thanks for the update!
Also do you happen to know where you found the zfs-init.tar as the original link doesnt work anymore
http://osdir.com/ml/attachments/tarUdnnwPCuOh.tar 404s
I don’t need the exact link, just a trail to find it!
Hmm…I found it on some board. It is now included in the PPA package. I’ll update the article to reflect that, along with the script, in case you aren’t using the PPA.
Also looking for zfs-init.tar – unless it’s no longer needed? Any updates?
Disregard.
Me again,
Couple things i noticed, it did import my pool, but retained NONE of the data, not so bad since I had everything backed up, but still weird.
Secondly I see it doesnt mount on boot, even though zfs-mount is set to go on boot, I have to type zfs mount -a to get it to come up. Does this happen with you also?
That’s really, really messed up that it didn’t retain your data. If it is a reproducible error, please report it! https://groups.google.com/a/zfsonlinux.org/group/zfs-discuss/topics?lnk&pli=1
RC7 is out now, so try running updates and see if that fixes your problem.
I’ve found the init script to be a bit flaky. Sometimes it works, sometimes not. Since I started using the PPA I haven’t had any problems though.
Just an update, couple months later, and running VERY WELL!
Have moved data to it, and all has been well! Still a bit scared since it’s all so beta, but wow. So easy! I still worry about doing any maintenance, but I guess i just need a scrub every few months? What are you doing for maintenance if anything?
Btw this is still like the only good blog post for zfs on ubuntu on the net I believe! I’m running stable on 12.04! woot!
Great! I’m glad it is still working for you! I try and write useful articles, especially when I cannot find the howto anywhere else on the web.
I have a cronjob running a scrub once a week. I believe you should do it at least once a month on consumer grade drives.
Pingback: Ubuntu Zfs – GeekLogy
Nice article! Just wanted to note that if you use the PPA, you shouldn’t edit /etc/modules. See here: https://github.com/dajhorn/pkg-zfs/wiki/Ubuntu-ZFS-mountall-FAQ-and-troubleshooting
just wanted to give everyone a heads up…
line 1 where it says:
sudo apt-get install zliblg-dev
because of the font type, it is hard to tell, but it should be
sudo apt-get install zlib1g-dev – as in the NUMBER ONE
the best thing about noticing this error…issues help you learn now things. for example, trying to figure this out helped me learn the command [aptitude search]. running [aptitude search zlib] returned a list of ALL packages containing the context of zlib.
awesome guide!!!
I did everything and had the pool from freenas loaded and all the files where ther. Had them shared over SMB. after restart the Data mount is empty. Tried zfs mount with no luck. tried to import the pool again. it said the pool already exists.
Any Ideas?
Try sudo zfs scrub .
the correct command is: sudo zpool scrub nameofpool
Use of fdisk needs to be depricated. gparted and parted should be used instead. These tools support GPT and 4K sector disks which fdisk does not handle properly.
Pingback: Verschlüsseltes NAS selber aufsetzen (Ubuntu, LUKS, ZFS, RAID) | undkonsortenBlog
Pingback: New Tech Toys | Transience