Friday 12 October 2012

AFP and Bonjour (ZEROCONF) installation on FreeBSD 9.0

Introduction

If you have a FreeBSD server and want to offer NAS functionality to Apple users here's how I achieved it the easy way.
No need for avahi. I don't like it because it depends on various X11 ports that I don't want to install.

HOWTO

I started out with a virgin installation of FreeBSD 9.0-RELEASE updated to RELEASE-p4 using freebsd-update. After that I built a custom kernel to exclude all the modules I don't need.
The ports that where installed before I started this project are:

$ portmaster -L
===>>> Root ports (No dependencies, not depended on)
===>>> libtool-2.4.2
===>>> portaudit-0.6.0
===>>> portmaster-3.14
===>>> 3 root ports

===>>> Trunk ports (No dependencies, are depended on)
===>>> autoconf-wrapper-20101119
===>>> automake-wrapper-20101119
===>>> ca_root_nss-3.13.6
===>>> db41-4.1.25_4
===>>> libiconv-1.14
===>>> m4-1.4.16_1,1
===>>> perl-5.12.4_4
===>>> ruby-1.8.7.370,1
===>>> 8 trunk ports

===>>> Branch ports (Have dependencies, are depended on)
===>>> autoconf-2.69
===>>> gettext-0.18.1.1
===>>> p5-Locale-gettext-1.05_3
===>>> ruby18-bdb-0.6.6
===>>> 4 branch ports

===>>> Leaf ports (Have dependencies, not depended on)
===>>> automake-1.12.4
===>>> curl-7.24.0_1
===>>> gmake-3.82_1
===>>> help2man-1.40.12
===>>> portupgrade-2.4.9.9,2
===>>> sudo-1.8.6.p3_1
===>>> 6 leaf ports


I started by installing the howl port. I use portmaster:


# portmaster net/howl

Then I created the mDNSResponder.conf file and added the services I need:
# edit /usr/local/etc/mDNSResponder.conf:
#name         #type                   #domain  #port  #text
gluon         _afpovertcp._tcp        local.   548
gluon         _ssh._tcp               local.   22
gluon         _device-info._tcp       local.   0      "model=RackMac"

My server is called gluon. You'll need to change that to your server's name.
The last line in the configuration file makes the server show up as an Apple Xserve in OSX' Finder window. Other Apple models are available see the references below. 

Next, I prep-ed the rc.conf file for things to come:

# edit /etc/rc.conf
netatalk_enable="YES"
cnid_metad_enable="YES"
afpd_enable="YES"

mdnsresponder_enable="YES"
mdnsresponder_flags="-f /usr/local/etc/mDNSResponder.conf"

After that I installed netatalk:

# portmaster net/netatalk
I kept all the default options, but I switched off the ZEROCONF option, because it wants to install all kinds of stuff I don't want.

In netatalk.conf make sure the below 4 options are uncommented. The rest either aren't needed or the defaults seem to work fine.

# edit /usr/local/etc/netatalk.conf
CNID_METAD_RUN=yes
AFPD_RUN=yes
AFPD_MAX_CLIENTS=20
AFPD_UAMLIST="-U uams_dhx.so,uams_dhx2.so"

# edit /usr/local/etc/afpd.conf
-transall
-adminauthuser admin
-signature auto
-uamlist uams_dhx2.so
-setuplog "default log_info /var/log/afpd.log"
-mimicmodel Xserve

The -mimicmodel option doesn't seem to work in my set-up, but I kept it in (and synced with the setting in mDNSResponder.conf) just to be sure.
I've added the user admin as the adminauthuser. This allows me to authenticate other users with the admin password (useful for troubleshooting).

Finally, you may want to edit /usr/local/etc/AppleVolumes.default to add any shares you need. I've found that the defaults will do for starters.

I rebooted and found the Finder window to show the server.

What's next?

Now, all Apple computers on the network can see the server gluon, but any Windows 7 computer will ignore it even though they have Bonjour installed. Also, when I log into the server I can't ping any computer by it's Bonjour-name.
So, there's still some work to be done.

References: