HowTo: Make Ubuntu A Perfect Mac File Server And Time Machine Volume [Update6]

Ubuntu Mac File Server ConnectivityFor quite some time I use my Ubuntu machine as a file and backup server for all Macs in my network which is perfectly accessible from the Finder in Mac OS X. There are some instructions available in the web for this task but all failed in my case so I wrote my own tutorial with all the steps needed for it to work properly.

So here’s my little Tutorial for connecting Mac OS X Leopard with Ubuntu and using your Ubuntu machine as a backup volume for Time Machine but all steps can be reproduced on every Linux box and they work with Mac OS X 10.4 Tiger too. At the end of this tutorial you will have a server which shows up in the Finder sidebar and behaves just like a Mac server when accessing it from your Macs. To be perfectly integrated with Mac OS X we’re going to use Apple’s Filing Protocol (AFP) for network and file sharing.

Although this Tutorial involves using the Terminal in Ubuntu and looks a bit geeky it’s very easy even for beginners. I have tried to explain all steps and Terminal commands so you may learn a bit about the Terminal too. At the end of the article you can download my Server Displays icon pack quickly made by me with custom icons for a Mac, Ubuntu and Windows server.

Personally I use a fresh installation of Ubuntu 8.04 Hardy Heron Desktop version (32bit on one machine, 64bit on the other) and Mac OS X Leopard (10.5.3 and later) to connect to them. On my Ubuntu boxes there’s no other file sharing protocol like samba (Windows sharing) or NFS activated.

Update 12/07/2008:
Rumors are Apple will add some undocumented AFP commands with the Mac OS X 10.5.6 update which therefor won’t be supported by the current Netatalk package (and maybe never will). So be sure to check the latest comments on this article when the 10.5.6 update is out to see if this rumor is true and if there are problems caused by that.

Here are the steps involved in setting up your Ubuntu box as a Mac file server:

  1. Modify and install Netatalk (Open Source AFP implementation)
  2. Configure Netatalk
  3. Configure shared volumes (and Time Machine volume)
  4. Install Avahi (Open Source Bonjour implementation)
  5. Configure Avahi and advertise services
  6. Configure TimeMachine
  7. Conclusion, Problems and more informations
  8. Downloading and using the Server Display Icons
  9. Translations Of This Article

1. Modify and install Netatalk

Netatalk iconNetatalk is the Open Source implementation of AFP. Mac OS X requires encryption to work properly but the standard package of netatalk provided in the Ubuntu repositories doesn’t include this feature. So we have to build our own netatalk package from the sources with the encryption feature enabled.

First you have to enable the Source Code repositories via System > Administration > Software Sources under the Ubuntu Software tab. Check the Source Code Box, click Close and choose Reload in the next dialogue.

Source Code Repositories

Update 09/28/2008: Alessandro has built a nice .deb package for i386 machines. Although written in italian you can follow the necessary code snippets for installing this package in his blog post. If the install package works for you just skip the following self compiling process and head over to the Configure Netatalk section.

Now fire up your Terminal under Applications > Accessories and execute the following lines (separately). You have to type Y for yes when Terminal asks you if it should continue:

sudo apt-get build-dep netatalk
sudo apt-get install cracklib2-dev fakeroot libssl-dev
sudo apt-get source netatalk
cd netatalk-2*

Now you have downloaded the source code of Netatalk to your home folder, installed some required packages for building Netatalk and changed the directory to the downloaded folder.

Next you have to build the Netatalk package with the encryption option enabled:

sudo DEB_BUILD_OPTIONS=ssl dpkg-buildpackage -rfakeroot

Depending on your hardware this may take a while but you can enjoy the geeky build output in your Terminal:

Building Netatalk

If everything went through without errors (except the signing warnings, can be ignored) you can install the recently created package:

sudo dpkg -i ~/netatalk_2*.deb

To stop Ubuntu from overwriting your custom Netatalk package you should set its state to hold. This will cause the Netatalk package being grayed out in the Software Update dialogue:

echo "netatalk hold" | sudo dpkg --set-selections

Now you have successfully build and installed your custom Netatalk package which now has support for encrypted logins. Now let’s configure the whole thing.

2. Configure Netatalk

Netatalk iconFirst you should deactivate services provided by Netatalk which are not needed if you just want to use your Ubuntu box for file sharing. This will speed up the response and startup time of Netatalk dramatically. For instance Netatalk starts the old AppleTalk protocol by default which is just needed for pre OS X systems. So we’re going to use the graphical editor gedit for stopping unneeded services:

sudo gedit /etc/default/netatalk

gedit should pop up with the defined file loaded as superuser (needed for saving). Find the “#Set which daemons to run” part and replace the default values with these to enable just AFP and disable all unneeded services. Let the cnid_meta daemon run too and if you want to share your Linux connected printer with your Mac also enable the pap daemon (set to yes):

ATALKD_RUN=no
PAPD_RUN=no
CNID_METAD_RUN=yes
AFPD_RUN=yes
TIMELORD_RUN=no
A2BOOT_RUN=no

Here it’s very important to run the cnid_meta daemon because this service will handle all the metadata for us (namely the reosurce fork) which would get lost due to the fact that your Linux box isn’t formatted as Apple’s HFS+. If you’re interested what the other services could do: atalkd is the AppleTalk daemon (pre-OSX file sharing, old printing), timelord can make your Linux box a network time server and please don’t ask me for what a2boot is good for (If you know it, post it in the comments please / Kelly suggests it’s a netboot server for client Macs).

Press Ctrl + S to save the document or choose File > Save. Next we have to edit the main config file for AFP sharing called afpd.conf:

sudo gedit /etc/netatalk/afpd.conf

Scroll to the very bottom of the document and add this to the bottom (replace the whole line in case there’s already one). This is one line so be sure that there’s no line break in your afpd.conf file:

- -transall -uamlist uams_randnum.so,uams_dhx.so -nosavepassword -advertise_ssh

Press Ctrl + S to save the document or choose File > Save.

3. Configure shared Volumes

Time Machine Volume iconNow we have to tell the afpd daemon what Volumes to share. This is defined in the AppleVolumes.default file inside /etc/netatalk/. The following line will open this file in the gedit editor with superuser privileges (required for saving) where we can define our shared volumes:

sudo gedit /etc/netatalk/AppleVolumes.default

Scroll to the bottom of the document and define your Volume shares. By adding the following line you will share each users home directory with the user name as the Volume name. To make things more secure you can define all users who are allowed to connect to your Ubuntu box via AFP:

~/ "$u" allow:username1,username2 cnidscheme:cdb

Because we want to use the Ubuntu machine as a backup server for Time Machine you should define a second volume just for Time Machine. Create a new folder in your home directory first and name it TimeMachine (or anything you like). Then add the following line to your AppleVolumes.default. This is one line so be sure that there’s no line break in your AppleVolumes.default file:

/home/username/TimeMachine TimeMachine allow:username1,username2 cnidscheme:cdb options:usedots,upriv

Thanks to tsanga for pointing out the usedots and upriv options. The usedots option is required if you want to use invisible files and folders (those starting with a dot in the name). Otherwise afpd would encode them as :2e which is bad if you have to use invisible files (like .htaccess). If you’re on Leopard and have no Tiger installed Macs in your network or mixed OS X versions in your network you should use the upriv option which adds support for AFP3 unix privileges. If you have Macs with Tiger installed just use options:usedots to avoid unexpected behavior:

/home/username/TimeMachine TimeMachine allow:username1,username2 cnidscheme:cdb options:usedots

Finally if you want more stability and can accept slower file transfers you can use the dbd cnidscheme (cnidscheme:dbd).

Press Ctrl + S to save the document or choose File > Save. Of course you can define every folder you like or even an attached USB disk. Just define the correct path. External drives in Ubuntu should be found under /media

Finally restart Netatalk to activate the changes:

sudo /etc/init.d/netatalk restart

Although we now have a fully configured AFP file server it will not show up in the Finder sidebar on Mac OS X Leopard (but it’s reachable via Go > Connect to Server… in the Finder). Macs use a service called Bonjour for the sidebar thing (and for a lot of other cool stuff) and on the Linux side we can have this functionality with the Open Source implementation of Bonjour, called Avahi.

4. Install Avahi

Bonjour iconSo the Avahi daemon will advertise all defined services across your network just like Bonjour do. So let’s install the avahi daemon and the mDNS library used for imitating the Bonjour service. When fully configured this will cause all Macs in your network to discover your Ubuntu box automatically:

sudo apt-get install avahi-daemon
sudo apt-get install libnss-mdns

To make everything work properly you have to edit the nsswitch.conf file:

sudo gedit /etc/nsswitch.conf

Just add “mdns” at the end of the line that starts with “hosts:”. Now the line should look like this:

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns

Press Ctrl + S to save the document or choose File > Save.

5. Configure Avahi and advertise services

Bonjour iconNext we have to tell Avahi which services it should advertise across the network. In our case we just want to advertise AFP sharing. This is done by creating a xml-file for each service inside /etc/avahi/services/ following a special syntax. Let’s create a xml-file for the afpd service with the following line:

sudo gedit /etc/avahi/services/afpd.service

A blank document should open in gedit. Now paste the following into the document and save the file by pressing Ctrl + S or by choosing File > Save:


<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=Xserve</txt-record>
</service>
</service-group>

update: The last part is used to assign a specific (Apple) hardware model to your Linux box. In this example your server will be advertised as an XServe and will be shown with this icon in the Finder sidebar. This will come in handy when you want to use your own icon for it or the one’s made by me provided within this article. Thanks to Simon Wheatley for figuring this out. Additionally you can use these models in this file: RackMac (same as Xserve), PowerBook, PowerMac, Macmini, iMac, MacBook, MacBookPro, MacBookAir, MacPro, AppleTV1,1, AirPort

Finally restart the avahi daemon to activate all changes:

sudo /etc/init.d/avahi-daemon restart

Now you have configured the Avahi daemon to advertise AFP sharing across your network which will cause your Ubuntu box to show up in Finder’s sidebar in Mac OS X Leopard. In Mac OS X 10.4 Tiger your Ubuntu server should now be visible under Network.

Now you’re done with setting up AFP file sharing on your Ubuntu box and advertising it across the network for Finder’s sidebar. Check if everything works as intended by clicking on your Ubuntu server in Finder and clicking on the “Connect As” button. Enter your username and password (the ones you’re using on your Ubuntu machine) and you should see the Volumes we defined earlier with the AppleVolumes.default file:

Netatalk shares

Another side effect of using AFP is that your Ubuntu box will show up as a nice Apple Cinema Display icon instead of the BSOD windows icon. Here you see my Ubuntu server showing up in Finder as Rockhopper:

Ubuntu box in Finder

update: If you’ve followed the revised version of this article your Linux box should now be represented by a Xserve icon in Finder:

Ubuntu box as Xserver in Finder

6. Configure Time Machine

Time Machine iconupdate 07/14/2008: On the Mac side you have to enable the option to use network volumes as Time Machine drives first. Without it your freshly shared and advertised network volume won’t show up in the disk selection dialogue in Time Machine. This is a hidden option not accessible via the graphical user interface so you have to copy & paste this in Terminal (it’s one line):

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Thanks to FoolsRun and tsanga for pointing this out in the comments

Now just mount the “TimeMachine” Volume first and choose it as a backup disk in the Time Machine system preferences. Time Machine will create a sparsebundle disk image inside the volume and mounts that too. This is needed because the hard drive on your Ubuntu box is formatted as ext3 or Reiserfs and not the native Mac format HFS+. Because Time Machine backups everything to the disk image all metadata (like creation dates etc.) will be preserved.

When your first Time Machine backup is done you can remove all Volumes and the next time Time Machine starts it will automagically mount the disk image from your TimeMachine volume on your Ubuntu box without mounting the whole TimeMachine volume:

Finder sidebar

7. Conclusion, Problems and more informations

You see that Linux and Ubuntu can be configured to behave like Macs in your network. But it’s sad, that you have to fire up the Terminal to achieve this. I hope especially the Ubuntu team will simplify this in future versions. Another sad thing is that Ubuntu is missing a useful avahi/Bonjour and AFP implementation for Nautilus, the file manager. So there’s no way to access your Mac from Ubuntu via AFP in the file manager. In my network I use SSH to access the Macs from Ubuntu or Linux by allowing Remote Login on the Macs in the Sharing preferences. But there’s a command line based AFP client available called afps-ng which uses the FUSE system.

Some other strategies of connecting Ubuntu/Linux and Mac OS X would involve sharing via Samba (Windows sharing) or NFS but according to my experiences nothing beats the speed, stability and secureness of AFP.

But if you’re interested you can have a look at this post on the ubuntuforums to learn how to setup NFS for file sharing between Ubuntu and Mac OS X Leopard.

Although I have checked all log files while using file sharing and especially while Time Machine is running and found no errors or warnings I cannot guarantee it’s working without errors or backup data loss on your system too. So I encourage you to check the system logs on Ubuntu AND on Mac OS X with the Console app in your Utilities folder. If you see no errors or warnings this configuration should be pretty bullet proof in terms of stability.

Finally the only problem remaining is that your Ubuntu or Linux box isn’t formatted as journaled HFS+ so some scenarios would fail or make problems. This can include having your iTunes, iPhoto or Aperture library on your Ubuntu server. But the cnid_meta daemon will always try handle that for us. This will cause some hidden folders to show up in Ubuntu which are used to store all the metadata required to almost reproduce a HFS+ file system. But if you ever run into problems you can easily resolve these by creating sparse disk images on your server with the Disk Utility built into Mac OS X. Just create a new sparse disk image on your desktop, copy it to your mounted Ubuntu volume and mount the copied disk image by double clicking it. Now you can put all the files and libraries in it which depends on HFS+

update 07/06/2008:

Problems with creating the backup disk image

If time Machine says “The backup disk image could not be created” during the first backup attempt you can do the following to avoid this problem and some others (backup fail due to permissions):

In short, you have to create the backup disk image on your Desktop and copy it to your mounted Time Machine volume. But Time Machine creates a unique filename for the disk image and we can find out this name with a little trick:

First open up the Console from your Applications > Utilities folder and open the Time Machine preferences. In Time Machine preferences set your backup volume back to none. After that reselect your mounted Time Machine volume. The counter should start and Time Machine’s big button will change to on. When the backup tries to start and fail have a look at your Console (Click All Messages in the sidepane). There should be a line tellung you the name of the disk image:

Creating disk image /Volumes/TimeMachine/computername_0014e3856bd0.sparsebundle

The computername should be the name you have assigned to your Mac. Now just click on that line and hit command + C to copy the message.

Now Open Disk Utility from your Applications > Utilities folder and click on New Image in the toolbar. Now just hit Command + V in the Save As field and remove everything before the name of the sparsebundle.

Update: The secret number Time Machine adds to your computer name is nothing more than the MAC address of the network device that your Mac uses to talk to your server, as Simulacrum and Todd found out in the comments. As he points out you can open up Network Utility and under the info tab you’ll find a field called “Hardware Address”. Just remove the colons and you have the number Time Machine adds to the disk image name.

In the field volume name write Backup of computername. Now FIRST chose sparse bundle disk image as the image format and THEN adjust the volume size to the size of your internal harddrive (minimum, choose more if you like) afterwards. Remember that Disk Utility won’t let you make a bigger image file as you have physical hard drive space available if you don’t chose sparse bundle disk image as the image format first. For reference have a look at this screenshot:

Time Machine sparse bundle disk image

Select your Desktop as destination and click create. After the creation is finished drag the created disk image to your mounted Time Machine volume (you can delete the disk image on your desktop when copy is finished). Finally go to Time Machine preferences and start your backup again and everything should work as expected now. After the first backup (this can take a long time depending on your harddrive) you can unmount your Time Machine volume and the next time Time Machine starts it will grab and mount the sparse bundle disk image automatically (with “Backup of computername” as the volume name).

update 09/21/2008:

Firewall Settings

As Kevin points out in the comments you would have to adjust any firewall you use. But the standard Ubuntu installation won’t use any Firewall.

In short you have to allow communications over port 548 and 5353.

“Connection Failed”

If you get one of those errors:

"Connection Failed - There was an error connection to the server. Check the server name or IP address and try again"

or

"There was an error connecting to the server. Check the server name or IP address and try again. If you are unable to resolve the problem contact your system administrator."

you should first be sure you have either no firewall on your Ubuntu box in use or have it configured to allow AFP communications as suggested in the above paragraph.

Remember that this error can be caused by a myriad of problems and just a lot of other configurations on your side. So you should try a minimal way: On my Ubuntu boxes I have no other file sharing protocol like samba or NFS enabled (even not installed) so the samba hostname and the AFP hostname can’t interfere with each other. Also I’ve left the Workgroup field blank under System > Administration > Network > General tab.

If you still can’t connect to your Ubuntu box you can edit your /etc/hosts file as I’ve pointed out in the comments:

sudo gedit /etc/hosts

Add the following two lines at the very top of the file.

127.0.0.1 localhost
127.0.1.1 Rockhopper.local Rockhopper

My server is named Rockhopper, adjust the name according to your server name. There should be some sort of name already but the important part here is the servername.local which is the AFP way of server names. If there are any other numbers at the beginning in your file leave them as they are.

If that won’t solve the connection problems you can test out Eric’s solution as suggested in the comments which would involve removing and reinstalling netatalk.

Sorry I can’t give you any other solutions for that but in most cases it’s some sort of network misconfiguration outside of netatalk or avahi and on Linux these can be a lot of configurations on your side I can’t know of. And since I’m not able to reproduce these errors I can’t investigate in them.

But for those people still having problems with these error messages: On Mac OS X have a look in the Console app inside your Utilities folder. Click on “All Messages” in the left sidebar, try to connect to your Ubuntu box in Finder and see the messages in Console. These are the “real” error messages which normally will lead you to a solution.

-5014 error

Some people have problems when connecting to an AFP share and get a -5014 error. As J5 pointed out in the comments you have to delete the hidden .AppleDB folders on your Ubuntu box and restart netatalk afterwards:

sudo /etc/init.d/netatalk restart

Time Machine Full System Restore

In case of a full system restore you would have to boot your Mac from the Mac OS X installation DVD (the one delivered with your Mac) by pressing the c key during boot. Your Mac will start with a minimal UI where you have a Utilities section in the top menu bar. There you’ll find “Restore from a Time Machine Backup” but it won’t find your network share with your Time Machine backup. Luckily Dmitry Nedospasov found a way to manage this by simply mounting your Time Machine network share with the Terminal (which you can find under Utilities in the menu bar too) by utilizing the following syntax (shamelessly copied from Dmitry):

mount -t afp afp://username:password@hostname/ShareName /Volumes/ShareMount

Replace everything instead of /Volumes with your matching names. You can test if your network share was properly mounted by doing

ls /Volumes

which outputs the content of the Volumes folder and you should see your network share.

Now you can close the Terminal and select “Restore from Time Machine Backup” from the Utilities entry in the menu bar and select your mounted Time Machine backup and thats it. Oh, needless to say: a gigabit ethernet connection will speed things up dramatically even compared to (draft)n-WLAN.

update 12/07/2008:

Netatalk backup disk reaching maximum capacity

As Seron pointed out in the comments, there is some discussion on the net regarding problems with Netatalk and TimeMachine when the backup disk reaches maximum capacity. This is due to missing support for the AFP commands FPSyncDir aka commands 78 and 78 in Netatalk. As a commenter in an ArsTechnica forum says: “As soon as your backup volume will reach max capacity, it will self destruct because of it.”

In the forum you’ll also find some links to various patches to avoid problems with that. If you have tested such patch please post your experiences in the comments for this article.

More Articles

8. Downloading and using the Server Display Icons

Ubuntu Server DisplayI’ve quickly crafted a custom icon for your Ubuntu server. It’s the Apple Cinema Display with the default wallpaper of Ubuntu 8.04 called Hardy Heron. Additionally I’ve included an icon with the default Leopard and the default Vista wallpaper to represent your Leopard and Windows server too (The default Mac server icon uses the old Tiger wallpaper).

Here you can see the icons included in the Server Displays icon pack:

Server Displays

Because I’ve just modified Apple’s standard icons these icons are just available via this blog post and they will not show up in my Goodies section. Just download the whole package directly via this link:

v1.0 | 4 icons | zip-file | 5.5MB

How to use the icons

In the avahi configuration part in this article you have assigned the Xserve device info to your afpd.service file. All you have to do is to replace the generic Xserve icon (or whatever model you have assigned in your afpd.service file) with an icon from this icon package. Just rename the Ubuntu Server.icns to com.apple.xserve.icns and navigate to

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources

Drag & drop the renamed file into this path and replace the generic icon (making a backup before doing that is a good idea) and after a logout all your avahi advertised Ubuntu servers should be displayed with the new icon (assuming that you assigned a device model in avahi).

If you’ve used another model in your afpd.service file, browse the Resources of CoreTypes.bundle to get to know the correct filename for the device icon and replace that file.

As for the Windows Vista server icon: Just rename the Windows Server.icns file to public.generic-pc.icns and navigate to

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources

Now drag & drop the renamed file into this path and replace the generic icon (making a backup before doing that is a good idea) and after a logout all your Windows servers should be displayed with the new icon.

update: A solution for the icon problem is here: Simon Wheatley figured out how to assign a different icon to your avahi advertised Linux box. All you have to do is assigning a device info part at the end of the avahi service file for AFP. I’ve updated this article to include this part. Please head back to the Configure Avahi and advertise services part in this article and edit your afpd.service file again if you’ve followed the first revision of this article.

Oh no!

Congratulations! You finally arrived at the end of my article. There’s a good chance that your coffee or tea cup is now empty. But before making your next coffee you should share this article on your favorite social website. Your vote is highly appreciated! After you’ve finished voting and making your next coffee or tea you could subscribe to my RSS- or Atom-Feed, discuss this article or buy me my next coffee ;-)

9. Translations Of This Article

The following articles are direct translations of my article but some of them are slightly modified or simplified. Remember that the authors/translators are responsible for the content.

German: Ubuntu + Apple Fileserver + TimeMachine on kde4.de
French: Tuto: Comment créer votre serveur Time Capsule sous Debian on the Blog of Pierre de la Celle

Article Updates

01/19/2009 added links to some translations of this article

12/07/2008 added a warning regarding the new undocumented AFP commands which maybe will be added by Apple with the Mac OS X 10.5.6 update

09/28/2008 added a link to the precompiled Netatalk .deb package from Alessandro

07/14/2008 added the Time Machine network volume hack under 6. Configure Time Machine

07/06/2008 added a new part Problems with creating the backup disk image

06/21/2008 added instructions for changing the server icons in Mac OS X

923 Responses

  1. Anuj Sehgal

    I was setting up a new server the other day and followed your post to setup netatalk and avahi for sharing to my macs from the ubuntu machine. All worked great till I was using the wifi.

    When I plugged in the machine to the ethernet port on my router and disabled the wireless, to my absolute surprise the avahi advertised services would just keep disappearing after 3-4 mins, unless I restarted the service.

    Of course, my first solution to this was a small hack to create a cron job to restart the avahi-daemon every few minutes, but this is not ideal.

    It turns out that the problem has to do with multicasting and some network card drivers may lead to this issue. The solution in my case was to turn on promiscuous mode on eth0 and voila, everything works. Its been 3 days now and I have even accessed the server through the internet. All rock solid!

  2. maze

    In Ubuntu 10.04LTS the build command has become:


    sudo DEB_BUILD_OPTIONS=openssl dpkg-buildpackage -rfakeroot

    Thanks for this great documentation!

  3. Drew

    So, I too got the “Connection Failed” message. To remedy it I changed afpd.conf to allow for Allow Diffie-Hellman eXchange 2 (DHX2) for authentication. My afpd.conf now looks like this:

    - -transall -uamlist uams_randnum.so,uams_dhx.so,uams_dhx2.so -savepassword -advertise_ssh

    * There are also some other tweaks. But uams_dhx2.so is essential for my setup. My setup:
    OS X 10.5.8
    afpd 2.0.5

    • Lacy

      This was driving me nuts! Found the answer on a forum and solved my “connection failed” instantly.

      “uams_dhx2.so is essential”

  4. Carsten

    Anuj:
    I have the exact same problem.. Can you please guide me to turn on promiscuous mode on eth0 ??

  5. nrsgzz

    Hi.
    I followed your tutorial but could not mount the AFP share on my macbook. The ubuntu server is running 10.04LTS and the client is a 10.6.3 “Snow Leopard”.
    The server shows up in finder but it doesn’t display any folders.
    If I try to mount the share on the terminal I get

    “mount_afp: AFPMountURL returned error -5002, errno is -5002″

    Any thoughts?

    • Puneet Madaan

      #nrsgzz

      you do not need all steps for Ubuntu 10.x … netatalk luckily fixed the stuffs :)

      so all you need to do is..

      sudo apt-get install netatalk avahi-daemon libnss-mdns

      then edit mount volumes in

      sudo gedit /etc/netatalk/AppleVolumes.default

      configure avahi in

      sudo gedit /etc/avahi/services/afpd.service

      and add mdns in /etc/nsswitch.conf as explained in article.

      I used the config from above, though i call the server macpro ;) and everything else went great :)

  6. Hugo

    I can confirm that this article has become obsolete for the most part. Just installing Netatalk, Avahi and mdns from Ubuntu repositories is all you need. The only manuel steps are adding your share in Netatlak and configure Avahi. Setup is done in under 5 minutes. Works not only in 10.04 but also in 9.10.

  7. docbrown

    Thanks for such a well written guide!

    I’ve got AFP running on two Ubuntu 10.04 computers which work fine, but experience the same issues as Davy (posted May 14 2010)

    My shares for the two computers:

    host: mythtv
    share: home-mythtv

    host: seedbox
    share: home-seedbox
    share: seedbox1tb

    if I mount a share from seedbox, the same shares are listed when I try to view the mythtv shares. So mounting from two ubuntu computers simultaneously is not possible. To get to the shares from the other host, I need to unmount the current share first.

    Would really appreciate any help! Thanks.

  8. docbrown

    Did some more digging and found a fix to my issue above. Posting here in case others wish to achieve something similar.

    If you have multiple linux afp servers on the same network, and want to mount shares from each host at the same time, you must add this line to /etc/netatalk/afpd.conf on each server:

    -signature user: | hostname
    

    for example, on the host “mythtv” i have
    -signature user:mythtv | mythtv

    and on the host “seedbox”
    -signature user:seedbox | seedbox

    user: must be different on each machine.

    Hope this helps.

  9. Ryan Drake

    Thanks for this guide. It deserves its place at the top of the search results for linux time machine! I hit it up every time I set up a new system.

    This guide is definitely still good information for Debian, which does not ship with ssl-enabled netatalk out of the box.

  10. Jarrod

    I had this working for 1 night, then I wake up the next morning and try to access the the server (AFP) via the finder and I get a message that states: “Your password has expired..Please contact the system admin for details.” Could you help me on this issue. I am new to linux, so I am not sure what is going on. I have already used some terminal commands in Ubuntu to ensure that my password is not set to expire!

  11. tdiaz

    For those who use samba along side this, adding this to /etc/samba/smb.conf makes the file content identical to what the Mac sees:

    veto files = /.*/:2*/TheVolumeSettingsFolder*/TheFindByContentFolder*/Network*Trash*Folder/Temporary*Items/

  12. Mac Connolly

    what do i put under the username1 and username2 line???
    i know it says “By adding the following line you will share each users home directory with the user name as the” but i dont get it

    • Ozz

      Thanks for the article!
      I have 1 problem thou. I use the Puneet Madaan method.
      I have 4 drives (1 1.5TB and three 300GB) in the Ubuntu box. I see all shares on my Mac but only the 1.5TB drive i can open and work with. When opening the other three drives i get a error message that the original item is not found? Can someone please get me on the right way?
      Thanks!

  13. jonnyfive

    Thanks for this great guide! I am unfortunately having a problem I can’t seem to figure out.

    everything works great for my admin user on my ubuntu server, but additional users I can not get any shares besides their default home share to show up when they log onto the file server.

    example:

    "media/Big Disk/music" "music" allowed:admin_user,regular_user cnidscheme:cdb options:usedots,upriv

    the sahre “music” shows up just fine for admin_user but not for regular_user.

    any suggestions?

    thanks
    Jonny

  14. Martin West

    Just switch to fedora after an abortive attempt to upgrade to 10.04 on a new server. Basically you follow the same process as Ubuntu 10.04 with the following changes

    replace apt-get with yum

    Fedora Core 13 already has avahi et al installed

    Just install netatalk

    yum install netatalk

    the netatalk config files are in /etc/atalk with the same names.

    the init.d stuff has different commands

    to add netatalk etc to the start up

    chkconfig atalk on

    chkconfig –list | grep talk
    atalk 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    Had to delete the .AppleDB folder (again).

    Also had to do chown -R USERNAME:GROUPID TIME_MACHINE_DIR

    Since uid/gid changed from 1000 to 500 on the new machine.

  15. Asbjorn

    I have one problem I don´t find a solution to. I have two users on the ubuntu machine (Ubuntu 10.04). Two lines of text in AppleVolumes.default. The two lines are identical exept they point to the two different users. Each user has a separate TimeMachine folder (named TimeMachineUsername).

    The problem is that we can both log onto Ubuntu, but only one of the users see the TimeMachine folder. The other user only sees the home folder. What can it be?

  16. Colt

    Does anyone know how I would share an entire hard drive? I have a 1TB drive that I would like to be accessible on my mac. I am unsure what I need to put in the AppleVolumes.default file. Any suggestions?

  17. Felipe Sugimoto

    Dear friends,

    I think it worths to tell my story here. I really enjoyed reading this tutorial and comments last year when I tried to make a FreeNAS server (not a Ubuntu Server as mentioned here) with Time Machine. It didn’t work unfortunately. It was really unstable and, for it purpose it didn’t worth.

    This year I decided to buy a Time Capsule and I must say that it worths its price here in Brazil. I should only warn you guys to UNDO THE TERMINAL CHANGES BEFORE YOUR FIRST BACKUP (it’s the “defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1″ command, you only need to change “1″ to “0″ (zero) back).

    I had a f&#$ng headache because I forgot that I had done this last year. If you don’t change this, Time Machine WON’T BACKUP and will flood your screen with a thousand of SVN (subversion) problem/errors messages.

    In my first time, I messed it up so much that I had to open (physically) my Time Capsule and erase my disk. I just start thinking that it was a problem on my Macbook after I tried to make a Time Machine on my Mac Mini and it worked flawless.

    So please, remember to set the configs to default if you buy a Time Capsule.

  18. Alexander

    Great article, it is super detailed! Thanks! One question, what if I don’t want to use usernames and have the shares open for everybody in the network? How can I do this?

    Any ideas would be welcome.

  19. Rubin110

    I recently built a new Debian box to run as my home server replacing an older machine I had the same setup on. Here are some notes about things I’ve learned this time around…

    - More current versions of netatalk (Anything 2.0.5 and later) no longer support masquerading symlinks as actual files/directors in order to satisfy some Apple spec. Kind of sucks. The symlinks will act just like normal symlinks would in the *nix world, as a pointer to something else, so if /media/drivename/timemachine exists on your mac, then you’re in luck. You can use a relative path for the symlink and make sure the path is valid through the AFP mount, that works fine.

    - Running OSX 10.6.4 and Debian Squeeze, Time Machine didn’t barfing when a disk image wasn’t present with it’s own machine ID.

    Other then that, gigabit ethernet makes the medicine go down faster. :)

  20. jt2010

    Thanks for the awesome guide, worked like a charm on Ubuntu 10.04 amd64 jumping in at 2. Configuring.. using default packages

    One little suggestion, use
    options:usedots,upriv
    at the end of the
    ~/ "$u" allow:username1,username2 cnidscheme:cdb
    line, so it reads
    ~/ "$u" allow:username1,username2 cnidscheme:cdb options:usedots,upriv

    This avoids (very ugly) :2eDStore files everywhere when you open you home folder over netatalk.

    Thanks,

    John

  21. David Ontiveros

    I have used this tutorial numerous times. However, I did manage to have this done on a FreeBSD headless box. I don’t want any X11 libraries on this box. You can do this by adding the following to /etc/make.conf:

    WITHOUT_X11=yes

  22. alex gardiner

    Hi there.

    This article is great.

    Thanks to you I am now running 10.04 ubuntu with netatalk and avahi. Performance is great across a 12 drive raid 6 array.

    The way I’m working is creating a user on the ubuntu server when I need to create a new share for somebody. This might be messy, but it does mean I don’t have to restart netatalk each time I need to create a share.

    The remaining question I have yet to find an answer to is how do I limit the number of people who can connect to an individual share concurrently?

    Do you know if this possible?

    I suppose I am looking for a function similar to the ‘max connections’ in samba.

  23. JvBSH

    If you add the following service to avahi, then you don’t have to tweek the Time Machine settings as indicated in the article.


    %h (TimeMachine)

    _adisk._tcp
    9

  24. JvBSH

    Well, my previous comment didn’t look too good …
    This how it should look:


    <?xml version="1.0" standalone='no'?><!--*-nxml-*-->

    <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
    <service-group>
    <name replace-wildcards="yes">%h (TimeMachine)</name>
    <service>
    <type>_afdisk._tcp</type>
    <port>9</port>
    </service>
    </service-group>

  25. Pierre

    Like Semmi (#650) I get

    “something wrong with the volume’s DB … FIXME with a better msg”

    but it seems to be the only way I can get my ubuntu box (actually running Xubuntu 10.04 LTS) to talk to my wife’s MacBook running OS X 10.5.8, or vice versa.

    I’ve tried using cnidscheme:dbd and I don’t get the message but the MacBook doesn’t seem to be able to properly connect to the Linux box – it eventually appears to have connected but trying to browse files in the Finder or open Time Machine Preferences just leaves a Spinning Beachball and then the volume seems to unmount from Finder.

    Going back to cnidscheme:cdb I’ve been able to back up fully using Time Machine, it all mounts properly but I get the aforementioned message popping up every now and then. And still the volume seems to spontaneously unmount when it’s been idle for a while.

    I’d appreciate any advice anyone could offer. I’m considering adding the command to restart avahi to cron on the Linux box, it seems to be the only way to remind the MacBook that the shared volume is there!

  26. Hutch

    Thanks for creating this. I just tried this with my 10.04 desktop and OSX 10.6.4. I followed the install instructions to the letter and did not have one problem.

  27. Nik

    Hi there!

    Thanks alot for the manual – now my xbmc box drives are on network %)

    I have one problem: I have a hfs+ 1Tb drive connected be ESATA to my Ubuntu 10.8 box. It is mounted to /media/TV-Shows.

    When I’m adding it to AFP share I can easily see it from my mac but I can not write any files to it – finder says I have no permissions, but I’m connecting to AFP share under the root of Ubuntu system.

    Anyone knows how to fix it?

    • Denmaru

      Linux cannot write to HFS+. Format it using ext3, and you should be fine.

      Alternatively, check your /etc/fstab.

    • Riccardo

      That’s not completely correct; linux can write non-journaled Hfs+ volumes.
      It is supported in the kernel, so I think no additional package must be installed, only hfsprogs if you need to format HFS+ partition in Gparted.

  28. mundo

    Can someone provide me the exact syntax to mount the TimeMachine volume, via terminal, on my Mac.

  29. op414

    For the firewall, you have to open ports 548 and 5353 in TCP AND UDP, INPUT and OUTPUT

    If, you use Iptables, add these lines :
    iptables -t filter -A INPUT -p tcp –dport 548 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp –dport 548 -j ACCEPT
    iptables -t filter -A INPUT -p tcp –dport 5353 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp –dport 5353 -j ACCEPT
    iptables -t filter -A INPUT -p udp –dport 548 -j ACCEPT
    iptables -t filter -A OUTPUT -p udp –dport 548 -j ACCEPT
    iptables -t filter -A INPUT -p udp –dport 5353 -j ACCEPT
    iptables -t filter -A OUTPUT -p udp –dport 5353 -j ACCEPT

  30. Return Privacy

    Hi, I am also trying to get Time Machine to backup my iMac to my Ubuntu 8.04 computer on the same network. What you suggest as a fix, is waaaay beyond my technical ability. All I know is my Ubuntu computer is running samba, and the imac sees it that way. Time Machine won’t backup to Ubuntu. Is there any way you could make this fix easier for us “non-genuises”? Like “Click Install this program on Ubuntu” and it would fix this Time Machine problem? I would personally be willing to pay a donation for a way to fix this.

  31. mundo

    Return Privacy: one more comment. The other part of this posting that I followed is the section describing how to create a TimeShare volume on your Ubuntu machine.

  32. Mike

    It seems with my latest Ubuntu 10.04 afpd/netatalk launches after avahi-daemon which screws things up. If I do a restart of avahi-daemon, everthing looks and works correctly.

    Since avahi-daemon is now an “upstart” job, I don’t see how to coordinate when it launches relative to when afpd/netatalk launch (which isn’t an upstart job).

    Any wisdom on how to coordinate these two daemons?

    • Ferdinánd

      i’m looking for a suliton for that too!

      btw the article is great, but you should make the netatalk install fully CLI like this:

      i’ve installed ubuntu without GUI, so i couldnt check that checkbox ;)

      sudo aptitude update
      mkdir -p ~/src/netatalk
      cd ~/src/netatalk
      sudo aptitude install cracklib2-dev libssl-dev
      apt-get source netatalk
      sudo apt-get build-dep netatalk
      cd netatalk-2.0.3
      sudo DEB_BUILD_OPTIONS=ssl dpkg-buildpackage -us -uc
      sudo debi
      echo “netatalk hold” | sudo dpkg –set-selections

  33. mildmanneredreporter

    Timemachine backup error

    I’ve used this HOWTO for years, and had my timemachine system running perfectly. And then, about a week ago, I didn’t. Timemachine simply stopped backing up and said 1) preparing disk…backup could not be found and then 2) keyring error -25299 on the second attempt to connect.

    I can see the disk in Finder, and look at the sparsebundle. It mounts on the desktop when I click it. I get the same behavior when I mount the target as an SMB share. I’ve moved the existing sparsebundle backup to another directory, recreated a new sparsebundle target and even fidgeted around with the plist fix detailed elsewhere. Netatalk and Avahi seem to be working perfectly, but Timemachine on 10.6.4 has gotten all prissy on me and won’t back up. At all. Anymore.

    Anybody else experiencing this? Have any solutions?

  34. alex gardiner

    Does anybody here know how to get netatalk running with network card bonding?

    I have a bond up and running. Avahi advertises the service over it too.

    But can I connect? Nope :(

    Any ideas very much appreciated :)

  35. mildmanneredreporter

    After exhausting every other solution, including alternate backups, I gave up and decided to go with the nuclear option: reinstalling Snow Leopard. I made three different copies of my Users directory, ran a TimeMachine backup onto a Firewire drive, then slipped in the DVD and reinstalled.

    Everything went smoothly. All my user data was retained on the mac’s hard drive, so I didn’t need to restore anything. I booted up Timemachine and got it running then used the Software Update to upgrade to 10.6.4. Miraculously, Timemachine is back working again, without any noticable errors.

    God help you if you get to that point.

    • waeking

      I am also in the same situation. I have been using this TimeMachine tutorial for years with now problems. After the 10.6.4 update I am getting a TimeMachine error. I have deleted the sparsebundle and recreated a new sparsebundle. This works for a while. I have just updated my macbook again, I have now got the same error again. I should have read the error better but something about TimeMachine integrety.

    • mildmanneredreporter

      With a nod toward waeking’s comments, attached nearby, I should also note that Timemachine seems to have again changed its naming convention. It is now using a backup database title of some sort for the sparsebundle naming convention, rather than a machine name or MAC address. I don’t know exactly what’s going on, but something is afoot with Timemachine and sparsebundle creation.

  36. Cosmo

    I stumbled onto this website because I noticed in my firewall section of preferences that there was something extra added. I generally have my firewall set to not allow any incoming connections. However I recently noticed that there was added a new line called VNCserver or something like that – it was set to “allow all incoming connections”. I googled “VNCserver” and found this page. I sometimes let “friends” use my computer. Well any way, is it possible that someone could have set this up without my knowing about it so that they can view what I’m doing from a remote location(s). It would seem that the answer is yes. Supposing that is true, how can I determine if this is in fact set up on my machine and, if so, how can I get rid of it?

    thanks

    • Joe

      VNC is enabled in OS X when you enable sharing in preferences>sharing, screen sharing.

      If your computer is in a private network, ie. 192.168.x.x IP address, then the likelyhood of someone outside your network accessing your computer is pretty small. That being said it is certainly not impossible.

      Take a look at the software called little snitch. This monitors outbound connections from your Mac, and alerts you every time such connections are made. It is really quite surprising how many connections your computer makes int he background every time you open an application, etc.

      This tutorial is very good, but a bit dated. I find that I no longer ned to enable network time machine access with 10.6.4, and with netatalk 2.0.5, time machine works pretty much right away.

      Currently I am using FreeNas to host my timemachine (TM) backups, and TM worked right away with no creation of the image, etc. I’m currently in the market for a standalone NAS, and it looks like many manufacturers, such as Thecus, Promise (Smartstor boxes), and Synology all support TM out of the box.

      Regards to all, -Joe

  37. Kris

    If you are running Ubuntu 10.04 or later its no longer required to build a custom package, also worth noting the following -uamlist uams_randnum.so,uams_dhx.so needs to be changed to -uamlist uams_randnum.so,uams_dhx2.so

    thanks for a great howto, this was very helpful

    • Ryan

      Thank you, thank you @Kris!

      I was trying to set this up again last nite and until I changed that to _dhx2.so nothing was working.

      & thank you to the author!

    • disturbedmaggot

      I’ve been trying for weeks to figure out why my mac wouldn’t connect. Turns out it was changing uams_dhx.so to uams_dhx2.so.

      Thanks so much for pointing this out!!

  38. robert+

    Firstly THANK YOU ALL.. I try it and its working.. but its really slow. copying file from mac to ubuntu is 1MB/s. I have ma internet faster! :) whats wrong? THANKs AGAIN for any help. CHeers

  39. Repollo

    Hi guys I just wanted to point out that netatalk 2.0.5 now supports TImeMachine Backups, so this means you just need to write “/home/username/TimeMachine TimeMachine allow:username1,username2 cnidscheme:cdb options:usedots,upriv,tm” for Leopard and SnowLeopard and “/home/username/TimeMachine TimeMachine allow:username1,username2 cnidscheme:cdb options:usedots,tm” for Tiger users.

    Anyways Cheers!

  40. Amos

    Hello. This is a great article, but after trying to make things work with netatalk and hitting metadata/character set issues when doing very Apply things (like trying to host my entire iTunes folder on Ubuntu), I finally gave up and looked for alternatives.

    If anyone else is in the same boat, I suggest using lvm2 in ubuntu to set up a logical volume (ideally on top of Linux RAID), then installing “iscsitarget” via apt-get and configuring it to offer up the volume as an iSCSI disk. On the OSX side, you install an iSCSI initiator (globalSAN iSCSI Initiator is free to use) and then the linux lvm will show up as a raw disk under OSX. All this means that you can then format it HFS+ and everything works. If you need multiple machines to connect, just share it from the Mac. I now have an 8TB linux software RAID5 array in the basement auto-mounted as a native HFS+ volume on a mini under the TV via Gb ethernet and iSCSI. The mini treats it like an HFS+ formatted external drive so everything is happy.

    See:

    http://www.howtoforge.com/using-iscsi-on-ubuntu-9.04-initiator-and-target

    http://www.studionetworksolutions.com/support/faq.php?pi=11&fi=51

    http://www.tldp.org/HOWTO/LVM-HOWTO/index.html

    https://raid.wiki.kernel.org/index.php/Linux_Raid

    Hope folks (and especially Matthias) find this useful.

    • aaron

      Alright Amos,

      You did exactly what I want to do. Can you explain your steps in detail for a Linux Ubuntu noob? Stuck on setting up LVM2.

  41. Josip

    Thx for great tutorial, it really helped me with installing netatalk on ubuntu 10.04, but finally Ubuntu is shipped with netatalk that works by default.

  42. mildmanneredreporter

    Sheesh. I just get all my other problems solved, I upgrade to Meerkat, and suddenly, I’ve got CNID DB problems. The Mac connects, but throws an error. /var/log/syslog says “cannot find module named [cdb] in registered module list!”, then says its using a “temporary CNID DB.” Deleted, then reinstalled netatalk, no soap. Error prevents unattended mounting by Mac, requires painstaking “verification” by Timemachine. I kept all my packages and confs during the upgrade, but no luck. Anybody else finding this?

    • Josip

      You just need to remove cnidscheme:cdb from config file. This worked for me.

  43. fennec

    Yes it’s ok if i remove cnidscheme:cdb

    but now i can’t share my /

    i have this error

    afpd[8385]: volume “Server” does not support Extended Attributes, using ea:ad instead

    i just see the folder, i can’t open folder he is empty

  44. Taz

    I get the same error after upgrading to Meerkat.. Anyone know how to fix this?

    • mildmanneredreporter

      Per the Netatalk release notes here: http://netatalk.sourceforge.net/2.1/ReleaseNotes2.1.4.html, you can change the cnidscheme to dbd (note caution on slower, more stable performance referenced in comments above) and it seems to start working again. I don’t think its a netatalk issue — it’s something Meerkat is doing, and the logfiles are very unhelpful.

    • Taz

      Thanks alot, Switching to dbd caused the error to go away.
      It is marginally slower, but definitely nothing to worry about.

  45. Steven Ball

    It would seem that netatalk 2.1 addresses the issues with the usedots option. I have installed 10.10 with netatalk 2.1 and following these instruction I keep getting invalid username.

    I had it working following your instructions under 10.4. I’m no expert with Ubuntu so some help would be much appreciated.

  46. Tim

    Thought I’d add a success story using ubuntu server 10.10 (mavrick).

    1a. don’t use cdb, use dbd for cnid:
    1b. use option not options
    1c. use perm option

    so to cover all of this –> put this line in /etc/netatalk/AppleVolumes.default:
    /var/TimeMachine TimeMachine allow:sue,tim,john perm:0777 cnidscheme:dbd option:usedots,upriv

    2. no need for all that mounting a sparse volume on your desktop.

    3. the version of netatalk thats in the ubuntu 10.10 repos will work with the latest version of snow leopard, older distros like karmic have an older netatalk that doesn’t work with newer snow leopard os. –> so use apt-get to install netatalk and avahi.

    4. i used the avahi xml file provided in this tutorial – thanks.

  47. Hai Tran

    Thanks for the nice tutorial! Didnt got it working immediatly. Got problems with logging in, so after looking through the comments #330 worked for me :D
    Using Ubuntu 10.04 on an old iBook

Have Your Say

Be nice, don't spam. You can just use Markdown. Code snippets should be wrapped in <code> tags. Everything in between gets automatically encoded to HTML entities, wrapped in pre tags and syntax highlighted.