Nov 27, 2012

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
- ENJOY.

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 pi@192.168.1.140
pi@192.168.1.140'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 hfsprogs
Press "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 drive

Let's create a directory for our new tome. We will need this to mount filesystem.
pi@raspberrypi ~ $ sudo mkdir /mnt/TimeMachine
Lets unmount our tome (in case you did tested it exists with me).
pi@raspberrypi ~ $ sudo umount /dev/sda1
And add a proper fstab entry to auto-mount this hard drive on boot. Open fstab:
pi@raspberrypi ~ $ sudo nano /etc/fstab
And add a line to the end of the file, indicating our Time Machine tome mounting preferences. Mine was:
UUID="AAAA-BBBB..." /mnt/TimeMachine hfsplus rw,force,exec,auto,users 0 3
Where AAAA-BBBB...  is your devise UUID from that blkid command remember?
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/sda1
Anyway 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 update
And 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-dev
After 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:
pi@raspberrypi ~/netatalk-3.0 $ ./configure --with-init-style=debian --with-zeroconf
It will do the proper configuration for our needs. After this is done run:
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.conf
And 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/volume
It is quite well commented so you will be able to copy-paste and edit ;).

6. Configuring AVAHI services 

Now 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:
pi@raspberrypi ~ $ sudo nano /etc/avahi/services/timecapsule_afpd.service
Then add this contents to file:
<?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 start
Avahi 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 boot

We 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:
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 $
You can read about system runlevels and why this command and not another in this article:
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:

Please comment your thoughts about all of this. Every comment is appreciated. Thanks. And hope someone would benefit from those my findings.

83 comments:

  1. What is your opinion of this compared to the Apple Hardware? Especially with regard to restoring files and speed. The pi lacks GB networking, which is could be a significant slowdown.

    I backup a laptop over Wireless N connected to a Mac Mini setup much like you have done here, in that I don't have an official Time Capsule/Machine. Over wireless, I get about 300Mb/s average on a large single file. The external is also connected via FW 400.

    In the Pi's case, the bottleneck is probably USB 2 speeds, as I don't think it has USB 3 built in. Those would be the two best changes to the Pi in the future I think, USB 3 channels and GB networking. With built in Wireless N being a distant 3rd great option.

    I suspect you saturate USB speeds as it stands now?

    ReplyDelete
    Replies
    1. Well I have compared it to one of the top NAS devices that support time machine backups... My friend recently got one. QNAP for 2 hard drives. He had got himself a normal HDD and initial backup (his was 290 Gb, Mine was 340 Gb) took us about 24 hours. TO be exact His was around 20 hours and mine was 23 (Estimated). So speeds are almost equal. Now he bought Gigabit LAN. But speeds of Time Machine backup did not increase.

      So to sum things up I'd say I'm happy I did not pay around 250$ for a NAS.

      One more thing. In case of a system failure or my MAC stolen... I can restore deataching USB port from Raspbery Pi to a Mac directly and this will take about 3 hours to restore (Directly connected via USB 2.0) And did some magic in the console to mount a partition image of backups.

      SO I assume this decision is quite affordable and quite comparable to time capsule if you have an external HDD with a mount and power (Like I did). Besides all of this... You usually will back up your data using Wi-Fi... Or maybe you will set Time Capsule staying at your table. Which is possible but unlikely...

      So IMHO described in this article method is not barly the same, but an affordable cheap alternative in some cases.

      Delete
    2. QNap TS-212 with gigabit ethernet works as TimeMachine with average speed 10MB/s. 370 GB backup take around 12 hours.

      With AFP it gives avg. 30 MB/s on download from NAS and 20 MB/s in upload.

      HDD in NAS - WD RED 2TB.

      As I see in Apple TimeCapsule benchmarks it has speed around 10 MB/s top: http://www.cnet.com/network-storage/apple-time-capsule-1tb/4505-3382_7-33549751-2.html

      But Apple TimeCapsule cheaper then NAS with gigabit router.

      Delete
    3. ...also clear AFP speed is higher then backup speed (as processor is used more). So real TimeCapsule backup speed can be near 5 MB/s. It would be great if real TimeCapsule user can tell us more about it.

      Delete
  2. Wow, great suggestion for Mac owners! How much trouble would it be to adapt this to Ubuntu or Lubuntu? I already have a P4 Linux machine set up as an 802.11n bridge for my home network.... Thanks!

    ReplyDelete
    Replies
    1. AFAIK Ubuntu has package management "apt" command. SO I think only fstab edits may differ (in case Ubuntu uses alternative mounting mechanism) But in general I think all this commands from article must work without any modifications on Ubuntu. I think I've covered enough what is used here. But you may have easier options like precompiled Netatalk 3.0 package and so on. But this must work like described here on any Linux system that has apt and up to date core and utills...

      It would also be nice if you comment her if you have done it using this tutorial and (maybe) what is specific for Ubuntu.

      Delete
  3. Do you use any Media Server on your Raspberry?

    ReplyDelete
    Replies
    1. No I don't. At least for now. I usually play media via iPad over SMB share. So planning to add this possibility to RPi too...

      Delete
  4. Time machine is a nice option to backup Mac data and that too an incremental backup. It is suggested to create a bootable copy of Mac OS X via a cloning software like Stellar Drive Clone.

    An easy to use tool to make an exact replica of Mac drive.

    ReplyDelete
  5. oups, since I can't get my HD rw but only ro, I tried a "sudo fsck.hfsplus -f /dev/sda2" but this process never end and I fear to kill (or pom+c) because I don't want to damage my hard drive...

    any idea if I can kill this or not ?

    how long should this be for a 512Go HD ?

    ReplyDelete
    Replies
    1. Not sure... All depends on damages. But I've done this. e.g. killed this process several times and nothing happened (too bad)... I've mounted it to the mac directly and it had run much quicker. AFIAK it does not make changes until full scan. And on Pi it can take ages. SO feel free to break this and reconnect o your mac. Nothing bad must happen if there were no special conditions. Like real HDD errors or bad sectors.
      IMHO. But anyway do it at your own risk ;)

      Delete
    2. thanks, you were right. nothing happened but I got some minors errors on the disk... I will replace this one with a brand new next month and follow this time capsule again.

      thanks

      Delete
  6. Hi! I have some problems.
    I want to use Raspberry Pi as XBMC server and TimeCapsule so I install raspbmc OS. Then I used your instruction.
    My first problem is Netatalk doesn't start at boot:
    pi@raspbmc:~$ sudo update-rc.d /etc/init.d/netatalk defaults
    update-rc.d: using dependency based boot sequencing
    update-rc.d: error: unable to read /etc/init.d//etc/init.d/netatalk

    And I have the second problem. Disk doesn't mount in read-write mount.
    There is my /etc/fstab:
    /dev/sda2 /mnt/TimeMachine hfsplus rw,force,exec,auto,users 0 3

    But after reboot the RasplberryPi I have:
    pi@raspbmc:~$ mount
    /dev/mmcblk0p2 on / type ext4 (rw,noatime)
    proc on /proc type proc (rw)
    devpts on /dev/pts type devpts (rw,noexec,nosuid,relatime,gid=5,mode=620)
    /dev/mmcblk0p1 on /boot type vfat (rw)
    /dev/sda2 on /mnt/TimeMachine type hfsplus (ro,noexec,nosuid,nodev,force)
    /dev/sda1 on /media/EFI type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,uhelper=udisks)
    fusectl on /sys/fs/fuse/connections type fusectl (rw)
    /dev/sda3 on /media/NTFS type fuseblk (rw,nosuid,nodev,allow_other,default_permissions,blksize=4096)

    As you can see:
    /dev/sda2 on /mnt/TimeMachine type hfsplus (ro,noexec,nosuid,nodev,force)

    How can I fix it?

    ReplyDelete
    Replies
    1. About problem with netatalk on boot please read this part of article:
      7. Put avahi and netatalk demons into autolaunch on system boot

      About partition mounting:
      You must have a proper partition type for this. I have a hfsplus case insensitive journaled. And you must try to connect it to your Mac first. Maybe you need to scan this disc for errors. And this will enable mounting in a proper mode...

      Delete
    2. Thank You for help me with partition mounting. I connected HDD to my Mac and reformat partition as Mac OS X Extended (Journaled). Then I connected it to my Raspberry and it automount in 'rw' mode. I did this command again:
      sudo chown -R pi /mnt/TimeMachine

      About start netatalk on boot:
      I have read part 7 of article but I have error:
      pi@raspbmc:~$ sudo update-rc.d /etc/init.d/netatalk defaults
      update-rc.d: using dependency based boot sequencing
      update-rc.d: error: unable to read /etc/init.d//etc/init.d/netatalk

      Delete
    3. same problem here

      update-rc.d: using dependency based boot sequencing
      update-rc.d: error: unable to read /etc/init.d//etc/init.d/netatalk

      Delete
    4. I will try to test it. Because I have installed this several times on my Pi. Perhaps I've missed something here. Thanks guys.

      Delete
    5. Hek. The solution here you need to enter that directory.
      pi@raspberrypi ~ $ cd /etc/init.d/
      pi@raspberrypi /etc/init.d $ 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 $

      Worked for me... Please try and report...

      Delete
    6. it work for me, thanks! Running at the first reboot
      One more thing to ask
      both my macbooks, running lion dont show the TimeMachine in the sidebar of Finder, unless i use the cmd+K and insert the path.
      There's no way it show up, only show's the smb share i have setup for xbmc thumbnails and content in with another hard drive.

      Good

      Delete
    7. Select Finder and hit Preferences in main menu. There is a Sidebar part. Check all the stuff there. Enjoy ;)

      Delete
    8. I have all selected, but no way finder detects it and show it up.
      Not that big deal, time machine backups just works, even if no TimeMachine share show up in Finder, the app finds and connect automatically, my backups are working.

      Thanks

      Delete
  7. I was looking for this kind of tutorial on internet for few days. Actually i have same issue Netatalk.......
    update-rc.d: using dependency based boot sequencing
    update-rc.d: error: unable to read /etc/init.d//etc/init.d/netatalk
    please someone suggest me about this........Visit this link

    Regards,
    Berry

    ReplyDelete
  8. I still have problems with connect external HDD in 'rw' mode.

    I have formated HDD as HFS+ Journaled in Mountain Lion OS and have attached it to RaspberryPi. RPi rebooted and showed me that HDD in read-write mode. But after manual reboot RPi I noticed that HDD is in 'read-only' mode. And I can't change it in read-write.

    Can You help me with that?!

    ReplyDelete
    Replies
    1. I to am having issues with this. Just tried a clean format of a drive to HFS+ as well.

      Delete
  9. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Do i need to reconnect to my Pi all the time when i come home with my macbook or will it be automatic?

      Delete
    2. I have automatic time capsule sessions. But it may depend on your network configuration. I have a static IP's set to main devices that I deal with. E.g. I know that my PI has ip ... and macbook has ip ... So when I connect a macbook to netwok I know it will work. However For automatic working of time capsule, this way described in the article, you will need only Pi to have static address. Or set up in any other way so it will be easily locatable by time machine software. Time Machine on a mac connects to the Pi based time capsule in auto mode. It mounts a network share by itself. Without entering anything. However you must enable your security policy to store password into Keychain. And it works.

      Delete
    3. In fact it connects and stores a backup without you manually mounting a AFP share.

      Delete
    4. Yeah tried it out and it works perfectly! Thanks man! One more question. Is it possible to connect another computer to the same time machine? Will it create an other "img" for that computer? Or do i need to partition the hdd and more to make it work?

      Delete
    5. Main condition for it to work simultaneously is for those macs to have different names. Same names may cause collision. But it may be handled too. I use it for 2 of my macbooks in fact ;)

      Delete
  10. Just wanted to leave a comment to thank you for your tutorial. It worked perfectly for me and I'm now happily running Time Machine backups over wifi rather than having to physically connect my usb external hard drive.

    One question, is there a way to have the drive automatically display in OSx every time I log in? I tried to add it as a login item via user preferences but it never reconnects automatically. I always have to click the drive and then explore it to connect.

    ReplyDelete
    Replies
    1. Go use this guide.
      Worked for me.
      http://rics.partners.org/show_article.php?id=110
      One thing instead of smb://.... please specify another protocol you are using:
      afp://........

      Delete
  11. Hello, I have followed this tutorial (It is one of the best tutorials out there btw) but I have run into a problem when trying to connect. What do I connect as?

    I think I changed my Pi username from "pi" to "RAPCS" as I have: root@RAPCS but when I try to enter RAPCS it will not let me connect. Should I therefore connect using the details I use when SSH'ing into the client? I'm confused.

    Thank you

    ReplyDelete
    Replies
    1. NO!
      you have changed not a username but computer name according to this string:
      "I have: root@RAPCS"
      so seems like you still have username pi...
      Not sure...

      Delete
    2. RAPCS looks like the hostname of your raspberry pi machine and you're logged in as root. The fact that you're logged in as root means that you'd likely be able to log in using the name 'root' with the proper password. That said, operating as root is not recommended and I'd suggest you look at the contents of /etc/passwd to find out whether the 'pi' user still exists. Type "cat /etc/passwd" in your terminal to see the file contents. If the pi user is there, run "passwd pi" as root and you should be able to reset the password. Good luck.

      Delete
  12. This is a terrific article. Thank you for putting it together!

    I have followed the entire tutorial and have been successful with all but the final step. I am able to see/mount the shared drive in finder; however, when I open "Time Machine Preferences" and click "Select Backup Disk..." it looks for time capsule devices and does not locate the raspberry pi.

    Have you run into this?

    Thanks again!

    ReplyDelete
    Replies
    1. Figured it out! I restarted the Pi so that the AFP configuration would be reloaded. I'm sure there's an init script that I could have used instead, but restarting did the trick.

      Delete
  13. Any idea if you can set up 2 separate drives connected to the Pi to have 2 separate Time Machines for different laptops. My son and I both have Macbook Pros and I would like to set up the Pi with 2 separate drives so we each have our own Time Machine?

    ReplyDelete
    Replies
    1. I think it's a matter of connecting two drives and mounting them in proper mode. Also config will have two directories. And mounting your time machine will differ too a bit... you must choose one directory there and your son's laptop another. But in general no need of two separate drives for this. Your backups will be in separate volume files. Only the laptop names must differ for this.

      Delete
  14. it work for me, thanks! Running at the first reboot
    One more thing to ask both my macbooks, running lion dont show the TimeMachine in the sidebar of Finder, unless i use the cmd+K and insert the path. There's no way it show up, only show's the smb share i have setup for xbmc thumbnails and content in with another hard drive.
    Regard's,
    Ben Linus,
    Click Here For More Info

    ReplyDelete
  15. Thank you very much ... it works the first time after several unsuccessful attempt following other article on the Web.

    ReplyDelete
  16. Thank you very very much. It's at great guide you have made. Very easy to follow and the only part that gave me some trouble was the "download, unzip and install Netatalk part" but even as a linux beginner i succeeded.
    I do have a couple of problems/questions.
    -My new little server shows up both as TimeMachine Pi and TimeCapsul raspberrypi. Is that correct and why does it show up twice?
    - I have saved a couple of test files on the harddrive. I can se all the files from my mac but i cant delete them. There is a issue with the permissions. The same problems appears when i want to make a timemachine backup. The timemachine shows up put my mac has not permission to read and write on the drive.
    How can i fix this?

    ReplyDelete
    Replies
    1. I think you have missed the point with mounting your hard drive in a write mode. Please read it again. Maybe rebooting your pi would help. Anyway it is quite hard to tell without additional specific data. ;) e.g. /etc/fstab content and your mout command output... Would be quite useful, if not tell yourself what's wrong.

      Delete
  17. This is a great post in every way. so good detailed even a novice linux can work it out.
    But I faced a problem.
    The main problem is: Timemachine doesn't show the disk.
    Also I can't see the disk under network in finder but I am able to connect it by cmd+K and I see the disk mounted.
    But I can't write to disk from my mac!

    some details:
    I see that disk is mounted as rw.
    but I cant copy files to it even on my pi.
    I tried this by startx and copying some file to mnt/TimeMachine but I get permission denied.
    When I check the permissions I see 99.

    Any help would be appreciated.

    Thanks.

    ReplyDelete
    Replies
    1. I am not sure how but I managed to solve this.
      Maybe it got solved by repairing the disks with diskutility on mac.

      Now I have 1 minor problem:
      Disks do not get mounted without cmd+K and this will for sure hurt the automation of the backups.

      Any ideas?

      Thanks.

      Delete
    2. Here at last. Ok. You do not need any CMD+K by default for Time Machine backups. It will automount this volume, in case you connect it in a default way...

      So CMD+K needed only for you to check that backup or to find something. As for me it often auto connects when I hit "Enter Time Machine"...

      Not sure what your problem is. I guess it is about properly specifying a backup destination in the Time Machine itself.

      Delete
  18. I am up and running the Time Machine now. Thanks to you...
    But I find the backup very slow. you guys got like 35 hours for 350GB. But I get like 3-4 days !
    I read some stuff about mounting the disks and how mounting options can fasten up things by disabling some functionality.

    currently I am mounted with your settings in this article.
    But what do you think about adding noatime to the mounting options?
    Will that hurt Time Machine functioanlity?

    People report that they have dramatic speed increases by adding noatime with other filesystems.
    What do you think? will that mess up the timemachine?
    What do you think?

    ReplyDelete
    Replies
    1. I think you should definitely try it and report here. My settings are quite basic. I did not dive into details with mounting speeds. I believe your time machine is hard to damage because it is mounted as 1 file at an external filesystem. All other stuff happens inside this file. So it may be the matter of write permissions for this file. So again, nothing to cruel may happen. The worst thing is that you may loose your backup and have to recreate rom scratch... But dramatic speed increase sound like a worth trying case ;)

      Delete
  19. Thanks for the guide!

    It's definitely the most complete guide that uses netatalk 3. Most other guides I found use version 2.

    Regarding using HFS+. As I understand it, and from my own experience, it doesn't really matter what file system the backup disk has. Since Time Machine uses sparse bundles (.sparsebundle), the Mac-specific metadata is kept intact.

    These are my experiences with filesystems on the backup disk:

    I started out using HFS+ non-journaled, which ended up corrupting the backups very quickly (Time Machine says "... must create a new backup for you"). I was thinking of enabling journaling (as you suggest), but as I read it other places on the web, there's little evidence that the the "-o force" option actually makes the journaling work.

    So I ended up using the ext3 filesystem, which is journaled like HFS+ and tried and tested under Linux, and everything seems to work quite well. I have had no backup errors under network interruptions (ie. if the lid of the Mac is closed), and the Time Machine share shows up when booting the Mac into recovery mode.

    So my suggestion is to go for ext3 on the backup disk. I'll report back if I encounter problems!

    Some links I found relevant regarding the subject:
    - The error message I received using HFS+ (non-journaled): http://pondini.org/TM/C13.html
    - A guy who's had one bad experience but since then good experience with HFS+ journaled and force-mounting: http://ubuntuforums.org/showthread.php?t=1723857
    - Guy claiming file system doesn't matter (in the comments): http://pwntr.com/2012/03/03/easy-mac-os-x-lion-10-7-time-machine-backup-using-an-ubuntu-linux-server-11-10-12-04-lts-and-up/
    - Guy wanting to re-implement HFS+ with journaling and claiming using force is "not a good idea": http://www.google-melange.com/gsoc/proposal/review/google/gsoc2011/naota/1

    ReplyDelete
    Replies
    1. I thought to use ext3/ext4 too (at first). Here is why I discarded this idea:
      Main idea that in case of a failure you could use this pi/external HDD to connect directly to your mac/book and restore from there. This is possible. Because in case of real failures you usually need things lightning fast. And so restore from backup may take about 24 hours, like it did to make initial bakup.
      Using native time capsule HDD FS format eliminates many (possible) bugs like this one (IMHO).

      Thanks for this. My friend figured out why his time machine fails sometimes with error to recreate a backup. He uses journaled ext4 at his nas and has such a problem ;)

      Delete
    2. How to restore the data throuht the USB after i use HFS+ format to do Time Machine job?

      Delete
    3. >>> How to restore the data throuht the USB after i use HFS+ format to do Time Machine job?

      You need to connect your HDD to your mac (obviously) and then boot in Restore mode. Then you have to enter terminal and type a command. Exact command. I do not remember... And can not google it in a timely manner... But be sure it works. I have done this once.

      Delete
    4. It's a pity :(
      Restore the backup from AFP is too slow...

      Delete
  20. Thanks for this tutorial-- great! I have everything flying smoothly, except that the hard drive that I want to use (1.5 TB WD Passport) is showing up in both Mac OS and Terminal as 128M. It's been properly formatted, configured, etc., because I was using it as a direct USB backup for several weeks until now. Any thoughts?

    Thanks again-- I appreciate the well-written directions.

    ReplyDelete
    Replies
    1. I think it was not properly formated. Because it would display your space properly. Please make it 1 partition and HFS+ Journaled filesystem type before working out this article.

      Direct usb backup is not equal to time machine backup. Time machine creates an image and direct backup stores data directly...

      Delete
    2. Ah-hah! I bet you're right. I have been using it as a Time Machine backup, but I had it encrypted. I bet that's why it's not displaying properly. Will reformat and attempt. Many thanks!

      Delete
  21. Replies
    1. Feel free to use Netatalk 3.0.1
      Main thing I have experienced Issues with Netatalk 3.0.1 and using 3.0 solved this. I do not remember what they were exactly... AFIK it was netatalk daemon dying time to time and killing the automation. IMHO it';s a Pi specific part. Or maybe it's just my hands... ;)

      Delete
  22. When I was running through these commands I am unable to get past configuring the netatalk before install.
    ./configure --with-init-style=debian --with-zeroconf
    -bash: ./configure: Permission denied

    I have tried with sudo as well as setting myself up as a super root. Any suggestions?

    ReplyDelete
    Replies
    1. Not sure exactly. But to my opinion, the spot is in you sources of netatalk...
      I think you have to download a 3.0.0 from official mirror. Be sure you have done so. ./configure with those perms works out of the box on a PI for many people...

      Delete
  23. I don't see the advantage of having a separate share as a Time Capsule which is also an AVAHI service. I mean, if I add the Time Capsule, on Finder appear two shares ("TimeMachine RasPi" and "TimeCapsule") but once logged in, on both shares appear the same volumes ("Time Machine" and "Home").
    On Time Machine interface happens the same, only appears the volume "Time Machine" on share "TimeMachine RasPi".
    From your instructions I don't get a clear explanation :/
    Can you explain the reason of creating a Time Capsule share?

    Anyways you've done a great job that's a great tutorial!
    I'm currently backing up a 10 GB test, although through a 54 Mbps WiFi with speeds less than 1 MB/s :(

    Thanks and bye!

    ReplyDelete
    Replies
    1. I can only agree with Àlber, I don't see the point of configuring the AVAHI.
      I would like to have my Mac view it as a real Time Capsule, but it's annoying having two shares, like this:
      - one appears as "TimeCapsule RasPi" (icon of a Time Capsule)
      - other appears as "TimeMachine RasPi" (icon of another computer)

      I changed my hostname to RasPi, that's why I don't see it as "TimeCapsule raspberrypi".

      Delete
    2. Yes you are right. But you got the pattern ;)

      Delete
  24. I went through and followed your guide and it looks really good! Good work!
    I'm close to having it working, but no cigar yet...

    I do have one problem, that is that I have connected a disk already containing an existing Time Machine backups on my Pi. It looks good, I can mount it and I can see the Backups.backupdb folder with its contents.
    However, after configuring the disk in Time Machine I would have expected that my old Time Machine history (from 2011 and forward) would show in the System settings overview on my MacBook, but all I see is this:
    - Oldest backup: None
    - Latest backup: None

    I haven't proceeded here, because I would like to avoid creating a new instance of backups. I would prefer to continue building on my old backup history. I somehow imagined OS X to just realize that this is the same backup set, only on another location.

    When I browse the Time Machine disk (mounted on my Pi) over the network using Finder on my MacBook I can see the folder Backups.backupdb// containing several folders named with dates in the past.
    So I don't understand why Time Machine isn't able to understand that there already are existing old backups.
    Or perhaps it's not meant to work that way?

    ReplyDelete
    Replies
    1. No it does not meant to wrk that way. I thought I'd make a local backup to that hard drive and then use it afterwards. But it creates a virtual volume (like on original time capsule)...
      So you must stick to that. You may try to create that volume and put your data into that volume...

      You also will need to mount that volume in system restore (in case of failures) and you wish to boot your mac in recovery and connect your HDD directly.

      So yeah. It comes at a cost...

      Delete
    2. Aha, I didn't realize this.
      In that case, I guess I could just as well use ext4 instead of hfsplus, if it keeps everything in an image?
      This would certainly feel more comfortable on a Linux box...

      And I also guess that I could initiate a backup, then mount it and copy all old backups into the image to make Time Machine recognize my old backups.

      Thank you for the clarifications.

      Delete
  25. This comment has been removed by the author.

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. Is it possible to direct to "Time Machine" folder when logging in on "TimeCapsule" instead of having both directing to the same folder? So if i log on to "Time Machine" i can se pi home dir and time machine dir but if i log on to "TimeCapsule" i will be directed to the time machine dir without having to klick on it?

    ReplyDelete
    Replies
    1. Also want to ask why should i create the second share "TimeCapsule" when it only shows "Time Machine on TimeMachine Pi" and not "Time Machine on TimeCapsule"

      Delete
    2. Ok... Let me try to explain.
      You could create a single share e.g. TimeCapsule. So You can create One share and use at as your Time Machine backup destination only. I have several devices attached to my Pi and they serve me well ;). So feel free to create one share with redirect. It was not sufficient for me.

      About 2 Shares. To my understanding. It may mean you consider virtual time machine volume as another additional volume. I can not see what's going on farther. Time Machine MUST create an additional volume with certain names type. It is required so you could back up several of your computers onto there...

      Hope this helps.

      Delete
  28. very great stuff! just tried this out yesterday, and asides from the time it took to compile netatalk, everything was set up real fast and easy!
    thank you Iurii Garmash!!!

    ReplyDelete
  29. Great guide, Iurii! I've started building netatalk-3 debs here: https://github.com/thpani/netatalk-armhf/releases Perhaps you want to use them / refer to them in the article?

    ReplyDelete
  30. For some reason after selecting "Time Machine on TimeMachine Pi" as my backup disk I am told "You don't have the necessary read, write and append privileges on the selected network backup disk." I don't understand since I chown the directory and I could connect to the "shared" disk.

    ReplyDelete
  31. Hey Iurii! Nice guide!
    I would make one suggestion, rather than changing the owner of the TimeMachine disk
    (sudo chown -R pi /mnt/TimeMachine)
    I would add your mac's user and UID to the raspberry pi. This is for a couple of reasons, first if the disk is large, it takes a long time to change all permissions.
    And second, your time machine disk no longer will work if you need to directly plug it into your mac. This is a common problem with network shared file systems (NFS). It is best to have common user name's and UID on all machines.
    Thanks for the write up!

    ReplyDelete
    Replies
    1. Hi Dave,

      Sorry to drag up a comment you made ages ago. I was wondering if you might be willing to elaborate with some instructions on your suggestion. It's seems like a really sensible idea but I've been going round and round in circles all morning trying to figure out how to do it!

      Any help would be greatly appreciated.

      All the best,

      Will

      Delete
    2. True. Mine stays in semi public place now. SO mine is really encrypted even. Thats why. You suggestion is really nice Thank you.

      Delete
  32. Hi,

    I followed the steps of this excellent tutorial, but I ran into a problem: when I connected to the Raspberry Pi "Time Capsule" in Finder and logged in, I was greeted only with the pi home folder. I did not see my Time Machine Backup. I'm sorry to take up your time, but I would greatly appreciate some help. Also, I had to make netatalk without acls, I'm not sure if that affected anything.

    Thanks,
    Robert

    ReplyDelete
    Replies
    1. Hi!
      Many people did this and it worked. Please in general check if you have followed this steps described.
      "netatalk without acls" why this? default package for netatalk really works like intended. You seem to have installed the wrong one.

      Delete
    2. I installed 3.1.5, but I was getting problems with the make. I've checked all the other steps, and I think I've followed them exactly (except for this one).

      Delete
  33. Great article! One question: Have you had your Mac stop recognizing the Raspberry Pi? I think maybe my Pi's IP changed and now my Mac says that it cannot find the Pi to backup to even though it is on the network. I've restarted netatalk and avahi-daemon but no luck, I think I'll have to readd it in the TIme Machine settings and start over.

    ReplyDelete
    Replies
    1. Note I have assigned static IP's for both my Macbook and Pi. This should solve issues like it.

      Delete