Speed up shares for OS X with custom made Netatalk .deb package

With the release of OS X 10.7 Apple decided to develop their own version of the SMB-protocol, called SMBX. This resulted in compability problems, as accessing a Network Share, from a computer running OS X 10.7 or newer, that wasn’t hosted by a server running OS X Server, turned out to be really slow. And since it was believed that Apple’s AFP-protocol was deprecated, the only solutions were to either get a server running OS X Server or getting a third-party File Manager – any other than the OS X default, Finder.
However, it turns out that the AFP-protocol is in fact still available, and as such we’ve found the ideal available solution is to use Netatalk.
Unfortunately, as of writing this article, the latest version of Netatalk (3.1.7) isn’t available as a package, but would have to be compiled from source.
Fortunately, we have created this guide for how to put together a .deb-package from the source for Debian Wheezy 7.8, install Netatalk using our own Netatalk.deb-package and how to configure Netatalk in afp.conf.

Creating the Netatalk.deb
First of all, download all the dependencies for Netatalk.
You’ll also need to find out which version is available for the tracker sparql/miner and download accordingly. We used version 0.14.

# aptitude search tracker
# apt-get install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev tracker libtracker-sparql-0.14-dev libtracker-miner-0.14-dev

Download the required tools for making the .deb-package.

# apt-get install dh-make autotools-dev devscripts

Download the tarball for Netatalk 3.1.7.
I recommend doing so in an empty workplace.

# wget http://sourceforge.net/projects/netatalk/files/netatalk/3.1.7/netatalk-3.1.7.tar.gz

Untar the tarball. DO NOT remove the tarball when you’re done. It’s needed later.

# tar xvf netatalk-3.1.7.tar.gz
# cd netatalk-3.1.7

Run dh_make to initiate the creation of the .deb-package, pointing at the tarball that you DIDN’T REMOVE.

# dh_make -f ../netatalk-3.1.7.tar.gz

Edit debian/control and add all the depencies we previously downloaded, except for build-essentials, at the place that read ”dependencies”. Each package is seperated by comma-space.

# vim debian/control
 Source: netatalk
 Section: unknown
 Priority: extra
 Maintainer: root <root@debian>
 Build-Depends: debhelper (>= 8.0.0), autotools-dev, libevent-dev, libssl-dev, libgcrypt11-dev, libkrb5-dev, libpam0g-dev, libwrap0-dev, libdb-dev, libtdb-dev, libmysqlclient-dev, libavahi-client-dev, libacl1-dev, libldap2-dev, libcrack2-dev, systemtap-sdt-dev, libdbus-1-dev, libdbus-glib-1-dev, libglib2.0-dev, tracker, libtracker-sparql-0.14-dev, libtracker-miner-0.14-dev
 Standards-Version: 3.9.3
 Homepage: <insert the upstream URL, if relevant>
 #Vcs-Git: git://git.debian.org/collab-maint/netatalk.git
 #Vcs-Browser: http://git.debian.org/?p=collab-maint/netatalk.git;a=summary

 Package: netatalk
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}, libevent-dev, libssl-dev, libgcrypt11-dev, libkrb5-dev, libpam0g-dev, libwrap0-dev, libdb-dev, libtdb-dev, libmysqlclient-dev, libavahi-client-dev, libacl1-dev, libldap2-dev, libcrack2-dev, systemtap-sdt-dev, libdbus-1-dev, libdbus-glib-1-dev, libglib2.0-dev, tracker, libtracker-sparql-0.14-dev, libtracker-miner-0.14-dev
 Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>
	 

Run debuild while still located in Netatalk-3.1.7/. Afterwards you can run lesspipe on the newly created Netatalk.deb-package and make sure that a lot of paths show. You’ll know when too few show, in which case you’ve done something wrong.

# debuild
# lesspipe ../netatalk_3.1.7-1_amd64.deb

You should now have a functional Netatalk installation package.
NOTE: When you install using this package you won’t get an init-script. To get that I had to first install a Netatalk by compiling the source. You can just copy the script we use:

#!/bin/sh
### BEGIN INIT INFO
# Provides: netatalk
# Required-Start: $remote_fs $syslog
# Should-Start: avahi-daemon
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
#
# netatalk Netatalk 3.1.7 initscript
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Netatalk"
NAME=netatalk
SCRIPTNAME=/etc/init.d/$NAME

# Guard to prevent execution if netatalk was removed.
test -x /usr/sbin/netatalk || exit 0

# Start Netatalk servers.
netatalk_startup() {
if [ -x /usr/sbin/netatalk ] ; then
/usr/sbin/netatalk
echo -n " netatalk"
fi

}

case "$1" in
start)
echo -n "Starting Netatalk services: "
netatalk_startup
echo "."
;;

stop)
echo -n "Stopping Netatalk Daemons:"
echo -n " netatalk"
start-stop-daemon --stop --quiet --oknodo --exec /usr/sbin/netatalk

echo "."
;;

restart)
$0 force-reload
;;

force-reload)
echo -n "Restarting Netatalk Daemons"
$0 stop
echo -n "."
sleep 2
echo -n "."
if $0 start; then
echo "done."
fi
;;

*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

Copy that text and put it into /etc/init.d/netatalk

Or follow this guide:
http://netatalk.sourceforge.net/wiki/index.php/Install_Netatalk_3.1.7_on_Debian_7_Wheezy

If you do decide to follow the guide you’ll have to edit the script so that it points to where your Netatalk is installed. To do that I edited the file so that it pointed at /usr/sbin/netatalk and /usr/bin/netatalk instead of /usr/local/sbin/netatalk and /usr/local/bin/netatalk at all places except the DIST-var.

Installing Netatalk using our Netatalk.deb
You install the package like you do with any .deb-package.

# dpkg -i netatalk_3.1.7-1_amd64.deb

However, the first time you do it, the dependencies won’t install, so we’ll install them. When you do that it’ll automatically uninstall Netatalk again, so you’ll have to install it again.

# apt-get -f install
# dpkg -i netatalk_3.1.7-1_amd64.deb

You might also want to install Avahi-daemon, which automatically announces your Netatalk shares on the network. This allows for users to connect to your share without having to insert the IP to the server.

# apt-get install avahi-daemon

Make sure that /etc/afp.conf doesn’t have a funny name (it shouldn’t, but it did in one version, so just make sure it doesn’t.)

# ls /etc/afp.conf

Place the init-script in /etc/init.d/, edit your afp.conf to share a directory (We’ll show you how further down) and start up Avahi-daemon and Netatalk.

# /etc/init.d/avahi-daemon start
# /etc/init.d/netatalk start

You may also want to make sure that these start up automatically if you reboot your system. Be careful when doing this, as it’s possible to leave your system unbootable if you do something wrong, using insserv.

# insserv avahi-daemon
# insserv netatalk

Now you can connect to the share from a computer running OS X. In the Host-field you write
afp://<ip.to.netatalk.host>/
Or if you’re running Avahi-daemon, you can just click on the Share in the list.
Then you’ll be prompted to log in with a user available on the Server.
To add a user, you just add a user like usual.

# adduser username

Configuration of afp.conf
A simple share configuration can look like this:

[Global]
[Shared]
path = /srv/shared
file perm = 0664
directory perm = 0775

This configuration creates a share called Share which shares the directory /srv/shared/ and automatically sets the Owner and the Group of any file/directory created to whatever coresponds to the user used when connectng to the share, as well as putting 664 permissions on new files and 775 permissions on new directories.
If you would want more options you can check out all available options here:
http://netatalk.sourceforge.net/3.1/htmldocs/afp.conf.5.html

Troubleshooting
Make sure your afp.conf is configured correctly. If it isn’t, your client won’t be able to connect. Make sure to restart Netatalk when you make changes to afp.conf.

Make sure Netatalk is started and that port 548 is open.

# /etc/init.d/netatalk restart
# netstat -tulpan | grep 548

If your share isn’t automatically listed using Avahi-daemon, make sure that you start Netatalk after starting up Avahi-daemon.

You can download our package of Netatalk 3.1.7 for Debian Wheezy 7.8 amd64 at:
http://github.com/patrik-nilsson/Netatalk-deb-package