Raspberry Pi, Raspbian, HFS+, AFP and Time Machine

Since getting my Raspberry Pi I have installed a few different operating systems and had a good little mess about.  One great use I have found for it is plugging in external drives and utilising it as a Time Machine / Time Capsule backup device for my Mac’s.  At such a low price point with a 2Tb drive you can have a working time capsule for under £100! Certainly an attractice prospect for backups!

(This little HOWTO assumes you are running Raspbian)

There are a few steps you need to take in order to get this working, as you will need the Raspberry Pi to support HFS+ as well as running AFP to enable Time Machine.

HFS+

To enable HFS+ you should install the following

sudo apt-get install hfsplus hfsutils hfsprogs

This will install the necessary packages to mount the HFS+ formatted drive.

Getting the drive to mount as read/write can be achieved by the following command

mount -o force /dev/sdx /mnt/blabla

 It is also worth noting that if the drive appears as sdb the actual data on the partition will be one higher so sdb1.

If the drive doesn’t mount try running a fsck

fsck.hfsplus -f /dev/sdaX (change X to your appropriate drive)

Hopefully this should see your HFS+ drive mounted under raspbian.  Now all we need to do is share the drive over AFP and enable Time Machine.

AFP + Time Machine

We need to install a few packages before we can move onto installing AFP support, as netatalk requires a DB as well as encryption.

sudo apt-get install avahi-daemon libavahi-client-dev libdb5.3-dev db-util db5.3-util libgcrypt11 libgcrypt11-dev

Once all dependencies are installed download the latest source code of netatalk (At the time of this HOWTO it was Netatalk 3.0).  After unzipping build with the following commands

./configure --with-init-style=debian --with-zeroconf

make

make install

Now we should have a working install of netatalk which gives us AFP support for the drives we mounted using HFS+.  All that is left is to configure afp.conf and start netatalk as a service.

afp.conf is located in /user/local/etc/

Open this file and edit as appropriate by following the instructions at netatalk.  However for a simple get started setup the following will give you a drive shared to be used as a Time Machine backup.

[Global]
; Global server settings
uam list = uams_guest.so

[Time Machine Raspberry]

path = /mnt/test
time machine = yes

With everything configured all that is left to do is run netatalk and your Time Machine backup will appear in the finder under OS X.

This is a very rough guide on how to get everything running under raspbian but hopefully it will providers a jumping off point for further research in order to fine tune the setup to exactly how you want it.

17 thoughts on “Raspberry Pi, Raspbian, HFS+, AFP and Time Machine

  1. For anyone using some copy & paste to get this done…

    The first dashes in the configure line
    ./configure –with-init-style=debian –with-zeroconf
    break the configure command, make sure you change them to actual dashes.

    There is also a few ‘Machone’ typos.

    Anyway, thanks for the info.

  2. Thanks,
    This is very helpful. The other examples around on the interwebs in seem to use Netatalk 2.x. Version 3.x has tidied up the config files and removed the need for ‘defaults write allowNetworkTimeMachine’ on the client, it’s great to see another way to do it.

    You may want to steal the avahi service XML from http://buffalo.nas-central.org/wiki/Time_Machine_&_Time_Capsule_support_on_your_LinkStation

    It turns the Pi into a Time Capsule in the Finder sidebar. I think I prefer “model=Xserve” more 🙂

  3. The majority of the information I found on the net was for Netatalk 2.x thats why I decided to write this.

    I am certainly no expert when it comes to Linux so I just threw this together giving a few pointers for people to add on to.

    That XML file is a nice addition, cheers!

  4. I followed this guide and it worked for me with a few changes:

    My afp.conf is located in /usr/local/etc and I changed it to this:
    ;
    ; Netatalk 3.x configuration file
    ;

    [Global]
    ; Global server settings
    uam list = uams_guest.so, uams_dhx.so, uams_dhx2.so,

    [Time Machine Raspberry]

    path = /media/250GB
    time machine = yes

    I created a new user on my RPi named “timemachine” and ran the command “sudo chown timemachine /media/250GB” .

    I edited /etc/avahi/services/afpd.service based on http://www.ubuntugeek.com/getting-timemachine-to-work-under-ubuntu-10-04-lts-os-x-lion.html (which looks like droid’s) to be:

    %h

    _afpovertcp._tcp
    548

    _device-info._tcp
    0
    model=Xserve

    Now I need to get the drive to mount automatically on start up and make sure Netatalk is also doing the same. This took me two days to get working due to my own errors and general lack of knowledge so I may have done something else and forgotten about it or not needed to make one or more of my changes 🙂 Thanks for writing this up!

  5. Thanks for the post;

    Ive been unable to write to my usb drive and would love some help. Running most current raspbian release. Drive is formatted mac os extended. Have installed the recommended packages. Using your force mount able to mount drive which I can see when I run df -h from command line. When I go to my Mac and attempt to copy a file to directory where my drive is mounted, after mac finder asks for my mac username and password I get an error message saying “The operation can’t be completed because you don’t have permission to access some of the items.”

    I’ve rebooted the ras pi, unmounted and remounted drive. Any suggestions would be appreciated. Thanks.

  6. Joel,
    See if you can create a file in the mounted disk when logged in via ssh. I suspect it’s the permissions on the disk. It could be that the user you are logging in with AFP doesn’t have write permissions.

    I think I did…
    sudo mkdir -m 777 /media/DISK
    sudo chown pi:pi /media/DISK
    to make Pi the owner of the directory.

    I’m unsure if it would be cleaner to set it in fstab so the disk is mounted for the correct user.

    The AFP permissions would be set in the afp.conf, but I think the [Time machine] option takes care of that (man afp.conf).

  7. Thanks for the instructions. Just spend most of the evening trying to get it working with 3.0.1 (latest at moment) but could not connect at all.

    Removed netatalk and re-tried using 3.0 and works fine now! Not sure where the problem lies with 3.0.1, maybe a subtle config setting change?

  8. Remember a newline in the end of afp.conf

    I was setting up netatalk with two Raspberry Pis. One worked, one didn’t. The second simply didn’t show up on my Mac. Found out that pressing enter after “time machine = yes” made all the difference.

    Restart the service with “sudo service netatalk restart”

    Thanks all!

  9. Hi,

    Strangely, my external USB Drive (MBR, 1 partition, HFS+) is mounted automatically in read only following the steps above, and I can not remount it read write. Any idea ?

    pi@raspbmc:~$ sudo mount
    /dev/mmcblk0p2 on / type ext4 (rw,noatime)
    proc on /proc type proc (rw)
    devpts on /dev/pts type devpts (rw,noexec,nosuid,relatime,gid=5,mode=620)
    /dev/mmcblk0p1 on /boot type vfat (rw)
    /dev/sda1 on /media/TimeCapsule type hfsplus (ro,nosuid,nodev,uhelper=udisks)
    pi@raspbmc:~$ sudo mount -n -o remount,rw /media/TimeCapsule
    mount: /media/TimeCapsule not mounted or bad option

Leave a Reply

Your email address will not be published. Required fields are marked *