Shoebox Time Machine backup server with Raspberry Pi ("poor man's Time Capsule")

It is possible and fairly easy to build an acceptable Time Machine backup server using a Raspberry Pi and a spare USB drive. Basically, the process is as follows:

1. Install dependencies
2. Format and set up the drive
4. Configure netatalk

1. Install dependencies

Just do

sudo apt-get install build-essential libevent-dev libssl-dev libgcrypt-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-0.16-dev libtracker-miner-0.16-dev libgcrypt20-dev


2. Format and set up the drive

Some guides call for using a hfsplus-formatted drive. If you have one that you previously used with macOS, by any means – use it. If not, I would prefer a more well-adapted GNU/Linux file system. I would recommend ext4, which is what most distros use, unless you have any particular reason to use something else.

First use sudo fdisk /dev/sda to partition your hard drive (this is assuming that the hard drive is the only USB harddisk or pendrive attached to your Raspberry Pi – if it is not, make sure you pick the right one!).

1. Press o to create a new partition table.
2. Create a new partition using the n command. Choose primary (p) and use the suggested sizes (unless you have reason to change them). Choose the Linux filesystem, which should be the default.
3. When you are back at the main menu, press w to write everything to disk and quit.

Now, format the drive as ext4: sudo mkfs.ext4 -L "Time Machine" /dev/sda1. When you are done, determine the unique identifier (UUID) of the new partition with blkid /dev/sda1 and copy the entire UUID="LOTS OF TEXT" part.

Create a mount point at /media/time_machine with sudo mkdir /media/time_machine.

Edit /etc/fstab and add a line like this: UUID="ca92ada0-e97a-44fc-badb-f0e934d775c9" /media/time_machine ext4 defaults,rw,user,auto 0 0

Mount it using sudo mount -a and try writing anything to /media/time_machine (e.g. touch /media/time_machine/test.file). If you get permissions errors, do sudo chown -R user /media/time_machine, where user is your user name (again, proably pi).

Netatalk is a free implementation of Apples network/file sharing protocols. It is available from the official repositories, but that version is ancient, so we need to compie it ourselves.

First, download it. You can either do it on your local machine and copy it to your raspberry pi using scp, or you can find a link on the download page and use wget <file link> to download it directly. After you have it, just extract it with the usual tar xvf netatalk-3.1.9.tar.bz2 (assuming you have the same version).

You can follow the official guide, but basically it is a matter of running configure with the right flags.

First, see which version of tracker you got from apt-get: pkg-config --list-all | grep tracker and insert it after –with-tracker-pkgconfig-version in the proposed command. In my case, I got 1.0:

./configure --with-init-style=debian-systemd  \
--without-libevent  --without-tdb \
--with-cracklib --enable-krbV-uam \
--with-pam-confdir=/etc/pam.d     \
--with-dbus-daemon=/usr/bin/dbus-daemon \
--with-dbus-sysconf-dir=/etc/dbus-1/system.d \
--with-tracker-pkgconfig-version=1.0


Verify that DHX2 is enabled (you need it for password authentication on recent versions of macOS, at least El Capitan):

UAMS:


Then make && sudo make install it!

4. Configure netatalk

After that, update your /usr/local/etc/afp.conf:

[Global]
; Global server settings
vol preset = default_for_all_vol
log file = /var/log/netatalk.log
uam list = uams_dhx.so,uams_dhx2.so
mimic model = TimeCapsule6,106

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

[Time Machine]
path = /media/time_machine
time machine = yes


Substitute your own user name for amanda at valid users, or omit the line entirely to allow all users. Remember, this is a user account on the server. If you are using a Raspberry Pi, this is probably the “pi” user and “raspberry” password (but you really should create a user of your own and change the password of the default account!). mimic model doesn’t really do much, except giving your Raspberry Pi a nice Time Cube icon in Finder.

Start up netatalk:

sudo service netatalk start


Keep track of the logs using sudo tail -f /var/log/netatalk.log, and try to browse and log in from your computer. The Raspberry Pi should appear in Finder, and you should be able to log in as your chosen user (e.g. pi).

When you are confident everything works, you can set up netatalk to start when the server does:

sudo systemctl enable netatalk


After this, you should be able to find and select your shoebox server as a target in Time Machine. Now, go and make a very big cup of tea as your computer runs its initial backup.

Monoprice tablets and multiple screens under ElementaryOS (and other GNU/Linuxes)

I recently got a 10 x 6.25-inch Graphic Monoprice drawing tablet via Massdrop. It turns out that these tablets are actually re-branded Huion devices, supported by recent kernels and by the Digimend driver. Mine is a Huion H610. ElementaryOS Freya’s kernel is apparently patched to contain the necessary drivers, and everything worked out of the box in terms of reading input.

However, the coordinates on the tablet are mapped to X11 coordinates. Since I have two monitors, this means that every coordinate on the tablet is mapped against a corresponding coordinate on the combined surface of both my screens, which makes navigation extremely awkward. This can be solved by modifying the coordinate transformation matrix. The easiest way to do this is to use the neat tool xrestrict, which simply prompts you to click on the desired screen and sets up the coordinate transformation matrix to restrict inputs to that screen for the tool you just clicked with. It is currently not available in the official repos, but building and running it was fairly straightforward.

Disabling suspend on lid close in Debian 8.0 Jessie

As Jessie now uses systemd by default, the old trick of editing /etc/default/acpi-support doesn’t work. In stead, you have to edit /etc/systemd/logind.conf and add the line HandleLidSwitch=ignore.

In my case, suspend was really slow to kick in, and I have no idea why. In other words, in case you have a newly installed laptop server that dies a while after having its lid closed, this is probably your problem. Also, mine typically crashed on resume, because, hey, it’s 2015 and suspend/resume is apparently still hard.

How I teach myself complex things

I have a method for teaching myself complex new things that I have developed over my 8 years (and going!) as a university college student. Of course, reality is neither this sequential nor this formal, but something along these lines goes very far. It is also important to note that this process is repeated over several cycles for most university courses, so you can not simply assume that a single course is a domain in the sense used here.

1. Get a feeling for the topic

Learning something entirely (or mostly) new is quite stressful, if you are anything like me. So one of the most important things during the inital stages of planning is to cushion the blow as much as possible in order to avoid a negative emotional association with the topic that will hamper my learning. You can do this in a variety of ways; eat ice cream while studying. Study outdoors, in the sun. Use your favourite pen. Tell yourself while reading that you are a fantastic person. Read in small increments, and switch to a more familiar topic. Try to find familiar things within the current topic and find out more about them (this will also help you remember and understand better, so it is a good idea for that reason as well). Think breadth, not depth here.

You are supposed to get a feeling for the general outline and history of the domain you are studying, not become an expert. If you can impress someone who have never heard about compiler design for typed functional languages at a party, you are probably on the right track. Also, if you are under some sort of external control or supervision, this is a good time to start figuring out what they expect of you. If you are taking a university course, old exams are probably very useful to get an idea of what is expected of you. Almost every topic is significantly wider and deeper than any of their courses, and you need to be at least mostly in the same ballpark as your examinators.

2. Find help

The second stage is always to find good help. It may come in the form of an instructor, an older student, a friend, parent, a good book or an on-line resource. It is depressingly seldom your course book, however, because the course book is usually so close to the favored teaching method of your lecturers and/or course planners that you may as well skip reading the book and just attend the classes. Not every helper needs to be smarter or more knowledgable on the topic than you are (in fact, it is probably useful if at least one is not), but you need people, preferrably live people, to discuss your problems with, both in the form of assigned problems and in the form of things you encounter. Very few domains are smooth surfaces without oddities or irregularities, and when you hit them, you probably need someone to at least tell you that you are still sane. Also, be advised that books and other still text/picture resources are usually much, much worse than people in every aspect but availability here.

It typically requires much less work to find a person who understand a problem and have them explain it to you, than it does to bang your head against a description in a book until you have squeezed yourself past the hurdle, so keep a few “smart people” handy. If you do this, you will quickly find yourself becoming a “smart person”, by association.

3. Run into the wall, repeatedly

To understand complex problems you will need to keep seeing them, keep working at them, and keep doing them, even when everything hurts and life is horrible and my god you are way too stupid to figure this out anyway, the smart people must be aliens or something. You need to find mostly bite-sized problems in the domain and practice them over and over again, until they become trivial. This is the point where you develop deeper knowledge of your domain. At the very least, you must learn to recognise, use, and understand the domain’s words, concepts, how everything fits together, and the relationships to other domains, possibly also a knowledge of the history of the domain.

What historical problems have been tackled by the domain? How were they solved? Why? What factors limited/controlled its development? What factors are in play today? What words do experts use, and what do they mean (in a dictionary sense)? What wider concepts are used, and what need do they correspond to? What do they explain? What sorts of mechanised operations (e.g. addition, subtraction, multiplication) are you expected to perform readily? What sorts of things (objects, concepts, people) is the domain about? Generate a lot of questions, and make sure you answer them. This is where you need your help. It is vitally important to never, ever ignore the impulse to just accept things as they are, because that means you are mechanising too big chunks of knowledge. You need to understand not only how things are, but also why they are, historically and theoretically.

It frequently helps me to take pauses when trying to solve or understand a hard problem. I often find that my brain somehow backgrounds the task, and may have made some progress when I return to the problem at a later time. This type of very active, heavy-lifting studying will quickly wear you out, so make sure to combine it with other types of work for the best use of your time.

4. Memorise

The final part is to memorise what you have understood. My tool of choice is flaschards in Anki, but anything that works for you is fine here. The idea is, somewhat paradoxically, to ask yourself questions you already know the answers to, repeatedly and over time.

There are several things you may want to memorise: words, phrases, common methods, patterns… Basically, anything you need to have readily at hand in your head later on. Try to make the flashcards minimal, so that they only test a single word, concept, association, operation etc, and try to make the examples so simple that you can do any calculation or pattern matching almost immediately in your head. If you need to memorise more complex operations or concepts, make sure that you also have cards of their atomic concepts and methods. Think of this phase as long-term storage of your new knowledge. Practice every day.

Also, try to talk about what you have learnt with your friends/family/random people on the internet/your cat.

Focus-follows-mouse in ElementaryOS

I like the focus follows mouse focus behaviour. To set it in Elementary OS (including the recently released Freya), one can simply modify the GSettings database from a simple terminal command: gsettings set org.gnome.desktop.wm.preferences focus-mode 'sloppy'.