Using Raspberry Pi as an Apple TimeMachine
Backups are life-saving, so macOS has Time Machine service for years now. Apple even produces special TimeCapsule — device that is connected to your local network and provides storage to all macs to put their backups to. This is a story how to make your Raspberry Pi with external hard drive behave as a AirCapsule in your network.
Set up your Pi
First, download Raspbian OS image to your mac:
Mount it to the microSD card you want to use in Pi with Etcher utility:
Insert card into Pi, connect it to TV, electricity, Ethernet and USB mouse in order to boot and enable SSH in Settings.
Connect to it from your computer via SSH at pi@192.168.XX.XX with default password raspberry. Don’t forget to change password to something stronger with passwd
command.
[optional] Virtual Keyboard on Raspbian
I did not have USB keyboard to use with Pi, so next step was to install virtual keyboard:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install matchbox-keyboard
$ sudo reboot
And switch the keyboard on in Pi’s Settings.
Now you can plug in WiFi dongle and connect to your network via GUI using virtual keyboard to enter password. I’ve tried to setup SSID and password via Terminal directly in config files, but fucked up the settings and Raspbian refused to boot in normal mode, suggesting to press ENTER for emergency loading… which was kind of difficult without real USB keyboard.
Mount the HDD
Install tool for reading Apple drives:
$ sudo apt-get install hfsprogs hfsplus
Connect your external HDD. Run sudo /sbin/parted
tool and type print command to see the list of connected drives:
Create new directory to mount drive into:
$ sudo mkdir -p /media/tm
Edit /etc/fstab file replacing /dev/sda
line with following:
/dev/sdaX /media/tm hfsplus force,rw,user,auto 0 0
and running sudo mount -a
to mount the drive. My drive was mounted automatically, tho.
Building Apple Netatalk
We’re going to build Netatalk from sources, so first we have to install all the dependencies from default apt-get repository called Stretch:
$ sudo aptitude install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev
However, libmysqlclient-deb
is no longer there, so we’ll need to switch to another repository — Jessie:
- replace
stretch
withjessie
in/etc/apt/sources.list
file - update list of approachable libs by running
sudo apt-get update
$ sudo aptitude install build-essential libmysqlclient-dev
to install the dependency- and then switch back to Stretch by reverting steps 1 and 2
Now we are ready to obtain current version of Netatalk sources from the official page:
$ wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.11.tar.gz$ tar -xf netatalk-3.1.10.tar.gz
Magic configuration follows:
$ ./configure \
--with-init-style=debian-systemd \
--without-libevent \
--without-tdb \
--with-cracklib \
--enable-krbV-uam \
--with-pam-confdir=/etc/pam.d \
--with-dbus-daemon=/usr/bin/dbus-daemon \
--with-dbus-sysconf-dir=/etc/dbus-1/system.d \
--with-tracker-pkgconfig-version=1.0
And then is the time to pray:
$ make
$ sudo make install
… and then, if $ netatalk -V
shows something meaningful, open Schampaine 🍾
Configure Netatalk
First, tell it to share the drive by adding mdns4 and mdns to /etc/nsswitch.conf
in the end of hosts: section. Now the drive will appear in Finder while your Pi is conncted to network.
Then post following block into /etc/avahi/services/afpd.service
so Pi will pretend it is real Time Capsule:
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=TimeCapsule</txt-record>
</service>
</service-group>
Paste following into /usr/local/etc/afp.conf
so Pi will appear as shared in local network:
[Global]
mimic model = TimeCapsule6,106
[Time Machine]
path = /media/tm
time machine = yes
Add two daemons to autolaunch:
sudo systemctl enable avahi-daemon
sudo systemctl enable netatalk
And start them by hand for the first time:
sudo service avahi-daemon start
sudo service netatalk start
If everything was ok, you should be able to see your Pi in mac’s Finder:
Use the Time Machine from the mac
Just push that Connect As… button in Finder, open your mac’s System Preferences>Time Machine and select the drive.
— Taaaaa-da-da-da-daaaaaaam! 📯