User Tools

Site Tools


Time Capsule on OpenWRT (Apple File Protocol Server with Time Machine Support)

Working fine with 'force' mount option in fstab


Time Machine is Apple's backup software. It is included with Mac OS X and was introduced with the 10.5 "Leopard" release of Mac OS X. The software is designed to work with internal or external drives, as well as with Apple's Time Capsule. Time Capsule is (among other things) a wireless router with a built in hard drive. It will advertize itself on a network and allow Mac computers to back up wirelessly using Time Machine with a minimum of user configuration. This wiki documents how to make your OpenWRT router behave like a Time Capsule.

This following configuration is for the stable release of Attitude Adjustment 12.09 (r36088). It was developed and tested with a Mac running OSX 10.8.3. These directions have been verified on a Netgear WNDR3800 using a new installation of OpenWRT. There are many examples on the web for configuring a Time Capsule on linux systems. Many of these contain conflicting, incorrect, or superfluous information. This wiki is an attempt to detail the minimum configuration required to run a Time Capsule on OpenWRT. There are three basic steps to configuring Time Capsule:

  1. Formatting, mounting, and configuring an external USB Drive
  2. Installing and configuring netatalk
  3. Installing and configuring avahi

Formatting, Mounting and Configuring an External USB Drive

Time Machine will work with other filesystems, but the Mac native HFS+ is recommended. If your router should die, you can simply plug the external drive into your Mac to recover the data.

Plug the external drive to a Mac and use the Disk Utility to create a single partition. Use the GUID layout for the partitioning and select the "Mac OS Extended (Journalled)" format. When this is complete, use the following command (on the Mac) to turn off journalling:

/usr/sbin/diskutil disableJournal /Volumes/<name_of_volume>

A user name and password will be required to connect to the Time Capsule. Rather than running as root, create a new user and group. For the purposes of this example, the user name is "tmuser" and the group is "timemachine". This can be done manually, or by installing two packages and using the following commands:

opkg update
opkg install shadow-useradd shadow-groupadd
groupadd timemachine
useradd -M -G timemachine tmuser
passwd tmuser

Create a mount point for the drive and set the ownership of the directory to the timemachine group. For this example, the directory /mnt/TimeMachine will be used. Create the read-only file to prevent writing to flash if the disk is not mounted.

mkdir /mnt/TimeMachine
chown root:timemachine /mnt/TimeMachine
touch /mnt/TimeMachine/USB_DISK_NOT_PRESENT
chmod 444 /mnt/TimeMachine/USB_DISK_NOT_PRESENT

Install the packages required for connecting a USB drive. Check out usb.overview and usb.essentials for more details.

opkg install kmod-usb-storage kmod-fs-hfsplus block-mount

  • mkod-usb-storage: Kernel module for USB storage, including all dependencies.
  • kmod-fs-hfsplus: Kernel module for the HFS+ file system that will be used by the time capsule.
  • block-mount: Scripts for automatically mounting the drive on boot or when plugged in.

Plug in the external drive and find the device number using the block info command (on older installations of OpenWRT you may have to use the command blkid instead):

root@OpenWrt:~# block info
/dev/mtdblock2: UUID="1e0c82a7-150c1d32-b3d5c71c-917a14ed" VERSION="4.0" TYPE="squashfs"
/dev/mtdblock3: TYPE="jffs2"
/dev/sda2: TYPE="hfsplus"

Configure the drive to be automounted on startup or when plugged in. Add the following to /etc/config/fstab, where /dev/sda2 is the drive identified using block info:

config mount
	option target   /mnt/TimeMachine
	option device   /dev/sda2
	option fstype   hfsplus
	option options  force,rw,sync
	option enabled  1
	option enabled_fsck 0

Mount the drive.

/etc/init.d/fstab start

If this is successful, you may want to reboot the router to confirm that the drive is mounted on startup.

Change the ownership of the mounted disk to the timemachine group:

chown -R tmuser:timemachine /mnt/TimeMachine


Netatalk is the linux package that supports the Apple File Protocol on linux systems, allowing for file serving, printing, and time servers. It can also be configured to support Time Machine over a network, replicating the features of Apple's Time Capsule. Starting with version 2.2, Netatalk supports the latest AFP protocol level 3.3, required to support Time Machine on OSX 10.7 (Lion) and above. Thankfully, netatalk 2.2.1-5 is included in Attitude Adjustment. If you are using Barrier Breaker, note that netatalk was removed from this version, so you will need to grab an old package from Attitude Adjustment

For the purposes of this installation, only a Time Machine share will be configured. Start by installing the netatalk package:

opkg install netatalk

If this command fails, grab the old version of this package from Attitude Adjustment (you will need to change the ar71xx part of the URL to match the architecture of your router):

opkg install
cd /usr/lib
ln -s

Configure netatalk by adding the line below to /etc/netatalk/afpd.conf. Comment out all other lines. This will configure a server named "TimeMachine" to use the Diffie-Hellman eXchange 2 (DHX2) for authentication. Refer to the man page for afpd.conf for further details on the other options.

"TimeMachine" -uampath /usr/lib/uams -uamlist -nodebug -nouservol -icon -nosavepassword -mimicmodel RackMac

The volumes netatalk will make available are defined in /etc/netatalk/AppleVolumes.default. Add the line below to /etc/netatalk/AppleVolumes.default to create the AFP time machine share, commenting out all other lines.

/mnt/TimeMachine TimeMachine volsizelimit:150000 allow:@timemachine rwlist:@timemachine cnidscheme:dbd options:searchdb,usedots,invisibledots,tm

The first parameter specifies the location of the shared volume, while the second specifies the name. The Time Machine uses a CNID database to reference files on the shared volume. By default, this database will be located in the root directory of the shared volume. The size of the shared volume reported to time machine is set using the volsizelimit parameter. The size is given in MiB. Set this parameter to less than the full size of the disk to reserve space for the database. (If the database can't be written to or is corrupted, the entire Time Machine repository may be lost) The allow and rwlist parameters specify which users can access and write to the time machine. Either specify a user name directly, or just use @timemachine to allow access for users in the timemachine group. Reference the AppleVolumes.default man page for further information on options.

Restart netatalk and enable on boot:

/etc/init.d/afpd stop
/etc/init.d/afpd start
/etc/init.d/afpd enable


Avahi implements a protocol known as Zeroconf or Bonjour to advertise your volume on the network. Install the package:

opkg install avahi-daemon

Avahi is configured via /etc/avahi/avahi-daemon.conf, see Only three lines of the default file need changing:


The first line defines the host name, which will be displayed on client computers before logging in. The second line is not in the default file and must be added to disable dbus support. dbus is a protocol for communication which can be used to communicate between Avahi and Netatalk however, for the purposes of setting up a Time Capsule, it is not required. Instead, the services that Avahi advertises are defined via the XML files in /etc/avahi/services. Create the file /etc/avahi/services/afpd.service, with the following content:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<name replace-wildcards="yes">Time Capsule</name>

This file defines a service group named "Time Capsule", divided into three sections. The first two sections enable the AFP shared volume. The text "model=TimeCapsule" defines the volume as a time capsule, so that the time capsule icon is displayed in the finder. The third section attaches the disk to the service group so that it shows up under the "Select Disk" window in the time machine preferences. The "XX:XX:XX:XX:XX:XX" in the example above should be replaced with the MAC address of the router's LAN interface. The section "adVN=TimeMachine" should match the name of the volume defined in afpd.conf and AppleVolumes.default.

FIXME (Provide better explanation of XML file details.)

Restart Avahi and enable on boot:

/etc/init.d/avahi-daemon stop
/etc/init.d/avahi-daemon start
/etc/init.d/avahi-daemon enable

Configure TimeMachine

You can now use the TimeMachine preferences pane on your client Mac to define your advertised volume as destination drive. When prompted for a user name and password, use tmuser and the password set above. TimeMachine will save your login information.

Restore From Your Server

If the harddisk of your Mac dies and needs reinstallation through TimeMachine, your crippled Mac must first see your OpenWRT box. Boot your Mac with a DVD or similar, open a Terminal and type

mkdir /Volumes/TimeMachine
mount -t afp "afp://<your OpenWRT route>/TimeMachine" /Volumes/TimeMachine

You can then use TimeMachine to read back all your saved data from the remote drive.

FIXME (fix mounting commands to work with username:password)

Restore from the USB Disk

Since the USB disk was formatted using the HFS+ format, umount it from the router and plug it in directly to your Mac for a faster restore.

/etc/init.d/afpd stop
umount /mnt/TimeMachine

When finished, plug it back into the router and restart Netatalk:

/etc/init.d/afpd start

Recovery from Disk Errors

If the backup process is interrupted, the database can become corrupt and unusable. Time Machine will report that the backup is unusable and will suggest creating a new backup.

Use the following steps on your Mac as root:

  1. Connect to the TimeMachine network share.
  2. Run /usr/bin/chflags -R nouchg "/Volumes/TimeMachine/[hostname].sparsebundle"
  3. Run /usr/bin/hdiutil attach -nomount -noverify -noautofsck "/Volumes/TimeMachine/[hostname].sparsebundle"
  4. /sbin/fsck_hfs -drfy /dev/disk3s2 # or whatever disk partition it is mounted as
  5. Run /usr/bin/sed -i "" -e's/<integer>2<\/integer>/<integer>0<\/integer>' /Volumes/TimeMachine/[hostname].sparsebundle/
  6. diskutil eject "/Volumes/TimeMachine/[hostname].sparsebundle"
  7. Try running your backup again.
doc/howto/timemachine.txt · Last modified: 2017/03/20 00:14 by eagle-d