Use a Raspberry Pi 4 for Time Machine (works with macOS 11 Big Sur)
Time Machine is built into the system of macOS and I’m using it since the early days of Mac OS X Leopard. If you have a Raspberry Pi (or two) lying around at your place like me, this tutorial comes in handy to create a cheap and speedy backup solution.
Update system software
Make sure your Raspberry Pi is running on the latest software.
sudo apt-get update && sudo apt-get upgrade
We’re going to first install Samba (for SMB) which is a very popular Open Source file sharing protocol which is officially supported by Time Machine for backing up data over a network. The Avahi daemon is used for Apples “Bonjour” mDNS protocol that our Raspberry Pi server is automatically discoverable within the network.
sudo apt-get install samba avahi-daemon
Connect Hard drive to USB 3.0 port
As the Raspberry Pi 4 ships with 2x USB 3.0 ports we can connect an external hard drive as our disk space for backing up data. Also we should get decent speeds as we also get a 1GBit/s wired connection with the Pi 4.
Determine the device ID (UUID) of your USB drive
ls -lha /dev/disk/by-uuid
In my case the device was /dev/sdb1 and the UUID we’re looking for was the one below:
Note: exchange this UUID with yours
Create backup user
sudo adduser timemachine
It will ask to set a password for your newly created user.
Set a password
sudo smbpasswd -a timemachine
Create mount point
In order to mount the USB hard drive we need to create a folder where Linux can mount our device to.
sudo mkdir /mnt/timemachine
We’ll now mount the USB drive to the previously created mount point.
sudo mount /dev/sdb1 /mnt/timemachine
Note that you’ll need to exchange /dev/sdb1 with your device (see the Step with the the UUID above which letter your device uses)
To allow our backup user to write on the device we’ll need to take over the ownership of the mount point:
sudo chown -R timemachine: /mnt/timemachine
Edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
add the following to the end:
comment = Backups
path = /mnt/timemachine
valid users = timemachine
read only = no
vfs objects = catia fruit streams_xattr
fruit:time machine = yes
This will create a network drive called “backups” which we’ll use for Time Machine.
Test Samba configuration
sudo testparm -s
Not let’s restart the service to make sure our changes are active.
sudo service smbd reload
Test connection to your Time Machine
On your Mac press “Command + K” on your desktop which will open the “Connect to Server” prompt. Type in the IP Address of your Pi followed by the /backups to connect to our Time Machine volume.
Now you should be connected to your Time Machine volume.
Configuring Avahi deamon
In order to let MacOS automatically detect our new Time Machine we’ll need to configure Avahi. For that edit the following file:
sudo nano /etc/avahi/services/samba.service
And paste this configuration in:
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
With this we tell MacOS that in fact our Raspberry Pi is a 8th Gen Time Capsule and it will appear like one in the sidebar in Finder.
Restart Avahi daemon:
sudo service avahi-daemon restart
Automated mount on boot
We need to tell fstab that it mounts our hard drive to the Raspberry Pi.
sudo nano /etc/fstab
We need to append the UUID from above like this:
UUID=7efbdfc5–9c85–4e01–873a-204e00c9aa45 /mnt/timemachine ext4 sync,noexec,nodev,noatime,nodiratime 0 0
Automated start of the services
We need to edit crontab with:
sudo crontab -e
We’ll mount the USB drive and start the needed services on a boot/reboot:
@reboot sleep 30 && mount /mnt/timemachine && sleep 30 && umount /mnt/timemachine && sleep 30 && mount /mnt/timemachine && sleep 30 && service avahi-daemon start && service smbd start
Setup Time Machine
The first step is to choose our “backups” volume. For that open the Time Machine settings and you’ll find it under “Available disks”:
Use your password
Use your password to connect to the Raspberry Pi Time Machine volume:
and we’re done! Happy backuping!
This guide was inspired by the following guides:
Raspberry Pi Time Machine (2020 update)
2019-01-02 Updated after comments from Guy 2019-07-21 Updated after comments from Bastiaan 2019-12-14 Updated after…