Backup and Print Server for MacOS

24 April 2020

No AirPort Station or Time Capsule? No problem!

If you are already running a Linux machine on your network it is actually very easy make it of service to your Mac workstation(s).

Prerequisites

File and printer sharing are going to be provided by the avahi and netatalk services. Make sure they are installed and running:

apt-get install -y netatalk avahi-daemon

Check their statuses, they should be enabled and running:

service avahi-daemon status
service netatalk status

If netatalk isn't enabled or running:

systemctl enable netatalk
service netatalk start

AFP File Sharing

To make things easier, ensure that the account on your Linux machine has the same username, password and full name as the account on your Mac. If the full name does not match, run usermod ${user} to change it. This will make authentication from your Mac seamless.

If you want users from multiple Macs to access the same shares, you will need to add their accounts to a common user group. I have not tried such setup, but it should not be a problem.

Adding an HFS+ Formatted Disk

Plug the external disk you're going to use to your Mac and have it formatted as HFS+ (journaled, case-sensitive) using Disk Utility. After that you can plug it to your Linux machine. Check the path and UUID of the disk:

ls -l /dev/disk/by-uuid

You should see similar output:

total 0
lrwxrwxrwx 1 root root 15 Jan 28  2018 52AA-6867 -> ../../mmcblk1p1
lrwxrwxrwx 1 root root 10 Apr 19 09:43 67E3-17ED -> ../../sda1
lrwxrwxrwx 1 root root 15 Jan 28  2018 e139ce78-9841-40fe-8823-96a304a09859 -> ../../mmcblk1p2
lrwxrwxrwx 1 root root 10 Apr 19 09:43 fe38d9d0-fd48-3e90-aacd-85257f5334d9 -> ../../sda2

Storage partitions have a full UUID. In my case, the new disk is sda2. If in doubt, run dmesg and df -h and check which partitions are already mounted.

To be able to work with HFS+ partitions on Linux, we need to install hfsutils. Then we can mount the disk. Don't forget to replace ${diskpath} with your actual path, such as /dev/sda2:

apt-get install -y hfsutils hfsprogs
mkdir /media/timemachine
mount -t hfsplus -o force,rw ${diskpath} /media/timemachine

You should change permissions so your user has full access to the disk:

chown -R ${user}:${user} /media/timemachine

We want a permanent mounting point, so that the disk is automatically available after a system reboot. Append the following line to /etc/fstab:

UUID=${UUID} /media/timemachine hfsplus force,rw 0 0

Double-check that you put in the correct disk UUID.

Setting Up a Time Machine Volume

Append the following to /etc/netatalk/afpd.conf:

"${machine name}" -uamlist uams_dhx2.so

Append the following to /etc/netatalk/AppleVolumes.default:

:DEFAULT: options:upriv,usedots
/media/timemachine "Time Machine" rwlist:@{user} cnidscheme:dbd options:usedots,upriv,tm

Then, restart the services:

service avahi-daemon restart
service netatalk restart
service avahi-daemon status
service netatalk status

You should now be able to select this network volume in Time Machine preferences. I turned off automatic backups, as I found it prevents the disk from idling.

Time Machine volume selected

Troubleshooting

 hfsplus: Filesystem was not cleanly unmounted, running fsck.hfsplus is recommended.  mounting read-only.

If you find a similar message in dmesg logs then the volume is mounted as read-only and backups will not work. To be able to mount it with write access you will need to run disk check on it:

umount /media/timemachine
fsck.hfsplus -f /dev/sda2

Then mount the volume again and restart netatalk.

Print Server Setup

We need to install CUPS (Common UNIX Printing System).

apt-get install -y cups cups-pdf python-cups

It is useful to enable CUPS administrative rights for your user:

usermod -a -G lpadmin ${user}

Finally, edit /etc/cups/cupsd.conf. Add Allow $Local to <Location> and <Location /admin>.

service cups restart

You should now be able to access CUPS web interface at localhost:631. Open it and enable the Printer Sharing option.

Adding a Printer

If you aren't already using your printer on your Linux machine, you will need to add it. You could do that from the GUI or from the command line. In my case it is a network printer. If you know the exact model you could search it like this:

lpinfo --make-and-model LaserJet -m | grep 4050

If the drivers are already installed, you will find it in the list. Then you can add it and set it as default printer:

lpadmin -p ${printername} -E -v socket://${ipaddress} -m ${ppdpath}
lpadmin -d ${printername}

Finally, you can check that the configuration is correct:

lpstat -p -d
lpoptions -p ${printername}

Enabling AirPrint

We will simply run a script that creates the AirPrint configuration automatically:

wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
chmod u+x airprint-generate.py
sudo ./airprint-generate.py -d /etc/avahi/services

Check that an entry has been created for your printer:

ls /etc/avahi/services

You should now be able to see it in the list of printers on your iOS and Mac devices. Open a document, tap Share and then tap Print to open the print dialog.

AirPrint printer selection