Saturday, September 12, 2009

Turning pogoplug into a TimeMachine

Disclaimer first: this is not really fully tested - I haven't tried restoring from TimeMachine backup yet. So there's a chance that this won't really work in the end.

Described below is the (somewhat convoluted) steps I did to get this working. It would be really nice if someone can clean this up, submit the patch to netatalk, create an Optware netatalk package with proper configuration, and another Optware package for pogoplug/timemachine configuration example files... In theory, it should be possible to make "ipkg install pogoplug-timemachine" just "Do The Right Thing". Anyway, here goes the steps:

1) Install gcc, autoconf, automake, dbus, openssl, avahi, libgcrypt from Optware ipkg (it's possible I might have missed a few packages though).
2) Download berkeleydb source from here, unzip/untar, and then build/install by:
$ cd db-4.7.25/build_unix
$ ./dist/configure --prefix=/opt --with-gnu-ld
$ make
$ make install
3) Download netatalk source package somehow. I used CVS following this instruction but it looks like you can download the tarball from sourceforge as well. Once you download/untar it, you can build/install it by:
$ cd netatalk
$ CFLAGS="-O -DSHADOWPW" CPPFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib -Wl,-rpath,/opt/lib" ./configure --prefix=/opt --with-ssl-dir=/opt/ --with-bdb=/opt/ --with-shadow --with-cnid-cdb-backend --enable-afp3
$ make
$ make install
3-1) If your pogoplug mounted disk is formatted in FAT or NTFS, those disks are mounted as root by pogoplug's daemon (hbplug). So you need afpd to be able to run as root. By default, afpd does not allow this to happen. The patch below fixes that - by adding a new option "-[no]allowroot". If you want that, apply the following patch before doing "make" above (if you don't know what patch is, or what to do with the following file, you probably don't want to do this anyway), but understand that this increases the security exposure:

Index: afp_options.c
===================================================================
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/afp_options.c,v
retrieving revision 1.45
diff -r1.45 afp_options.c
212a213,216
> if (strstr(buf, " -noallowroot"))
> options->flags &= ~OPTION_ALLOW_ROOT;
> if (strstr(buf, " -allowroot"))
> options->flags |= OPTION_ALLOW_ROOT;
Index: auth.c
===================================================================
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/auth.c,v
retrieving revision 1.63
diff -r1.63 auth.c
255c255,256
< if ( pwd->pw_uid == 0 ) { /* don't allow root login */
---
> if (!(obj->options.flags & OPTION_ALLOW_ROOT)
> && pwd->pw_uid == 0 ) { /* don't allow root login */
Index: globals.h
===================================================================
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/globals.h,v
retrieving revision 1.26
diff -r1.26 globals.h
39a40
> #define OPTION_ALLOW_ROOT (1 << 8)
cvs diff: Diffing nls

4) Set up dbus to use avahi, by creating a file /opt/etc/dbus-1/system.d/avahi-dbus.conf with the following content:

<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

<!-- Only root or user avahi can own the Avahi service -->
<policy user="avahi">
<allow own="org.freedesktop.Avahi"/>
</policy>
<policy user="root">
<allow own="org.freedesktop.Avahi"/>
</policy>

<!-- Allow anyone to invoke methods on Avahi server, except SetHostName -->
<policy context="default">
<allow send_destination="org.freedesktop.Avahi"/>
<allow receive_sender="org.freedesktop.Avahi"/>

<deny send_interface="org.freedesktop.Avahi.Server" send_member="SetHostName"/>
</policy>

<!-- Allow everything, including access to SetHostName to users of the group "netdev"
<policy group="netdev">
<allow send_destination="org.freedesktop.Avahi"/>
<allow receive_sender="org.freedesktop.Avahi"/>
</policy>
-->
</busconfig>

5) Setup avahi to find aftpd by creating a file /opt/etc/avahi/services/aftpd.service with:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=Xserve</txt-record>
</service>
</service-group>

And edit /opt/etc/avahi/avahi-daemon.conf and set "host-name" to what you want (you probably want to use a different name than the hostname of pogoplug itself, as using the same would make it a bit more cubersome to use samba and afp simultanenously).

6) Now it's time to configure afpd. Edit /opt/etc/netatalk/afpd.conf and add the following line:
- -transall -uamlist uams_dhx2.so -nosavepassword -allowroot
The key part is "uams_dhx2.so" - as far as I tried, this and uams_guest.so were the only UAMS modules that worked with OSX 10.5.8. "-allowroot" would only work if you applied my patch above.

7) You need to set up with "directory" to be exported. Edit /opt/etc/netatalk/AppleVolumes.default, and add a line like (it's supposed to be in a single line):
/tmp/.cemnt/mnt_sda1/TimeMachine TimeMachine allow:root rwlist:root dbpath:/tmp/cdb.db cnidscheme:cdb options:usedots
This would export /tmp/.cemnt/mnt_sda1/TimeMachine directory as a volume named TimeMachine.

8) Create an empty file named ".com.apple.timemachine.supported" in the top directory of the exported volume you want to use as timemachine. e.g.:

$ touch /tmp/.cemnt/mnt_sda1/TimeMachine/.com.apple.timemachine.supported

9) Start all daemons if they haven't started yet.

$ /opt/etc/init.d/S20dbus start
$ /opt/etc/init.d/afpd start

10) Now you should see a Xserve icon in Finder's network view (Shared -> All). Click it, and it will ask for a login and a password - give it the login and the password for pogoplug. You can use root (if you used the patch above), or you can create your own user but in that case you need that user be able to write to the volume. Once you have mounted the TimeMachine volume (that has .com.apple.timemachine.supported file at the root), the system preference -> TimeMachine -> Change disk should display the pogoplug as a TimeMachine disk:

Now the TimeMachine backup should work, though no guarantee it will restore - my backup is still in progress :)

PS. I used the information from following pages:


and possibly some others which I forget.

There was one website that explained setting up avahi/netatalk very well (where I took some of the config files), but I can't remember or find that site now. So I might be missing a few things related to avahi above :(

Saturday, September 05, 2009

Pogoplug performance through AFP

Apparently, netatalk/afpd can push files much more efficiently than samba - I get roughly 20MB/s over gigabit ethernet, compared to roughly 10MB/s with samba. Pogoplug keeps getting better :)

Pogoplug and AFPD, some progress, some roadblock

It turns out it's relatively straightforward to get afpd (in netatalk package from ipkg) running and have OSX talk to pogoplug through AFP as Guest user (this How-To turns out to be quite useful) - you need to set uam_guest.so as uam module, and use usedots option (I'll post my config later). However, I can't seem to get the authentication working yet. Since I can control the guest user id on pogoplug side, this wouldn't be such a big problem, except I have my disk formatted as NTFS and hbplug mounts the disk as root with default umask 755 AND afpd doesn't allow me to set uid 0 as the guest user. :( Hence, currently I can only read from pogoplug, but not write and thus I can't get this working as timemachine yet.

For proper authentication, I'm guessing I'd need to recompile netatalk package with ssl support as the How-To says (though I couldn't verify whether ipkg netatalk has that support included, I'm guessing it doesn't based on syslog output). Well, I tried to download the source from here, but somehow cvs anon login fails for me. Oh well. Till my next spare time...

Thursday, September 03, 2009

Pogoplug/samba/OSX/time machine



I copied a bunch of video files from Pogoplug to my MBP using Samba. And it could do slightly better than 10MB/s when connected through the gigabit. This is more than acceptable performance - at this speed, I don't need/want to install pogoplug kernel driver on OSX. Another happy combination. But this got me thinking... if Pogoplug can act as a native Windows storage system, why not native Apple storage ? So I've started working on turning Pogoplug into a time machine using avahi and netatalk. I haven't got it working but at least pogoplug shows up on Finder's Network view as if it's an Xserve :) Hopefully I'll get some spare time to dig this more and get it working soon...