Linux as your Time Machine for mac
Arsenii Kharlanow
Posted on July 25, 2022
Do you have an old laptop or do you have a raspberry pi? If yes, it is for you.
One day I found that my mac doesn't boot, and I realized that I didn't save my last work. After a few hours of trying to restore my mac hard drive, I found only one way - formatting my disk and reinstalling OS (probably I was wrong).
It is not a very often case, but when it happens will be better to have a backup of your data.
Maybe you thought about backup too, but usually, it's still just a thought.
The first easier way to create a backup on the mac machine is to connect the hard drive through USB and set up it as a backup disk, however, it is not our way.
Let's start.
First of all, you need to install your favorite Linux distributive (I use raspbian).
Suppose you already have installed Linux on your raspberry pi or any other computer.
First, you need to update packages:
sudo apt update
sudo apt upgrade
The next step is to install all required software:
sudo apt-get install hfsutils hfsprogs netatalk avahi-daemon -y
Then connect your hard drive to the computer and set some settings:
sudo mkfs.hfsplus /dev/sda1 -v TimeMachine
sudo mkdir /media/tm && sudo chmod -R 777 /media/tm
sudo chown orangepi:orangepi /media/tm
After executing these commands you need to configure disk mounting after the system rebooting.
Find the Label of your hard drive:
ls -l /dev/disk/by-label/
or you can use UUID that can be found by this command:
ls -lha /dev/disk/by-uuid
Open to edit fstab file:
sudo nano /etc/fstab
and add the next line to the end of the file fstab:
LABEL=TimeMachine /media/tm hfsplus force,rw,user,noauto 0 0
if you use UUID:
UUID=3adc5a8b-1514-4a8a-be38-476c89b00d71 /media/tm hfsplus force,rw,user,noauto 0 0
Check that you made the correct changes:
sudo mount /media/tm
The next step is adding your disk to netatalk config:
sudo nano /etc/netatalk/AppleVolumes.default
Find these lines at the end of the file and change according to this example:
# The line below sets some DEFAULT, starting with Netatalk 2.1.
:DEFAULT: options:upriv,usedots,tm
# By default all users have access to their home directories.
#~/ "Home Directory"
/media/tm "TimeCapsule"
# End of File
Now you set up all settings and it is time to test your work.
Start services:
sudo service netatalk start
service avahi-daemon start
Go to your mac and set up a backup disk. (Preferences -> TimeMachine -> Select disk)
If you will get an error that the disk is read-only, try this command:
sudo chown orangepi:orangepi /media/tm
In order to start all required services after system rebooting you could use a crontab:
sudo crontab -e
Add this line to the bottom of the file:
@reboot sleep 30 && mount /media/tm && sleep 30 && umount /media/tm && sleep 30 && mount /media/tm && chown orangepi:orangepi /media/tm && sleep 30 && service netatalk start && service avahi-daemon start
For confirmation that your raspberry has the right configuration, you can try to connect using Finder. Open Finder -> press Cmd+K enter afp://ip-raspberry-pi then you will see new mounted folder.
This is it. I hope my tutorial will help you to start creating backups.
Posted on July 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.