DEV Community

Arsenii Kharlanow
Arsenii Kharlanow

Posted on • Edited on

Linux as your Time Machine for mac

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
Enter fullscreen mode Exit fullscreen mode

The next step is to install all required software:

sudo apt-get install hfsutils hfsprogs netatalk avahi-daemon -y
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

or you can use UUID that can be found by this command:

ls -lha /dev/disk/by-uuid
Enter fullscreen mode Exit fullscreen mode

Open to edit fstab file:

sudo nano /etc/fstab
Enter fullscreen mode Exit fullscreen mode

and add the next line to the end of the file fstab:

LABEL=TimeMachine /media/tm hfsplus force,rw,user,noauto 0 0
Enter fullscreen mode Exit fullscreen mode

if you use UUID:

UUID=3adc5a8b-1514-4a8a-be38-476c89b00d71 /media/tm hfsplus force,rw,user,noauto 0 0
Enter fullscreen mode Exit fullscreen mode

Check that you made the correct changes:

sudo mount /media/tm
Enter fullscreen mode Exit fullscreen mode

The next step is adding your disk to netatalk config:

sudo nano /etc/netatalk/AppleVolumes.default
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Now you set up all settings and it is time to test your work.

Start services:

sudo service netatalk start
service avahi-daemon start
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

In order to start all required services after system rebooting you could use a crontab:

sudo crontab -e
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)