Time Capsule for $25
The real article name might be something like: Configuring Raspbery Pi to serve like a Time Capsule with Netatalk 3.0 for Mountain Lion. But it's too long ;)Here I will describe the process of using Raspberry Pi like a Time Machine in my network. To be able to backup your MAC's remotely (Like it would be NAS of some kind). It assumes you have a Raspberry Pi and have installed a Raspbian there and have a ssh connection, or somehow having access to it's console. Refer to my previous article for details.
Now that we have a Pi that is ready for action let's animate it. So to make it suit you as a Time Capsule (NAS) for your MAC's you need to do those basic steps:
- connect and configure USB hard drive(s)
- install support of HFS+ filesystem to be able to use MAC's native filesystem
- make mount (auto-mount on boot) of your hard drive
- install Avahi and Netatalk demons
- configure Netatalk daemon to make it all serve as a Time Machine
- configure avahi demon
- put avahi and netatalk demons into autolaunch on system boot
1. Setup a Hard drive.I assume you know what you are doing and understand you have to have a hard drive formatted under your mac's HFS+ filesystem. That you, like me, used as an external hard drive for backups before this. Just for example. Or bought it... Whatever. One word you will need (or assume you have) an external USB drive to follow me farther.
Start your drive (in case it has external power). I think Pi would handle only drives with external power. But who knows ;). And connect it to your Pi. Let it spin for some seconds to be recognized.
Now connect to console of your Pi and let's roll.
leopard$ ssh firstname.lastname@example.org email@example.com's password: Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Oct 29 01:04:39 2012 pi@raspberrypi ~ $As you can see I have a clean system installed from latest (as for 24.11.2012) downloaded image.
Let's do some magic. Because Raspbian does not support Apple's filesystem out of the box. At least we need to mount it write enabled. Which is not set up by default too. SO let's start from typing command blkid under root and looking at output.
pi@raspberrypi ~ $ sudo blkid /dev/mmcblk0p1: SEC_TYPE="msdos" UUID="8B12-9112" TYPE="vfat" /dev/mmcblk0p2: UUID="AAAAAAA-1111-1111-......." TYPE="ext4" /dev/sda1: UUID="AAAAAAA-1111-1111-......." LABEL="Time Machine" TYPE="hfsplus" /dev/sda2: LABEL="Data" UUID="1234567890......." TYPE="ntfs" pi@raspberrypi ~ $Note UUID of your device. Mine is called sda1 and has a partition type hfsplus. Hurray! Drive is connected and is recognized by Pi.
2. Install support of AFP filesystem (MAC's native).Now let's install tools we need for HFS+ filesystem mounting. We need to mount it RW to be able to backup.
pi@raspberrypi ~ $ sudo apt-get install hfsplus hfsutils hfsprogsPress "y" in the process of install. You will get HFS+ support libraries installed. So let's move on to mounting.
After this you should be able to mount your HDD. You may try it or skip to making permanent mounting config via /etc/fstab (Step 3).
pi@raspberrypi ~ $ sudo mount -o force /dev/sda1 /mnt/TimeMachine pi@raspberrypi ~ $ cd /mnt/TimeMachine pi@raspberrypi /mnt/TimeMachine $ ls -l total 116 drwxr-xr-x 1 root 99 6 Jan 11 2012 Backups.backupdb drwxrwxrwx 1 501 dialout 31 Feb 1 2012 !DVD-s -rwxr-xr-x 1 root root 115716 Sep 1 07:23 tmbootpicker.efi pi@raspberrypi /mnt/TimeMachine $You may see your files from a HDD. Hurray! Again ;). Btw you can look at how is your device was mounted by typing mount command into prompt. It will show your mounted volume and mode it was mounted. So you will see something like this:
pi@raspberrypi /mnt/TimeMachine $ mount /dev/root on / type ext4 (rw,noatime,user_xattr,barrier=1,data=ordered) devtmpfs on /dev type devtmpfs (rw,relatime,size=118872k,nr_inodes=29718,mode=755) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=23788k,mode=755) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=47560k) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620) /dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro) /dev/sda1 on /mnt/TimeMachine type hfsplus (rw,relatime,umask=22,uid=0,gid=0,nls=utf8)Note last line with /dev/sda1 mounted in mode "rw". Yes everything works well. Let's move on.
3. Make mount (auto-mount on boot) of your hard driveLet's create a directory for our new tome. We will need this to mount filesystem.
pi@raspberrypi ~ $ sudo mkdir /mnt/TimeMachineLets unmount our tome (in case you did tested it exists with me).
pi@raspberrypi ~ $ sudo umount /dev/sda1And add a proper fstab entry to auto-mount this hard drive on boot. Open fstab:
pi@raspberrypi ~ $ sudo nano /etc/fstabAnd add a line to the end of the file, indicating our Time Machine tome mounting preferences. Mine was:
Where AAAA-BBBB... is your devise UUID from that blkid command remember?UUID="AAAA-BBBB..." /mnt/TimeMachine hfsplus rw,force,exec,auto,users 0 3
I used UUID to be sure it won't matter if I'll switch hard drives places in USB ports. But you may use /dev/sdXX, where XX is your device counting numbers in /dev. Mine in this case was /dev/sda1.
Note: You can skip reboot.
Let's now do a reboot to make sure it all spins in automatic mode ;).
pi@raspberrypi ~ $ sudo reboot Broadcast message from root@raspberrypi (pts/0) (Wed Nov 21 19:13:49 2012): The system is going down for reboot NOW!After system boots up run mount command to make sure we are ok in rw mode. Btw you may play with commands:
# to unmount volume: pi@raspberrypi ~ $ sudo umount /dev/sda1 # to mount again: pi@raspberrypi ~ $ sudo mount UUID="AAAA-BBBB..."While you will find your string. BTW you can read about how and why in /etc/fstab manual here... Or google about it.
Note: if your HFS+ tome does not mount and/or mounted read only. You should try to run fsck for hfsplus partition type manually.
pi@raspberrypi ~ $ sudo fsck.hfsplus -f /dev/sda1Anyway we must now have an rw mode HFS+ volume mounted and ready for our Time Machine. So Lets move on...
Checking your user permissions. As we will use user "pi" farther along the article we must add him ability to manage Time Machine data. (In case you are not mounting empty drive). You should consider changing all the data owner to user "pi" to make sure we will be abler to backup in future:
pi@raspberrypi ~ $ sudo chown -R pi /mnt/TimeMachine
4. Install and configure Avahi and Netatalk demons
First make sure you have the latest packages lists, running:
pi@raspberrypi ~ $ sudo apt-get updateAnd updating what necessary.
Now install all the required packages with db and encryption support in order Avahi and Netatalk demons to support for HFS+ filesystem:
pi@raspberrypi ~ $ sudo apt-get install avahi-daemon libavahi-client-dev libdb5.3-dev db-util db5.3-util libgcrypt11 libgcrypt11-devAfter this is complete we will have almost everything required for our little demon.
Download and unpack 3.0.0 (latest, as for now is 3.0.1 but I had problems with it spinnig) Netatalk demon sources. For e.g. using command: $ wget http://somesite.com/photos.zip You may get Netatalk at SourceForge. And unpack using e.g. tar: $ tar -xvf netatalk-3.0.0.tar.bz2
After you are ready with unpacked netatalk distribution go ahead and make custom configuration of it. Enter directory of unarchived netatalk and execute command:
It will do the proper configuration for our needs. After this is done run:pi@raspberrypi ~/netatalk-3.0 $ ./configure --with-init-style=debian --with-zeroconf
pi@raspberrypi ~/netatalk-3.0 $ make pi@raspberrypi ~/netatalk-3.0 $ sudo make install
5. Configure Netatalk daemon to make it all serve as a Time Machine
Now when you will have all this done go edit a configuration file of Netatalk. From version 3.0 it is located in /usr/local/etc and has Samba-like look. You can symlink this file to /etc/afp.conf if you wish...
pi@raspberrypi ~ $ sudo nano /usr/local/etc/afp.confAnd insert this sample configuration. This config file works with latest edition ( now it is 10.8.2 ) of OS X Mountain Lion. So the config:
; ; Netatalk 3.x configuration file ; [Global] ; Global server settings ; Name of your computer in apple devices network hostname = TimeMachine Pi ; IP of your Pi afp listen = 192.168.1.140 ; logging config log file = /var/log/netatalk.log log level = default:info [Homes] basedir regex = /home cnid scheme = dbd ; Display each user home directory in this format home name = Home: $u [Time Machine] ; Our Time Machine volume path = /mnt/TimeMachine cnid scheme = dbd file perm = 0660 directory perm = 0770 time machine = yes ; Example to add a new static share: ; [My AFP Volume] ; path = /path/to/volumeIt is quite well commented so you will be able to copy-paste and edit ;).
6. Configuring AVAHI servicesNow you would probably want to have a Time Capsule as a separate share in your network shares. Note this step is optional. But if you plan to use your pi for more than 1 thing, like I do... I'd recommend to do it. Create a special afpd services configuration file by executing:
Then add this contents to file:pi@raspberrypi ~ $ sudo nano /etc/avahi/services/timecapsule_afpd.service
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">TimeCapsule %h</name> <service> <type>_afpovertcp._tcp</type> <port>548</port> </service> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=TimeCapsule</txt-record> </service> </service-group>After this is configured for your desired settings. Go run your demons:
pi@raspberrypi ~ $ sudo /etc/init.d/netatalk start pi@raspberrypi ~ $ sudo /etc/init.d/avahi-daemon startAvahi demon was installed from package. So you might need to actually run restart instead of start command. Now go check your Mac's Network Shares.
7. Put avahi and netatalk demons into autolaunch on system bootWe have installed here an avahi demon from package. So it must be written to all system run-levels during installation. Only thing here is compiled Netatalk 3.0 so you can make a proper trick here by putting it to run with default init.d command:
You can read about system runlevels and why this command and not another in this article:pi@raspberrypi ~ $ cd /etc/init.d/ pi@raspberrypi ~ $ sudo update-rc.d netatalk defaults update-rc.d: using dependency based boot sequencing update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match netatalk Default-Stop values (1) pi@raspberrypi /etc/init.d $
http://www.debuntu.org/how-to-manage-services-with-update-rc.d I find it nice simple and easy.
You can also read about Time Capsule theory and find answers to many "why?" questions here: http://buffalo.nas-central.org/wiki/Time_Machine_&_Time_Capsule_support_on_your_LinkStation
Result:TADAM. The moment of truth. You can look into your Network Shares on a MAC. Select a virtual Time Capsule and hit "Connect as..." button. Login to your raspberry with user pi and saving password. Enter Time Machine directory... And Time Machine share will appear on a desktop (If it is configured to appear for newly mounted volumes...). You will experience something like this:
After all of this is done. Go enter your Time Machine settings and add a new drive. Bckuping on a time capsule is some kind of different to backing up into external (e.g. USB) hard disk drives. Using external HDD as a Time Machine backup disk will store folder Backups.backupdb into the root of your drive. But backup into time capsule (network backup) creates a volume like leopard.sparsebundle, where this leopard is your MAC's name. And connects it as a file system image, storing this folder inside. So to make initial backup connecting through USB and then continue making backups is possible but irrelevant. Because you would have to mount this image and change permission of all files. Then move them into mounted virtual image under Pi or over network. So the advantages of this idea are controversial.
It was looking like so for me:
And my pi, serving like a Time Capsule and external HDD: