NSLU2-Linux
view · edit · print · history

For those of you running Leopard, you can use your NSLU2 as a backup drive for Time Machine, effectively making a "Time Capsule". Unfortunately there is a little bit of work required to get it going, but once it is set up it runs pretty well.

UPDATE: Read the additional section on AFP (Apple Filing Protocol). Running Time Machine backups over AFP seems to work a lot better than over Samba (SMB).

UPDATE Again: There are some issues with the sparsebundle on Snow Leopard (10.6.x). My Time Machine continued working after an upgrade from Leopard to Snow Leopard, but when trying to set this up from scratch on Snow Leopard, it did not work. See http://www.macosxhints.com/article.php?story=20090905212640957(approve sites) for information on how to get this working on Snow Leopard.

I am running Unslung 6.10. I'd imagine that this would work on just about any of the possible OS choices out there, even the stock Linksys firmware, but I haven't tested it, so YMMV.

Basic Setup with Samba (SMB)

The first step is to gather information about your system that we will need later:

  • Open System Preferences
  • Click on "Sharing"
  • Note the "Computer Name"
  • Open a terminal window in OSX
  • Run the command "ifconfig en0 | grep ether"
  • This will produce a line similar to the following:
    ether 00:1a:45:bc:23:1a
    
  • Combine the Computer Name and the ether address (without the ":"s) to create the backup identifier name as such:
    "hostname_macaddr"
    
For example,
"MacBook_001a45bc231a"

The next step is to create a disk image to use for the backups, which will be created on your mac and then moved later to your NSLU2 disk:

  • Open a terminal window
  • Change into your desktop directory: "cd ~/Desktop" (or whatever directory you want to create the backup file)
  • Run the following command, and change the "size" parameter to be the maximum size of the backup, and change the name of the sparsebundle file to match the identifier we came up with earlier:
hdiutil create -size 140g -fs HFS+J -volname "Backup Drive" MacBook_001a45bc231a.sparsebundle

The final step is to copy the sparsebundle to your NAS and configure Time Machine:

  • Copy the sparsebundle we just created from your desktop to a share on your NSLU2. I created a share that only contained the sparsebundle, so I don't know if you can put the file in a share with other files.
  • If you have OS X 10.5.2 or later then you DON'T need to do this step (skip to the next step). Enter the following command into the terminal window:
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
  • Open the network share that you copied the sparsebundle file to
  • Double click on the sparsebundle file to mount it
  • Open System Preferences
  • Click Time Machine
  • Turn Time Machine on if it isn't already
  • Click on "Change Disk"
  • Select the mounted backup disk

Advanced Setup with Samba (SMB)

This hint is for more advanced users of Samba. If you're not comfortable with the theory and instructions below, take a look at the next section, "Alternate Setup with AFP (Apple Filing Protocol)".

As noted in GettingStartedWithSamba in the "Transfer Speeds with Many Files in the Same Directory" section, Samba is very slow when you have many files in the same directory. This is what Time Machine does, so Time Machine backups are very slow.

There is a way to speed things up: turn off case sensitivity in Samba, and rename all your files to be upper- or lower-case. For instructions and more info, see http://www.samba.org/samba/docs/man/Samba-Guide/HA.html#id403899

You need to be running OpenSlug, or Unslung, or anything that's not the stock firmware.

To do this for your Time Machine share, try the following:

  • Create a shared directory that is dedicated to Time Machine.
  • Follow the instructions in the above section to create your .sparsebundle and copy it to the shared directory.
  • Perform your first backup. It will be very slow, so give it a day or so to complete...
  • Whilst you're backing up, connect to your NSLU2 via "ssh" and issue the "top" command. Notice that the Samba process is taking up 98% of the CPU, pegging it.

OK, so now we have your first backup! It's slow, but we know that it works. Here's how to speed things up:

  • Connect to your NSLU2 via ssh.
  • Edit your Samba configuration file. For your shared directory only, set these options:
    case sensitive = True
    default case = upper
    preserve case = no
    short preserve case = no
  • You don't want these options for your "regular" share! That's why we make them specific to your Time Machine shared directory.
  • Whilst still ssh'ed into your NSLU2, cd to your shared directory, e.g. cd /media/sda1/TM
  • Get a directory listing with ls -la
  • Now here's the tricky part. We want to rename all these files to lower-case, and put zero-byte placeholder files in their place.
  • Let's say you have the following:
    $ ls -la
    total 4
    drwxr-xr-x 1 smbuser smbuser    0 Nov 15  2007 .
    drwxr-xr-x 1 smbuser smbuser    0 Jan  1  1970 ..
    -rwxr-xr-x 1 smbuser smbuser    0 May 23 12:25 .MacBook_001a45bc231a.sparsebundle
    drwxr-xr-x 1 smbuser smbuser    0 May 23 12:25 MacBook_001a45bc231a.sparsebundle
  • Now you issue the following commands:
    mv .MacBook_001a45bc231a.sparsebundle .macbook_001a45bc231a.sparsebundle
    mv MacBook_001a45bc231a.sparsebundle macbook_001a45bc231a.sparsebundle
    touch .MacBook_001a45bc231a.sparsebundle
    touch MacBook_001a45bc231a.sparsebundle
  • See what we've done? We renamed the existing files to lower-case, and put zero-byte placeholders in their place. Now you get:
    $ ls -la
    total 6
    drwxr-xr-x 1 smbuser smbuser    0 Nov 15  2007 .
    drwxr-xr-x 1 smbuser smbuser    0 Jan  1  1970 ..
    -rwxr-xr-x 1 smbuser smbuser    0 Jun 30 11:00 .MacBook_001a45bc231a.sparsebundle
    -rwxr-xr-x 1 smbuser smbuser   16 May 23 12:25 .macbook_001a45bc231a.sparsebundle
    -rwxr-xr-x 1 smbuser smbuser    0 Jun 30 11:00 MacBook_001a45bc231a.sparsebundle
    drwxr-xr-x 1 smbuser smbuser    0 May 23 12:25 macbook_001a45bc231a.sparsebundle
  • Do the same with the files inside the macbook_001a45bc231a.sparsebundle directory.
    $ cd macbook_001a45bc231a.sparsebundle
    $ ls -la
    total 6
    drwxr-xr-x 1 smbuser smbuser    0 Nov 15  2007 .
    drwxr-xr-x 1 smbuser smbuser    0 Jan  1  1970 ..
    -rwxr-xr-x 1 smbuser smbuser  510 May 23 12:25 Info.bckup
    -rwxr-xr-x 1 smbuser smbuser  510 May 23 12:25 Info.plist
    drwxr-xr-x 1 smbuser smbuser    0 May 23 12:25 bands
    -rwxr-xr-x 1 smbuser smbuser 1276 May 23 12:25 token
  • Rename the files and create placeholders:
    mv Info.bckup info.bckup
    mv Info.plist info.plist
    touch Info.bckup
    touch Info.plist
  • And now you get
    $ ls -la
    total 6
    drwxr-xr-x 1 smbuser smbuser    0 Nov 15  2007 .
    drwxr-xr-x 1 smbuser smbuser    0 Jan  1  1970 ..
    -rwxr-xr-x 1 smbuser smbuser  510 May 23 12:25 info.bckup
    -rwxr-xr-x 1 smbuser smbuser    0 Jun 30 11:05 Info.bckup
    -rwxr-xr-x 1 smbuser smbuser  510 May 23 12:25 info.plist
    -rwxr-xr-x 1 smbuser smbuser    0 Jun 30 11:05 Info.plist
    drwxr-xr-x 1 smbuser smbuser    0 May 23 12:25 bands
    -rwxr-xr-x 1 smbuser smbuser 1276 May 23 12:25 token
  • And you're done! You should be able to perform another backup and have it work a lot faster this time.
  • Whilst you're backing up, connect to your NSLU2 via "ssh" and issue the "top" command. Notice that the Samba process is taking about 30% of the CPU, much more reasonable.

So, how does it work? Here's how:

  • Your Mac asks for a directory listing.
  • Samba says, we have "info.bckup", "Info.bckup", "info.plist", "Info.plist", "bands" and "token".
  • Your Mac says, ooh, give me "Info.plist".
  • Samba returns the contents of "info.plist", since it's set up for case-insensitive file lookups. (That's the fast way.)

Alternate Setup with AFP (Apple Filing Protocol)

I've found that Time Machine backups work much better over AFP. They run much faster and appear to be a little more reliable and tolerant to interruptions (like putting the computer to sleep). So if you have an unslung box, I'd recommend going this route. For my setup, I don't configure any user security. Some forums mention difficulties with getting user security to work with the NSLU2 and since my setup doesn't require it, I didn't try it. These instructions are for Unslung 6.10, but I'd imagine they apply to most distributions other than the stock linksys firmware.

  • Install the netatalk package
ipkg install netatalk
  • Edit the /opt/etc/netatalk/AppleVolumes.default file and add the following line at the bottom. You may need to adjust the line to point to the directory you want to share out as your Time Machine backup drive.
/share/flash/data/public "Time Machine"
  • Edit the /opt/etc/netatalk/afpd.conf file and add the following line at the bottom.
"Time Capsule" -uamlist uams_guest.so
  • You need to implement some way to start the AFP daemon on startup. I do this by launching it from an /unslung/rc.local script. Here are instructions on how to do this:
* Create or edit /unslung/rc.local in your favorite editor
* At a minimum have the following lines in your file:
#!/bin/sh

# Start afpd
/opt/sbin/afpd
return 1
* Make the file executable by running
chmod 755 /unslung/rc.local

Reboot, and AFP should be running. Place your sparsebundle file in the shared directory, and follow the remaining directions in the "Basic Setup with Samba" section.

Supplement for Plug Computers

UPDATE: SlugOS users should create a symbolic link (ln -s) from the start files from /opt/etc/init.d/ to /etc/rc3.d/ for the files to be executed on boot.

UPDATE: To get avahi working, it likes to have ip at 169.254 so in some script before avahi is called, you need:

ifconfig eth0:0 169.254.xxx.xxx netmask 255.255.0.0 broadcast 169.254.255.255 # Setup eth0 interface for avahi.

It needs this for all interfaces if you have more than eth0. The ip #s must be different. You can also get udhcpc to do this automatically. You can also set up avahi to disregard some interfaces.

This supplement should work for most plug computers (Pogoplug V1, V2, Pro, Biz, Dockstars, etc.). Please see warnings in Optware installation since it pertains to this. It is based on the work of Seongbae and the above articles. What you end up with is a network time machine which appears to be quite authentic (like a Time Capsule) since it uses Avahi so the drive will show up in the sidebar. This will not work with a root password to log into the Time Machine.
You should use a new hard drive formatted in ext2/ext3 depending if you want a journaled file system (recommeded). It will be mounted on "/tmp/timemachine". I have tested this with a username with spaces. If you install a package and there are errors/warnings, take care of this or the install will not work. I had to rename a file in a directory under "/opt/etc/" to do this.

 "ipkg install netatalk"
"ipkg install libgcrypt" This is needed for authentication.
"ipkg install dbus"
"ipkg install avahi"

We need to set up some users and groups. If I use a group or user number that is used, choose another one. You can verify with "cat /etc/passwd" or "cat /etc/group".

 "addgroup -g 84 avahi"
"adduser -g 84 -H -D -G avahi avahi"
"addgroup netdev" Not really needed but did not want to edit dbus file.
"adduser someusername" Replace someusername with what you want.

We will use afppasswd to create an afp password for someusername for authentication. The utility afppasswd checks /etc/passwd to make sure that the username you use exists. If there is no afppasswd file in /opt/etc/netatalk, afppasswd will error out.

 "cd /opt/etc/netatalk"
"touch afppasswd"
"afppasswd -a someusername"

If you want to use your OSX username which probably contains spaces. You can do this by using quotes (adduser "Some User Name" and afppasswd "Some User Name").

Time to edit some config files.
Just like the preceding section. Edit the "/opt/etc/netatalk/AppleVolumes.default" file and add the following line at the bottom (The options:tm is so that your Mac will treat the Plug like a Time Machine).

 "/tmp/timemachine "Time Machine" options:tm"

Unlike the preceding section, do not edit the afpd.conf. In fact make sure that there are no functional lines and everything is commented. The authentication will default correctly.

 "cd /opt/etc/dbus-1/system.d/"

Verify that the "/opt/etc/dbus-1/system.d/avahi-dbus.conf" file exists and contains:

 <!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>

We will now change to "/opt/etc/avahi/services/" directory and create an afpd.service file which should contain:

 <?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>

We need to edit "/opt/etc/avahi/avahi-daemon.conf" and add an entry for "host-name=PlugTime", where PlugTime is whatever you choose to name your Time Machine host plug (try to make it different from your current hostname - "uname -n"). Uncomment "enable-dbus=yes".
Change to the "/opt/etc/default" to create the file "avahi-daemon" which should have one entry "AVAHI_DAEMON_START=1".
Create the "/tmp/timemachine" directory with "mkdir /tmp/timemachine" and mount your ext2/ext3 drive that you want to use for the Time Machine back-up. Then, Create an empty file named ".com.apple.timemachine.supported" in the top directory of the drive with "touch .com.apple.timemachine.supported" in the top directory.
Change to the "/opt/etc/init.d" subdirectory and create two start files. There should be a start file for dbus, but none for avahi and afpd. The one for dbus "S20dbus" needs modification to work properly. So edit "S20dbus" and make the modification below:

 shut_it_down()
 {
  echo -n "Stopping $DESC: "
  if [ -e $PIDFILE ]; then
    PIDNUM=`cat $PIDFILE`
    rm -f $PIDFILE
    kill $PIDNUM
  else
    killall ${DAEMON}
  fi
  echo "$NAME."             
  rm -f $PIDFILE
 }

Create this start file "S52avahi" for avahi:

 #!/bin/sh

 #start avahi-daemon
 /opt/sbin/avahi-daemon -D
 return 1

Create this start file "S81afpd" for afpd:

 #!/bin/sh

 # Start afpd
 /opt/sbin/afpd
 return 1

Create a script "mount_tm" (based on Openpogo mount_opt) in "/opt/sbin" to mount the proper drive in "/tmp/timemachine", give it full access, and run the scripts. If you want to use a journaled file system drive, substitute ext3 for the ext2. Of course making sure that your drive is ext2 or ext3 correspondingly:

 #!/bin/bash
 #
 mkdir /tmp/timemachine
 mount -t ext2 -o rw,nosuid,nodev,exec,noatime,sync /dev/sda1 /tmp/timemachine
 if [ ! -f /tmp/timemachine/.com.apple.timemachine.supported ]
 then
 {
  umount /tmp/timemachine
  mount -t ext2 -o rw,nosuid,nodev,exec,noatime,sync /dev/sdb1 /tmp/timemachine
  if [ ! -f /tmp/timemachine/.com.apple.timemachine.supported ]
  then
  {
   umount /tmp/timemachine
   mount -t ext2 -o rw,nosuid,nodev,exec,noatime,sync /dev/sdc1 /tmp/timemachine
   if [ ! -f /tmp/timemachine/.com.apple.timemachine.supported ]
   then
   {
    umount /tmp/timemachine
    mount -t ext2 -o rw,nosuid,nodev,exec,noatime,sync /dev/sdd1 /tmp/timemachine
    if [ ! -f /tmp/timemachine/.com.apple.timemachine.supported ]
    then
    {
    umount /tmp/timemachine
    }
    else
    {
      umount /tmp/.cemnt/mnt_sdd1
    }
    fi
   }
   else
   {
     umount /tmp/.cemnt/mnt_sdc1
   }
   fi
  }
  else
  {
    umount /tmp/.cemnt/mnt_sdb1
  }
  fi
 }
 else
 {
   umount /tmp/.cemnt/mnt_sda1
 }
 fi
 /bin/chmod 777 /tmp/timemachine 

 rm -f /opt/var/run/dbus/pid
 /opt/etc/init.d/S20dbus start
 /opt/etc/init.d/S52avahi
 /opt/etc/init.d/S81afpd

On all the scripts, make sure to set the permissions so that they are executable with "chmod 755 scriptname" where scriptname is the name of the script. You can then include "mount_tm" in the "/etc/init.d/rcS" start up script so that it will be executed on start up. When you shut down your plug computer or reboot, it would probably be a good idea to kill the processes and umount the drive.
When you first connect to the Plug Time Machine, it may take a few seconds longer since afpd is writing some resource files onto the drive. The drive should show up under shared of the finder because of avahi. If it does not, time to do some debugging. Once the drive is mounted, you can go into your time machine settings and select it as a backup. The first backup could take a while since it is the whole volume. To restore, follow directions below. Keep in mind that while backing up is pretty effortless, restoring can be tricky, even with a volume directly connected to your Mac. There have been issues with restoring Mail, iTunes, and other applications.

How To Restore To New Disk

This howto is great, but it was lacking a section on how to do a restore to a brand new drive. This section isn't needed if you are just restoring an old copy of a file to an already running system, but if your HDD crashed (like mine did!), you have to do a few special steps to be able to restore from your time machine.

After you have replaced the faulty hardware and have booted your mac from the install disk, you will be at a menu that lets you do a few basic things (disk util, terminal, etc...). Before selecting to restore from a time machine, you have to manually mount the time machine volume since its not a locally attached volume. Make sure you are connected to the network. If you are using wired network, the install disk has likely already obtained a DHCP IP and you are good. If you choose to go the (slower) wireless route, connect using the wireless icon at the top right of the screen, then proceed below.

The following commands assume you used the AFP method above. I haven't tried, but switching the mount command to mount an smb volume should be all that's needed if you used smb instead. Start a terminal section by selecting Terminal from the tools menu.


mkdir /Volumes/TimeMachine
mount -t afp "afp://<nslug_ip>/Time Machine" /Volumes/TimeMachine

And thats it! Exit out of terminal, and select restore from time machine and it should detect your time machine backup disk created above. You will be asked to pick a destination volume, so make sure you have already partitioned your new disk.

Happy restoring!

view · edit · print · history · Last edited by BLorenzo.
Based on work by BLorenzo, Scheb, OddballHero, Mike Machado, mkurtz, and Smee Jenkins.
Originally by mkurtz.
Page last modified on December 17, 2013, at 09:44 AM