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.

USE AT YOUR OWN RISK: I’m going to leave these instructions here but until hfsprogs, hfsutils, and hfsplus get updated to support journaling, this option will not work. I picked up a Mac Mini for $200 on eBay and I’m switching over. Good luck.

NOTE: On December 11th, 2019, this post was extensively updated.

NOTA BENE: (12/23/19) Since the last update I’ve run into an issue I don’t seem to be able to solve.

[NOT] RESOLVED: (1/11/2020) It looks like I fixed it. I was having reliability issues with the hard drive. It appears that the RPI can’t handle hard drives better than 3TB and mine was 6 so I partitioned it. Also discovered some better ways to do some things so I’m updating the instructions again.

NOT SO FAST: The RPI drivers must be 32 bit so the largest hard drive they can address is 3 TB. Got it. But, they do not support Mac OS Extended (Journaled) drives and that remains the problem. Time Machine will back up to them but from what I can tell, you can only use Time Machine once to restore from them and then the drive formatting gets scrambled. I tried using drivers from Paragon Software but they won’t run on the ARM architecture the RPI uses.

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 a 3 as well.

I found the instructions here. They are mostly right but now out dated so I’m going to summarize it, clean it up, and inject what I learned from my experience.

  1. I’m assuming you have your RPI up and running on your network and are ready to get Time Machine working. SSH into and let’s get it set up.
  2. Enter sudo apt-get update && sudo apt-get -y upgrade.
  3. We need netatalk to talk to Apple products over the network. Enter sudo apt-get install netatalk -y.
  4. It used to be that this would install an older version of netatalk but that has been up fixed. Verify you’re running the correct version by entering afpd -V (you don’t need sudo and that is a capital V). The first line after you enter that command should be something like: afpd 3.1.XX - Apple Filing Protocol (AFP) daemon of Netatalk
  5. Raspberry Pis can’t natively read Apple formatted disks so you’ll need to install software to allow them to. Enter sudo apt-get -y install hfsprogs hfsutils hfsplus to download and install them.
  6. Format your external hard drive. Plug it into the RPI and run sudo blkid to find it. You’ll need the address which looks like /dev/sdxy (where x and y are numbers depending on where you plugged it in). To format it run sudo mkfs.hfsplus -v Time\ Machine /dev/sdxy. This will format it as HFS+ which the Mac needs.
  7. You’ll need a directory to mount the external drive to. Create it by entering sudo mkdir -p /media/time_machine.
  8. We need to find the UUID of the drive so we mount the right one in the right place. Enter sudo blkid to list the devices. Find your drive in the list and copy the UUID. It is a bunch of numbers and letters between quotes, just copy the numbers and letters, not the quotes.
  9. To have Raspbian automatically mount it on boot, enter sudo nano /etc/fstab. There will already be a few entries in the file. Below them add the following all on one line:

    UUID="numbers and letters" hfsplus nofail,rw,user,auto 0 0

    No quotes around the numbers and letter!
  10. Enter sudo mount -a to mount the drive. It looks at the fstab file you just edited for what should be mounted where.
  11. Next, enter sudo chmod 777 /media/time_machine. This will set permissions on your external drive to drwxrwxrwx.
  12. To verify that the hard drive mounted correctly enter:
    cd /media/time_machine
    sudo touch test

    If that worked, there will be a file named test. That means we’re ready to continue. If you got a message that says the system is read only, you’ll need to troubleshoot that. Take a look at the bottom of this post for some tips.
  13. We need those programs that enable us to talk to Apple products to run every time the RPI boots so we’ll add those two commands to the linux version of autoexec.bat (for those old enough to remember MS-DOS.) Enter:
    sudo nano ~/.bashrc
    Add the following two lines to the end of the file:
    sudo service avahi-daemon start
    sudo service netatalk start
  14. To make sure that the RPI is visible to your Mac’s Time Machine, enter sudo nano /etc/nsswitch.conf and in that file, look for the line that starts with hosts: files mdns4_minimal. Add a space to the end of that line and add mdns4 mdns.
  15. Enter sudo nano /etc/avahi/services/afpd.service This will probably be a new, empty file. Add the following, where it says [Tab], don’t type it, just press Tab.

    [Tab] %h
    [Tab]
    [Tab] [Tab] _afpovertcp._tcp
    [Tab] [Tab] 548
    [Tab]
    [Tab]
    [Tab] [Tab] _device-info._tcp
    [Tab] [Tab] 0
    [Tab] [Tab] model=TimeCapsule
    [Tab]
  16. Enter sudo nano /etc/netatalk/afp.conf and under the [Global] heading, add mimic model = TimeCapsule6,106. Then add this to the end of the file:
    [Time Machine 6TB]
    path = /media/time_machine
    time machine = yes
  17. Enter sudo reboot. Give it a few minutes to come back up.

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 and the password. After that launch Time Machine preferences and select the disk. You should see Time Machine 6TB listed. Select that and let it Time Machine do its magic. This will take a while since this is an initial back up.

Troubleshooting

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. Make sure you’re using netatalk 3 or better. 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 is that if the Pi shuts down improperly, sometimes the external hard drive will mount as read only. Here’s how I’ve fixed it:

  1. SSH into the Pi.
  2. Unmount the drive using sudo umount /dev/sda2 (If you don’t remember the drive number, type mount and look for it.)
  3. Unplug the drive and plug it into your Mac.
  4. On the Mac, launch Disk Utility. Be patient. It tooks a moment before the drive shows because it is running a disk repair.
  5. Eject the disk and put it back on the RPI.
  6. Mount it with sudo mount -a
  7. 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.

It appears that if the Pi is using DHCP, when the IP address is refreshed, you’ll get a error because Time Machine can’t find the drive. If you connect, not via an IP address but using the host name of the RPI, that’s better. Otherwise, you should statically set the IP address of the RPI.

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

Print This Post Print This Post

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>