Netatalk on OpenBSD or how to build a free Time Capsule

Publié le 26/11/2020 et écrit par Vincent Finance

Catégorie : #openbsd

Traductions disponibles : fr

## The context behind this tutorial

At home, I have two Apple computers: a Mac Mini I bought new in 2019 and a MacBook Air from 2014 that I bought second hand and that I use for school. Globally, everything is working fine and I'm really happy to use them for my daily tasks, even if I still use Linux for programming and publishing my articles.

What I love the most on Mac OS is Time Machine, the backup tool Apple included by default. It backs up data fast and securely and it can easily go back in time to find a lost document or to restore the entire system. Moreover, it has the advantage of running in the background: you don't have to worry about your data and your backups.
So far, I was using a sketchy method: mounting a virtual drive thanks to a NFS share. It was pretty slow, but it was working fine, so I kept that for one year until I had problems with my storage server and lost my NFS share. Since then, Time Machine no longer works on my Mac and it became critical to change my backup drive.

So, I tried to look for a Time Capsule, a NAS device made by Apple which can be used by Time Machine for backups, but their current price (100€ for 1 TB) and their withdrawal from the market in 2018 (no more security updates) convinced me to not buy one and to look for another options.
Fortunately, I found a free (as in free software) alternative to these devices which is still maintained : Netatalk.

## What is Netatalk?

Netatalk is a file sharing software that can use Apple's proprietary protocols to share files with computers running MacOS X. In fact, Apple developped two specific protocols (AppleTalk and AFP) in order to have a Mac equivalent of SMB (file sharing protocol for Windows) and NFS (file sharing protocol for UNIX and GNU/Linux).
Version 3 of Netatalk can, for example, use AFP protocol and mount a file share that will be fully compatible with the latest versions of Mac OS. It can also act as a Time Capsule so Time Machine can interact with it for backups.

Netatalk is available, as a package, on most of GNU/Linux distributions and on BSDs. Here, we will install it on an old Pentium 4 computer with OpenBSD to give it a new life.

## Installation and configuration on OpenBSD

To install Netatalk, you only need to run this simple command :

doas pkg_add -i netatalk

As OpenBSD has two versions of Netatalk (the 2.1 version for older systems on MacOS 9 or 8 and the 3.1 version), we will choose the third version by typing 2 then Enter.

After installation, we will simply edit the /etc/netatalk/afp.conf file to configure the network shares. Its content looks like the following :

;
; Netatalk 3.x configuration file
;

[Global]
; Global server settings
hostname = narodnaia
log file = /var/log/netatalk.log
log level = default:warn
mimic model = TimeCapsule6,106
keep sessions = yes

[TimeMachine]
; My TimeMachine service
path = /srv/timemachine
time machine = yes
valid users = @users
file perm = 660
directory perm = 740
vol size limit = 350000

The default file contains a small list of examples of what we can configure for our Netatalk server. Here, I show you directly what I use to create a shared folder that Time Machine can use automatically.

The first block, delimited by the [Global] tag, contains the main options of Netatalk. We can find the hostname of the server, where it stores the log file, the kind of peripherials to mimic (in our case, a Time Capsule) and if we want to keep the current sessions connected.
The second block is the file share itself. Between the square brackets, we write the name of the file share and then we add some options for it.

In my example, I created a folder called TimeMachine with a quota of 350 GB (the size is always in Megabytes). This quota allows MacOS to limit the size of the folder and to not fill all of the server's hard drive. The time machine = yes allows Time Machine to use this share for backups.
Another interesting option is valid users which allows to use an authentication and to protect the file share. Here, I just specified that every user in the users' group can connect to the share and write inside the directory. Please note there is no encryption in this example and Netatalk must not be open to the world with this configuration. I invite you to check the official documentation if you want to enable encryption (I have no interest here, since it'll be inside a local network only).

## Time to start the server!

To start Netatalk and enable it at startup, we only use these two magic commands : rcctl enable netatalk && rcctl start netatalk

A netatalk(ok) should appear in your terminal and the server is now ready to accept our clients and exchange files on our local network.

To test it, you go on your MacOS client and you open a new Finder window. In the menu bar, you click on Go to then on Network to see available file shares. After a couple of seconds, a TimeCapsule icon appears in this window, with the name of our Netatalk server. You just need to click on it to open it.
If you need to login, then you click on the Connect as button and you enter your OpenBSD credentials. Your file shares will appear automatically.

Finder's window with the available file shares

## Back up with Time Machine

For a folder made for Time Machine, the procedure is as follow. Open Time Machine to configure your backup drive and click on Choose a disk... to open the selection menu.
After a couple of seconds, your shared folder will appear automatically and you only need to click on it to configure your Time Machine and start the backup. If you enabled authentication, Time Machine will ask for your OpenBSD username and password to connect before starting the process.

Et voilà! Your Mac will automatically connect to your Netatalk server to back up your data and you won't have to care about it, since Time Machine will do the job alone. Your backups are now automatic and safe.

Time Machine's interface with my configured network share

## Conclusion

To conclude, I must say I was impressed by the simplicity, the quickness and the efficiency of Netatalk and OpenBSD. In only 15 minutes, I have a complete backup system for my 2 Macintoshes without problems and using only Apple's base tools and a free software. No more updates problem and no more need to buy a special device which will be obsolete soon.
This is how you quickly recycle an old Pentium 4 computer or any other computer you have lying around at home!


Un commentaire à ajouter ?

Pour ajouter votre commentaire, envoyez directement un mail ici