Apple Time Machine on Server running Gentoo Linux

This guide is about how to add Apple Time Machine to a Server running Gentoo Linux. Since Apple's backup tool only supports thier own filesystem HFS+, we start with installing it and preparing the disk to be able to create the Time Capsule on it later.

emerge -avq diskdev_cmds
mkfs.hfsplus -v Backup /dev/md2    
mkdir /mnt/disks/backup
# optional: adding a mount point to your fstab
echo "/dev/md2      /mnt/disks/backup   hfsplus noatime     0 1" >> /etc/fstab

Futher we need to install two services - netatalk and avahi-daemon. Netatalk provides Apple's network filesystem protokoll, which is needed since using Time Machine over network requires afs. The Avahi Daemon is used to make Netatalk available in the network.

#  !!! NOTE make sure your use flags contains avahi
echo "net-fs/netatalk avahi pgp samba ssl utils" >> /etc/portage/package.use
echo "net-fs/netatalk ~amd64" >> /etc/portage/package.keywords
emerge -avq netatalk
# optional add both service to the autostart
rc-update add avahi-daemon default
rc-update add netatalk default

The next step is to configure netatalk that OS X could access the network drive by editing /etc/afs.conf as follows. Make sure the user(s) specified under valid user exists on the server. If not, create it. A client will need it to access the afs network drive.

[Global]
; Global server settings
; uam list = uams_dhx.so,uams_dhx2.so,uams_dhx2_passwd.so
uam list = uams_dhx.so,uams_dhx2.so
save password = no

[default_for_all_vol]
file perm = 0664
directory perm = 0774
cnid scheme = dbd
valid users = phgamper

; [Homes]
; basedir regex = /xxxx

; TMAFPVoume could be replaced by a name of your choice
[TMAFPVolume]
time machine = yes
path = /mnt/disks/backup/timecapsule
vol size limit = 1000000

Once we finished, we create the Time Capsule for the specified user(s). As mentioned above a client has to authenticate when connecting to the network file system. Thus the user has to own or at least has read, wirte and execution rights to the folder, where the capsule will finally be stored.

mkdir /mnt/disks/backup/timecapsule
chown phgamper /mnt/disks/backup/timecapsule

Finally we are finish with configuring the server and could go on starting netatalk and avahi-daemon.

/etc/init.d/avahi-daemon start
/etc/init.d/netatalk start

Now the server is ready and should appear in the Time Machine's system configuration. If not, the following fix on your client should work.

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Further Reading

PG4gdWVycz0iem52eWdiOj9maG93cnBnPWN1dG56Y3JlLnB1Jm56YztvYnFsPSUwTiUwTnVnZ2NmOi8vY3V0bnpjcmUucHUvZ2JjdnBmL295YnQvMjAxNC0wOS0yNF8xMTA5X2d2enJ6bnB1dmFyIj48diBweW5mZj0ic24gc24tMmsgc24tcmFpcnliY3ItZmRobmVyIGpiaiBvYmhhcHJWYSIgcW5nbi1qYmotcXJ5bmw9Ii42ZiIgZmdseXI9Iml2ZnZvdnl2Z2w6IGl2ZnZveXI7IG5hdnpuZ3ZiYS1xcnlubDogMC42ZjsgbmF2em5ndmJhLWFuenI6IG9iaGFwclZhOyI+IDwvdj4gPC9uPg==

Using Polybox on Gentoo Linux

The following guide shows how to run polybox, a dropbox like cloud provided by ETH Zurich, on Gentoo Linux.

Since polybox is not in the portage tree, we have to download the packages from a diffrent distro. Debian packages are easy to extract, thus we use the latest *.deb from https://polybox.ethz.ch/repo/Debian_7.0/amd64

  • libpolyboxsync-dev
  • libpolyboxsync0
  • polybox-client

The next step is to extract the *.deb packages using the following command

ar x *.deb
tar xvf data.tar.gz

Then we move the polybox binary, its dependencies and its config file to the right location

cp -r etc/polybox/ /etc
cp -r usr/include/ /usr/local/
cp -r usr/share/ /usr/local/
cp -r usr/bin/ /usr/local/
cp usr/lib/x86_64-linux-gnu/libpolyboxsync.so* /usr/lib/
mkdir /usr/lib/x86_64-linux-gnu/
cp -r usr/lib/x86_64-linux-gnu/polybox/ /usr/lib/x86_64-linux-gnu/

After that /usr/lib64/ should look as follows.

root@host user # ls -al /usr/lib64/ | grep poly
lrwxrwxrwx   1 root root       19 Sep 19 22:06 libpolyboxsync.so -> libpolyboxsync.so.0
lrwxrwxrwx   1 root root       23 Sep 19 22:06 libpolyboxsync.so.0 -> libpolyboxsync.so.1.6.3
-rw-r--r--   1 root root  1109640 Sep 19 22:06 libpolyboxsync.so.1.6.3

Now make sure all further dependencies available in portage are installed. Normaly the qtkeychain is the only missing package.

emerge -avq qtkeychain

That's it! Polybox could be started e.g. using xfce4-application-finder

Further Reading:

PG4gdWVycz0iem52eWdiOj9maG93cnBnPWN1dG56Y3JlLnB1Jm56YztvYnFsPSUwTiUwTnVnZ2NmOi8vY3V0bnpjcmUucHUvZ2JjdnBmL295YnQvMjAxNC0wOS0yM18xNjQwX2NieWxvYmsiPjx2IHB5bmZmPSJzbiBzbi0yayBzbi1yYWlyeWJjci1mZGhuZXIgamJqIG9iaGFwclZhIiBxbmduLWpiai1xcnlubD0iLjZmIiBmZ2x5cj0iaXZmdm92eXZnbDogaXZmdm95cjsgbmF2em5ndmJhLXFyeW5sOiAwLjZmOyBuYXZ6bmd2YmEtYW56cjogb2JoYXByVmE7Ij4gPC92PiA8L24+

Adding power management commands to i3 using polkit

As there are no power management commands, when using i3 we could add them as follows. First we make sure polkit is installed, to allow unprivileged users to run power management commands. Then we create the following script, that contains the polkit commands, place somewhere in $PATH, for example in /usr/bin/i3exit and make sure the script is executable.

#!/bin/sh

lock(){
    xflock4
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        dbus-send --system --print-reply --dest="org.freedesktop.UPower" \
        /org/freedesktop/UPower org.freedesktop.UPower.Suspend
        ;;
    hibernate)
        dbus-send --system --print-reply --dest="org.freedesktop.UPower" \
        /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
        ;;
    reboot)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
        ;;
    shutdown)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

Now we add the following lines to ~/.config/i3/config. Once completed we will be presented with a prompt whenever we press $mod+paus

set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
    bindsym l exec --no-startup-id i3exit lock, mode "default"
    bindsym e exec --no-startup-id i3exit logout, mode "default"
    bindsym s exec --no-startup-id i3exit suspend, mode "default"
    bindsym h exec --no-startup-id i3exit hibernate, mode "default"
    bindsym r exec --no-startup-id i3exit reboot, mode "default"
    bindsym Shift+s exec --no-startup-id i3exit shutdown, mode "default"

    # back to normal: Enter or Escape
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Pause mode "$mode_system"
PG4gdWVycz0iem52eWdiOj9maG93cnBnPWN1dG56Y3JlLnB1Jm56YztvYnFsPSUwTiUwTnVnZ2NmOi8vY3V0bnpjcmUucHUvZ2JjdnBmL295YnQvMjAxNC0wOS0yM18xNjE1X3YzX2NianJlIj48diBweW5mZj0ic24gc24tMmsgc24tcmFpcnliY3ItZmRobmVyIGpiaiBvYmhhcHJWYSIgcW5nbi1qYmotcXJ5bmw9Ii42ZiIgZmdseXI9Iml2ZnZvdnl2Z2w6IGl2ZnZveXI7IG5hdnpuZ3ZiYS1xcnlubDogMC42ZjsgbmF2em5ndmJhLWFuenI6IG9iaGFwclZhOyI+IDwvdj4gPC9uPg==