Raspberry Pi as Apple Time Capsule

Apple’s Time Machine is great. Their Time Capsule network accessible storage is too expensive. The Raspberry Pi can help with that.

I’ll skip the obvious stuff about having to own a Raspberry Pi and external hard drive and how to set up the Pi since the first two should be obvious and the third you can find 1,000 other places. Instead I’ll just cut to the chase. This worked for me on a Raspberry Pi 2 and so it should work on a 3 as well.

I found the instructions here. They are mostly right but the formatting is a little inconsistent and I thought some of the steps were out of order so I’m going to summarize it, clean it up, and inject what I learned from my experience. Instructions after the fold.

1. Format your external hard drive. I tried to use the one I had already Time Machine back ups on but it caused me a lot of headaches till I was forced to format it. It has to be formatted as Mac OS Extended (Journaled) and you can only do that on your Mac. Name it Time Machine. BTW, this disk format is also known as HFS+.

2. After you’ve formatted the drive, open the terminal on your Mac and enter sudo chmod 777 /Volumes/Time\ Machine && ls -l /Volumes. This will set permissions on your external drive to drwxrwxrwx.

3. You did do sudo apt-get update && sudo apt-get upgrade after you used NOOBS to install Raspian, right? I found the “&&” trick helpful because you have to do both of these steps.

4. On your Pi make sure you enable SSH. Wisely, it comes disabled by default these days. It is in the Raspberry Pi Configuration app under Preferences in the Pi menu. Also, I would suggest changing the password for user pi at this point so you don’t have to fuss with it later on both your Pi and your Mac.

5. On the Pi, launch the terminal and enter ifconfig to find the IP address of the Pi. It should be 192.168.something.something

6. We need to get some software that lets the Pi use Apple’s file sharing protocol AFP. We’re not going to use it just yet but it is easiest to get it now. Launch the Pi’s web browser and go to netatalk.sourceforge.net. Download the latest stable version from the “current releases” box on the left. When I did this at the end of 2016 the current stable version was 3.1.10 and I got the gzip file. Download it to your Downloads folder.

7. Unzip it in the downloads folder and just leave it there for now.

8. At this point you can plug your external hard drive into your Pi, unplug the HDMI cable and move the Pi to its permanent home. The rest of the work you’ll be doing can be done via ssh.

9. SSH into your Pi from the terminal on your Mac. The format is pi@192.168.XXX.XXX (the XXXs being the rest of the Pi’s IP address, of course). You’ll be prompted for the password which you hopefully changed back in step 4.

10. Raspberry Pis can’t natively read Apple formatted disks so you’ll need to install software to allow them to. Enter sudo apt-get –assume-yes install hfsprogs hfsutils hfsplus to download and install them.

11. We need to know where that external drive is mounted. Enter sudo /sbin/parted which will launch the parted tool. At the command prompt “(parted)”enter print to get a list of mounted drives and some info about them. Most likely, 1 will be the SD card and 2 will be the external drive. Just make sure. Enter quit.

12. You’ll need a directory to mount the external drive to. Create it by entering sudo mkdir -p /media/time_machine.

13. Now we need to have Raspbian automatically mount it on boot so enter sudo nano /etc/fstab. Nano is a text editor that you’ll use often in this procedure. There will already be a few entries in the file. Below them, but above the lines with #, add the following. NOTE: If you found your external drive mounted anywhere other than 2 in step 11 change the number after sda to it.

/dev/sda2 /media/time_machine hfsplus force,rw,user,auto 0 0

Press ctrl+O then hit return to write your changes, then press ctrl+X to exit Nano. Remember these commands, you’ll use them again.

14. Enter sudo mount -a to mount the drive. It looks at the fstab file you just edited for what should be mounted where.

15. Okay, not it gets a bit tedious. You’ll need to install all of the “Required Packages” listed here. One. At. A. Time. (This should redirect you to the list for the most current, stable build. If not, you may need to do some research on that site.)

I found the easiest way to do this and keep it all straight was to copy and paste sudo apt-get –assume-yes install followed by a space into the terminal window then copy the first package name and paste it after that then hit enter. NOTE: Copy ONLY the package name, not the notes in parenthesis after them. Once it starts installing, go back to your browser and copy the next package name. Then back to the terminal. Once it finishes installing, hit the up arrow to recall the last command entered, delete the package name at the end of the line and paste the new one. Once it starts, copy the next package. Repeat till you’re done.

16. Okay, now we need to build that latest version of netatalk. Enter cd /home/pi/Downloads/netatalk-XXXX where XXXX is the version of netatalk you downloaded.

17. Enter the following all together, it is one command. I had a problem and had to delete –withpam-confdir=/etc/pam.d to get it to run. /etc/pam.d is the default location so there really isn’t a need to tell it where it is.

./configure --with-init-style=debian-systemd --without-libevent --without-tdb--with-cracklib --enable-krbV-uam --withpam-confdir=/etc/pam.d --with-dbussysconf-dir=/etc/dbus-1/system.d --with-tracker-pkgconfig-version=1.0

This takes a while to run. Be patient.

18. Once it completes, enter sudo make.

19. Once that completes, enter sudo make install.

20. Hopefully all went well and netatalk is now installed on your Pi. To check, enter afpd -V (you don’t need to sudo it and that is a capital V). The first line after you enter that command should be something like:

afpd 3.1.10 – Apple Filing Protocol (AFP) daemon of Netatalk

21. We need to run this program every time the Pi boots so you’ll need to add those two commands to the linux version of autoexec.bat (for those old enough to remember MS-DOS.) Enter sudo nano ../.bashrc and addsudo service avahi-daemon start and sudo service netatalk start on two lines at the bottom of the file. Save and exit.

Next, we need to make sure that the Raspberry Pi is visible to your Mac’s Time Machine.

22.Enter sudo nano /etc/nsswitch.conf and look for the line that starts hosts: files mdns4_minimal. Add a space to the end of that line and add mdns4 mdns. Save changes and quit.

23. Enter sudo nano /etc/avahi/services/afpd.service and enter the following. This will probably be a new, empty file. Where it says [Tab], don’t type it, just press Tab.

[Tab] %h


[Tab] [Tab] _afpovertcp._tcp

[Tab] [Tab] 548



[Tab] [Tab] _device-info._tcp

[Tab] [Tab] 0 (Don’t type this part but that is a zero)

[Tab] [Tab] model=TimeCapsule


24. Enter sudo nano /usr/local/etc/afp.conf and under [Global] add mimic model = TimeCapsule6,106. Then add this to the end of the file:

[Time Machine 3TB]

path = /media/time_machine

time machine = yes

25. Save and quit then reboot your Pi. To reboot enter sudo reboot. Give it a few minutes to come back up.

26. If everything worked, you should see your Raspberry Pi in the Finder under Shared in the left column. Go ahead and connect to it with your Raspberry Pi username pi and the password. After that launch Time Machine preferences and select the disk. You should see Time Machine 3TB listed. Select that and let it Time Machine do its magic. This will take a while since this is an initial back up.


I had a few hiccups along the way and here’s what I learned.

In the past when I tried to do this, I was using an outdated version of netatalk which could be installed with apt-get or downloaded via git from github. Don’t bother. You have to use netatalk 3 as listed above. If you use the outdated version, you’ll get an error in Time Machine about sparesebundle and it will have error(null) which is not at all helpful.

Something I have encountered and honestly it makes me a bit nervous is that if the Pi shuts down sometimes the external hard drive will mount as read only.When it did I got that sparsebudle error message but it threw error 30. When it did, here’s how I’ve fixed it:

  1. SSH into the Pi.
  2. Unmount the drive sudo umount /dev/sda2 (or whatever your drive number is).
  3. Unplug the drive and plug it into your Mac.
  4. On the Mac, launch Disk Utility. Be patient. It took a moment before the drive showed up for me.
  5. Run First Aid on the disk.
  6. Eject the disk and put it back on the Pi
  7. Mount it with sudo mount -a
  8. Try it again.

If you have to format your external hard drive because it became corrupted, plug it into your Mac and do the initial Time Machine back up. After that, don’t forget to run sudo chmod 777 /Volumes/Time\ Machine && ls -l /Volumes in the terminal to change the permissions. If you don’t Time Machine won’t be able to use the drive.

ADDED: It appears that if the Pi is using DHCP, when the IP address is refreshed, you’ll get a sparsebundle 30 error again. I did and I followed the steps above, rebooted the Pi with the new address, and it worked. Again. If I can verify it again after the next DHCP renewal, I’ll update this post.

Honestly, format your external hard drive before you try to use it. I wanted to preserve the back ups I had so I tried to just use the drive and it kept giving me a lot of problems. It might be that I missed chmod from step 2 above but I doubt it. It had to get to the point where my Mac couldn’t read the drive that forced me to format it so that I could move forward.

I used a Raspberry Pi 2 I had sitting around with 16GB SD card. I think an 8 or 4 GB would have been fine but that’s what I had. Also, I used my 2 for this project because I have it sitting on the shelf right next to my router so an ethernet cable isn’t a problem. If a 2 is cheaper, it isn’t a bad way to go.

In step 24 above, we named the drive Time Machine 3TB but you can name it whatever by changing that line. This is just the title and doesn’t fix the size to 3TB.

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>