Introduction
Here is the 4th and final post on this subject. Previous posts can be found here, here, and there.
I’ll cover the installation of:
- A 4 ports SATA card ;
- A Media Center Remote USB receiver + remote ;
- Samba for home network CIFS filesharing ;
- ZFS for the main storage.
4 SATA ports PCI-Express controller
I bought a SAS3041E-HP card from eBay. My motherboard, an ASUSTeK AT5IONT-I, has a PCI-Express x4 slot but operating at x1 rate. While that rate, one 250MB/sec lane, could be a problem for a graphic card or anything with big bandwidth needs, it should be able to handle disk traffic just fine.
There was no software installation needed to get the SATA controller to work: its being handled just fine by the MPT driver from the GNU/Linux kernel.
Even if the controller supports RAID (only RAID0& RAID1 actually, no RAID5), I didn’t set it up. I want my storage to be controlled by ZFS, a very modern filesystem from the Solaris world that comes with a lot of advantages.
I plugged 4x2TB drives which were immediately discovered by the OS: no surprise here.
Media Center Remote USB receiver + remote
Alongside with the SATA controller, I also bought a MCE compatible remote and receiver from eBay. I was really afraid of the amount of tweaking I’ll need for all the buttons to work as intended, but here is the good news: is doesn’t need any!
My remote is an OEM HP MCE, but I can’t find any model reference on it. I guess all MCE compatible remotes from HP work the same way.
First, I started by plugging the USB receiver on the back of my server. It was recognized automatically by the kernel, but was giving weird results in XBMC. Some buttons were working just perfectly while others were sending some unidentified commands.
In order to get the remote to work as expected, I had to install lirc, the Linux InfraRed Control daemon:
apt-get install lirc
Right after installing I ran the configuration helper:
dpkg-reconfigure lirc
It should ask you what kind of remote you have, then what kind of receiver. My choices were:
- Remote: Windows Media Center Transceivers/Remotes (all)
- Receiver/Transmitter: Microsoft Windows Media Center V2 (usb) : Direct TV Receiver
With that done, I restarted XBMC and everything was working perfectly! All the keys are mapped correctly, even the colored ones that act like shortcuts to the main menus which is very helpful.
Samba for home network CIFS filesharing
Now that I can control everything from the couch using the remote, I’ll set up Samba so I can share my media folder over the network and copy files on it from my workstation.
Installing Samba is easy on Debian (well, Ubuntu here):
apt-get install samba
What may be a little more trickier here is to set up the configuration. The configuration file is located at /etc/samba/smb.conf: let’s fire up your favorite editor! I won’t list all settings here but just the important ones.
workgroup = WORKGROUP # Adjust to suit your network configuration
[homes]
comment = Home Directories
browseable = no
read only = no
[share]
comment = Guest share
path = /home/share
browseable = yes
read only = no
create mask = 775
directory mask = 775
force user = share
force group = users
So let’s explain all this a little.
First, the [homes] section will share the home directories of every user on the system. This is nice to transfer files back and forth on your network to a private directory.
Second, the [share] section will share a specific folder, /home/share here, which will be browseable by any authenticated user on the Samba server. We use specific directory & file masks, altogether with user & group forcing to enable all the users to write and read everybody’s files. This may not be a suitable security model in your environment, so be careful with this setting.
At last, I had to create the directory and set the corresponding permissions:
# useradd -m share
# chown share:users /home/share
You may now give any user the ability to connect to Samba using:
# smbpasswd -a <user>
Don’t forget to restart Samba for the changes to take effect.
ZFS for the main storage
First of all let’s explain why I want to use ZFS. While I could be happy with using all my drives as JBOD, I’d like to have some data security, ie. RAID. RAID1 is clearly not possible for me: the cost is prohibitive. I would have had to fall back to RAID5, which is known to have a few draw backs: its heavily CPU intensive, and has a write-hole issue.
ZFS appeared to be a natural solution to my problem: its able to operate as RAIDZ, some ZFS specific RAID-level basically the same as RAID5, and is using the Copy-on-Write mechanism. The file-system also provides data-integrity and 0-sized snapshots. It’s not really easy on the CPU, but I think the little Atom D525 can handle it.
Here comes the tricky part. I first tried using the KQ Infotech port of ZFS to GNU/Linux. It didn’t end up so well: I failed getting the lzfs module to build on Ubuntu 10.10 « Maverick ». Hopefully, the original implementation of ZFS on Linux had received some improvements with the 6.x series and was able to handle a complete file-system. This version also have the huge advantage of providing a PPA for the Ubuntu users out there like me, which ease the installation a lot.
First of all, let’s add the official PPA for ZFSOnLinux:
# add-apt-repository ppa:dajhorn/zfs
# apt-get update
The installation process is then straightforward:
# apt-get install ubuntu-zfs
It will take a few minutes for all the modules to be built against your running kernel. The packages also supports DKMS which means they will be recompiled automatically every time you install new kernel (during upgrades).
After that ZFS should be up and running! Let’s create our main storage pool:
# zpool create storage raidz1 sdb sdc sdd sde -f
None of the hard disk drives were formated so I need the -f flag to force pool creation. I don’t think this have any impact on the pool. Of course you would need to adjust the drive names according to your particular setup.
You should be able to see how your pool is doing using this command:
# zpool status storage
pool: storage
state: ONLINE
scan: none requested
config: NAME STATE READ WRITE CKSUM
storage ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
sdb ONLINE 0 0 0
sdc ONLINE 0 0 0
sdd ONLINE 0 0 0
sde ONLINE 0 0 0
The new zpool had its mountpoint automatically created by ZFS at /storage. You can ensure that using:
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
storage 401G 4.95T 53.9K /storage
Even if you could use /storage as your main storage directory, I strongly suggest that you create at least 1 sub-file-system because you can’t change the owner of the main mountpoint of a ZFS pool (just the of root directory itself). That’s why I created a 2nd file-system on my storage pool, then changed its default mountpoint:
# zfs create storage/share
# zfs set mountpoint=/home/share storage/share
From that point, everything was setup and working perfectly!
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
storage 401G 4.95T 53.9K /storage
storage/share 401G 4.95T 401G /home/share/
By default, the ZFS shares aren’t getting mounted at start-up, but you can edit /etc/default/zfs and set the ZFS_MOUNT variable to yes.
From my initial tests, the file-system is fast enough to handle my basic needs: I can achieve 45MB/sec copying files from the system disk. I didn’t have a single glitch yet, after a few months of testing.
Conclusion
What did I learn building this nice piece of HTPC/NAS server?
- Building a custom HTPC is expensive. I didn’t compute the total of my expenses, but I think I spent almost 800€. It has mostly to do with the 2TB drives, but the rest is still around 450€. You could probably get it down to 400€ with a small form-factor case including a PSU.
- A home-made HTPC is far better than any commercial one. XBMC is pretty awesome by itself, and the ability to operate at the OS level makes every customization possible.
- It may serve other purposes. Since I installed the server next to my TV I used it to run some scripts and do some UNIX-oriented development.
- ZFS is now ready to be used on GNU/Linux. It still needs some polishing to be perfect, but what is available already is pretty amazing.
- It’s possible to have a decent CPU with decent speed, and a HD-decoding capable graphic card, without any noise. I can’t even hear the 5 hard disk drives spin when the room is completely quiet.
I hope you liked those articles and invite you to ask any questions here in the comments.

I read all 4 posts, you have a really nice server there! Is a little out of my budget but I would love to put together a really nice server some day and host my web sites on them.. Always dreaming
Hey,
How is your set-up doing?
I’d like to build a similar set up, but the experimental status of ZFS is holding me back (I don’t want to wake up noticing all my anime is gone)…
The other option I’m considering is using FreeBSD and compile XBMC on FreeBSD. It should be possible but I have no idea about the stability of XBMC on FreeBSD.
Did you look into this option?