DIY Ubuntu NAS with AFP, SMB, DLNA and iTunes
I have been posting a lot about the LaCie Network Space recently. I finally had the courage to try and tinker with it and managed to add ssh and obtain root access. I was overjoyed, I proceeded to install ipkg, a package management tool much like apt-get, but suitable for weaker or embedded systems. The first thing I did was to install rsync, which I used to backup my data to an external usb drive. About one day after my backups were finished, the Network Space froze up on me and has now become an elegant yet unresponsive black box.
So I setup up my own NAS server on my spare Ubuntu laptop that plays nice with my Mac, serves media files to my Samsung LE40B650 and even shares my music with iTunes. Updated 2010.1.1
Step 1 - AFP
The first thing I did, was to follow this great tutorial to allow my Ubuntu machine to serve files through the AFP protocol. This is good if you have a Mac, because you can use the Apple Filling Protocol, and as an added bonus you can then use your Ubuntu machine to make TimeMachine backups from your Mac, so your Ubuntu machine can act much like Time Capsule.
One tip, if you do go ahead and set this up, and find that you cannot connect to your AFP shares from your Mac, make sure to delete the .AppleDB folders on your shares. This will only apply if you have connected to these shares using AFP in the past. Once you have deleted the old .AppleDB folders you will be able to connect using the AFP protocol and new .AppleDB folders will be made.
Update 2010.1.1
An additional good tip I woud like to give you, is to edit the following file (if you are not going to use any other protocol to share your files then you can ignore this update):
sudo gedit /etc/avahi/services/afpd.service
and to edit the following line from:
<name replace-wildcards="yes">%h</name>
to this:
<name replace-wildcards="yes">%h AFP</name>
This will help us identify the services in our Finder window on our Mac so that we can differentiate between using AFP or SMB. This edit is relevant for the next step as well.
If you also follow the update in Step 2 you should end up with this on your Mac in your Finder side-bar:
![]()
Step 2 - SMB
I also wanted to share my files using the SMB protocol, so that I could access them from my Windows machine. For this step you do not need any additional applications since Ubuntu has built in functionality.
From the terminal execute the following command:
shares-admin
A window will pop open, you may need to enter your password and you may be prompted to install additional packages (for SMB and NFS protocols).
Once you have done so, you can select the drive or folders to share, select the SMB protocol, and give the share a name.
Update 2010.1.1
Again I recommend this edit if you have followed the tutorial linked to in Step 1 and are sharing files using the AFP protocol as well:
Create the following file if you don't have it already:
sudo gedit /etc/avahi/services/samba.service
add this:
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h SMB</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
</service-group>
Check to see on which port your Ubuntu machine is serving your samba shares. I used a command line application call Nmap to do a port scan on my Ubuntu machine and found out that it was port 445, the service you are looking for in your port scanner is microsoft-ds
If you have also followed the update in Step 1 you should end up with this on your Mac in your Finder side-bar:
![]()
Step 3 - DLNA
The next step was to install minidlna on my Ubuntu machine, which is a small and lightweight dlna server created for embedded devices. The installation is very easy, here an example (make sure to edit the filename before you enter these commands as the version number will most probably be different) [source]:
kilroy@marvin:~$ ls -la minidlna_1.0.16-pre7_static.tar.gz
-rw-r--r-- 1 kilroy stefanh 1139313 23. Nov 10:02 minidlna_1.0.16-pre7_static.tar.gz
kilroy@marvin:~$ mkdir minidlna
kilroy@marvin:~$ tar xzf minidlna_1.0.16-pre7_static.tar.gz -C minidlna/
kilroy@marvin:~$ cd minidlna/
Once you have installed minidlna you will need to edit the config file:
sudo gedit etc/minidlna.conf
It is quite easy to understand:
friendly_name allows you give your dlna server a recognizable name
Then you have a section to define your shares:
media_dir=A,/media/audio
media_dir=V,/media/video
media_dir=P,/media/images
Finally you can start your dlna media server with the following command (run it from the folder in which you have installed minidlna):
kilroy@marvin:~/minidlna$ usr/sbin/minidlna -f etc/minidlna.conf
Note: you will need to run this command every time you restart your computer, by default minidlna will not launch automatically.
Now it will scan your media locations and index your files, once done, the media server should pop up on your dlna clients, such as a TV for example.
Step 4 - iTunes
Unfortunately minidlna does not support the format required by iTunes, so we will need to install another media server known as mt-daapd (or more recently Firefly Media Server).
In Ubuntu we can install it using:
sudo apt-get install mt-daapd
It will start immediately after installation and you will be able to access the web configuration by going to http://ip-of-your-machine:3689/
The default admin account and username are: mt-daapd (you can change this in /etc/mt-daapd.conf).
Then we need to configure it by clicking on the configuration link and adding our music folder:
Be careful with scan type and scan time, I have it set to scan once a day for music, I don't add music that often, so I don't need it to scan often.
Now go back to the server status link, and click on start scan.
If you have done everything right, you should immediately be able to see your server in iTunes:
In order to start the mt-daapd server after restarting your computer, enter the following command into the terminal:
sudo /etc/init.d/mt-daapd start
Note: It needs to run in root mode, hence the use of "sudo". Once started, it will scan your media location, and only after it has finished scanning will you be able to access the web interface.
Samsung LE40B650
I can confirm that minidlna works nicely with the Samsung LE40B650. I am happy to notice that the pause button finally works, so I am able to pause a movie and then continue. Fast forwarding or rewinding do not work yet and I am looking into that still.
My LaCie Network Space had TwonkyVision installed on it, a commercial DLNA server, this worked also with the Samsung LE40B650, but I was not even able to pause a movie. So minidlna has already paid off in my opinion.
Conclusion
With these simple steps you can create a basic file and media server that can even serve as a Time Capsule for your Mac and play nice with iTunes. Total set up time is roughly 30-45 mins.
Now that my LaCie Network Space has died (i will be sending it in to LaCie to get it fixed) I have set up a complete alternative that is, IMO, easier to maintain and configure.
Hope this helps others out there.




January 6th, 2010 - 23:45
Nice compilation of solutions.
great work.
January 13th, 2010 - 00:02
Great howto, thanks.
January 13th, 2010 - 10:25
Well..
For some reason, AFP worked once.
I had SMB working, and I was connected to it.
The first time I connected to the AFP share, I got rejected from the Samba share, I guess because SMB was mounted on /Volumes/sw and AFP mounted under the same name.
Then, while AFP was mounted, I couldn’t mount the share “sw” on the SMB server, the share was grayed out (while others were not).
Anyway, AFP was working fine, then I tried getting SMB and AFP and this is where AFP stopped working.
Now all I’m getting from AFP is “You entered an invalid username or password. Please try again.”
I ran tcpdump, I can see traffic going while initiating the connection with AFP, but when I type my password, I immediately get the error message and I see no exchange with the server. The issue must be on my laptop, something must be cached somewhere.
Any idea ?
Thanks
January 13th, 2010 - 15:16
Actually my SMB and AFP shares both point to the same folder location i.e. I am sharing my files and folders through both methods, since my wife uses a combination of windows and ubuntu and i use a combination of ubuntu and mac.
I don’t think the problems you are having have anything to do with sharing /Volumes/sw through both methods.
This issue could be linked to your settings in the AppleVolumes.default file.
How are you sharing your AFP shares? What settings did you choose?
January 14th, 2010 - 10:53
After many tests, I decided to rebuild netatalk with SSL support (it seemed netatalk was built with SSL support in Debian, but it’s actually not).
With the rebuilt version, it works fine and I can have both AFP and SMB mounted.
Not sure what exactly happened the “first” time AFP got mounted, if it ever happened
Thanks !
January 14th, 2010 - 11:10
Glad to hear it’s working