Home > Tutorial > Mac OS X Time Machine via NFS on Linux Ubuntu (Complete Guide, fixes error 13, etc)

Mac OS X Time Machine via NFS on Linux Ubuntu (Complete Guide, fixes error 13, etc)

January 30th, 2011

Mac OS X Time Machine is very powerful backup application. The simplified interface is great for day-to-day Mac users but doesn’t provide a lot of insight into errors when they rarely happen. Also the idea of physically attaching a external device, or buying a airport / time capsule don’t seem like a fun idea. So I set out to use my home’s Ubuntu media server as the remote HD using NFS. The road was filled with potholes and detours. I’ve documented the steps and a few ‘Ah HA’ moments that hindered me.

Requirements:

  • Mac OS X device (MacBook Pro, MacBook Air, Mac Pro, ect). Used below: Mac Air, OS X 10.6.6
  • Linux desktop/server edition. (Ubuntu, CentOS, Gentoo, Fefora, Debian). Used below: Ubuntu Alternative 10.10
  • Somewhat understanding of general networking
  • Some experience/knowledge of linux command line

Introduction:

During this article, The internal IP address of my Mac OS X device will be 11.1.1.10 and will be called ‘MacAIR‘, while my Ubuntu media server will be 11.1.1.100 and will be called ‘Ubuntu‘. The general idea is we want to backup to the hard drive on the linux server via NFS (network file system) that will auto mount every time the backup starts.

Ubuntu Instructions:

Dependencies:

1
sudo apt-get install nfs-kernel-server portmap

Setting up NFS exports:

So to be able to mount a drive via NFS we need to tell NFS which mount points will be available and what rules on who can connect. So declaring there mounts is done in /etc/exports. So we open this in our editor of choice (vi, emac, nano) and write a rule like below:

1
/backup       11.1.1.10(rw,sync,insecure)

The syntax of this line broken down is “<mount point> (tab) <IP/host ACL>(options)“. You will notice that I have selected for insecure in the options which will allow port connections via a port number greater than 1024, without this option just mounting the drive will become difficult from a Mac OS X environment. For the IP/host ACL options, you can specify 11.1.1.0/24 for all IPs in that block, but for my network I have multiple backup partitions for each user so I limit them directly to the target IP.

At this point lets tell NFS about the new configurations:

1
sudo exportfs -a

And for good measure, restart the whole NFS subsystem:

1
sudo /etc/init.d/nfs-kernel-server restart

Confirming everything is configured properly:

1
rpcinfo -p | grep nfs

Should result in something similar:

1
2
3
4
5
6
100003    2   tcp   2049  nfs
100003    3   tcp   2049  nfs
100003    4   tcp   2049  nfs
100003    2   udp   2049  nfs
100003    3   udp   2049  nfs
100003    4   udp   2049  nfs

Also you can test this from a remote machine as well:

1
rpcinfo -p 11.1.1.100 | grep nfs

If you don’t get similar to the above, I would double check your /etc/exports as well any firewall applications that may be hindering connections via UDP on port 2049. On Ubuntu systems the firewalls of choice are ufw and iptables. You can configure ufw via a handy simple application called ‘gufw‘ which you can in your main menu under System -> Preferences and installed by executing this command:

1
sudo apt-get install gufw

Also if your on a headless machine you can configure the firewall from command line easily ie:

1
sudo ufw allow 2049/udp

Extended Attributes Support:

One of the big gotcha moments in this process and really overlooked is the sparsebundle disk image that MacOSx uses to backup into will require extended attributes to work properly. I followed three different articles on similar setups and none of them identified this as a requirement. After fighting with Time Machine for a few hours I identified the necessity for extended attributes to be enabled for this hack to work properly.

Configuring:

To enable xattr we will need to modify our fstab which is what tells the OS on boot up which partitions to mount where. We will find this file at /etc/fstab. So again lets fire up our favorite editor (vi, emac, nano) and dive right in.

My fstab line:

1
UUID=c72e288a-3caa-4d0e-b6a5-2547174464a6 /backup         ext4    defaults,user_xattr,acl        0       2

So you will need to identify which partition / line is where you need to enable xattr. To do this an easy way is to call df on the folder in question, so if your folder was /backup you would execute:

1
df -h /backup

Result:

1
2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdc2             459G  118G  318G  28% /backup

So that output will tell you to look for the mount point /backup in your /etc/fstab.

Your fstab line will look below without xattr:

1
UUID=c72e288a-3caa-4d0e-b6a5-2547174464a6 /backup         ext4    defaults        0       2

So we need to modify the line to like so:

1
UUID=c72e288a-3caa-4d0e-b6a5-2547174464a6 /backup         ext4    defaults,user_xattr,acl        0       2

The syntax of the fstab lines are “<device/uuid> (tab) <mount point> (tab) <filesystem type> (tab) <options> (tab) <boot order numbers>“. You need to make sure that your add “,user_xattr,acl” to the “<options>” section of the line.

Depending on whether or not you’ve just modified the root filesystem “/“, you will need to reboot the machine for xattr to be enabled. If you’ve used a separate partition like me “/backup” you can just unmount and remount the partition:

1
sudo umount /backup; sudo mount /backup;

If you get an error about Device/Resource is busy instead of tracking down the source with “lsof” the faster solution would be to just issue a reboot.

MacAIR Instructions:

Now you may think we should be able to just mount the NFS and select the Volume in Time Machine and be done. Sorry but its not that simple (*hint hint* Apple). We will need to prepare a Sparse Bunde Disk Image for Time Machine to back up into on the NFS mount. To do this we will need to collect some information first.

Hostname / Machine Name:

One of the finicky aspects of this process is that if you have a fancy host/machine name creating your initial backup may be difficult. So first thing I recommend is reducing your machine name from “John Doe’s MacBook Pro” to something more like “JohnDoe“. Removing the spaces and quotation will make the success more likely of the backup. Don’t ask me why, but spaces are your enemy. Personally I recommend a more obscure name like “WindowsWirelessAuthenticationAgent” or “Airport“. For the rest of the tutorial MacAIR‘s machine name will be Airport

To change your machine name, you open “System Preferences” then click “Sharing“. In the first text field labeled Computer Name: change the value to the new computer name and note its exact spelling. We will need it soon.

Getting your en0 MAC Address:

The second piece of data off MacAIR is the en0 MAC address. Your MAC address is like your IP on the internet in an a 6 piece hex that is meant to identify specifically your wired/wireless hardware. I warn you that they shouldn’t ever be used for security purposes as they can be spoofed and changed easily.

1
ifconfig | grep en0 -B 1 | grep ether | awk '{print $2}' | sed 's/://g'

Result:

1
1093e903bcea

Note this is your MAC address. We will need it in the next step.

Backup Image Creation:

For our second to last task we will need to prepare a Sparse Bundle Disk Image (mouthful) that is really just a encapsulated (zip, tar) compression. We need to know how much space we want to backup.

How much backup space?

My rule of thumb is 4-6x your current usage.

I’ll provide you a command to easily get that amount: (Warning: This only works if you have less than TB of hard drive space.)

1
df -h | grep -e '/$' | awk '{print $3}' | sed 's/Gi//g' | xargs -I {} echo '({} * 4)' | bc -l

Basically I take your used space, times it by 4 above.

Result:

1
256

So we will need a disk image of at least 256 GBs. This number is for my MacAIR with Xcode, Komodo, Office Suite, and various other apps installed. Most of my large files are on various servers in the Cloud so my number may be small compared to yours depending on how much space you’ve used.

Disk Image Creation:

Now let’s take the information we’ve collected already prepare to make the disk image. Using my information I’ve collected my command looks like so:

1
sudo hdiutil create -size 256g -type SPARSEBUNDLE -nospotlight -volname "Backup of Airport" -fs "Case-sensitive Journaled HFS+" -verbose ~/Airport_1093e903bcea.sparsebundle

Syntax: sudo hdiutil create -size <size>g -type SPARSEBUNDLE -nospotlight -volname “Backup of <computer_name>” -fs “Case-sensitive Journaled HFS+” -verbose ~/<computer_name>_<mac address>.sparsebundle

<size> is the backup disk space we calculated.

<computer_name> is the Computer Name we assigned earlier in Sharing.

<mac address> is the mac address you got from the command above.

This may take a while depending on how big your backup image is. Go get a cup of coffee.

Mounting the NFS from Mac OS X:

Open Finder. Click Go -> Connect to server…
Enter in nfs://11.1.1.100/backup.
This should mount NFS and show a new Volume in Finder

Moving the SparseBundle Image to NFS:

So we’re almost done. Lets move the file to its destination:

1
rsync -avE ~/Airport_1093e903bcea.sparsebundle /Volumes/backup/

You may need to modify the final path /Volumes/backup/ to match your mount point.

Telling Time Machine To Access Alternative Storages:

You need to run this command as your user, not sudo!

1
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Great Success!

Now you can go to System Preferences -> Time Machine and click Select Disk You should see your NFS mount now. Select the disk and let it verify the backup. A dialogue will appear about using this volume. Select Ok. And now sit back and enjoy knowing your Mac is being backed up completely!

References:

Level of Indirection

ReadyNAS

Tutorial , , , , , , ,

  1. January 30th, 2011 at 23:28 | #1

    FWIW you could also use netatalk to share a volume with AFP, then use Avahi to announce it so it appears in Finder. I have multiple Macs backing up to a volume shared thusly from my Ubuntu 10.04 (Lucid) fileserver. There are various guides out on the web for how to modify netatalk’s config files to produce AFP shares that Snow Leopard is happy to talk TimeMachine to :)

  2. T
    January 31st, 2011 at 04:58 | #2

    its a nice idea but what if your local hard drive fails (unlikely but we know it happens…)?
    a fresh installed mac osx will not recover in the install process from nfs… thats the only reason i personally got the time cap. – everything fails -> recover from capsula. done.

  3. Colibri
    February 11th, 2011 at 19:49 | #4

    Why do you say that “acl” and “user_xattr” options have to be enabled for the filesystem?

    • February 13th, 2011 at 15:38 | #5

      Because without it Time Machine would report the backup was corrupt and want to recreate the sparesbundle (Error 23 or 22, can’t recall specifically). Also while rsyncing and using the preserve flag it reports that it is unable to modify the data.

  4. Dave
    July 22nd, 2011 at 23:31 | #6

    Outstanding! Thanks for the great info.

  5. Mark
    July 23rd, 2011 at 13:11 | #7

    I’m getting error 23 when moving the sparsebundle image to NFS. Also, I can see but not write any files to the NFS share from my Mac after I’ve mounted the NFS share in Finder. I’ve checked everything and have followed your tutorial precisely except for my etc/fstab file, which has these lines for my hard disks (sdb1 is being used for timemachine backups)

    UUID=a671c672-0f89-419e-8e7e-b079b4716168 / ext4 errors=remount-ro,user_xattr 0 1
    /dev/sdb1 /timemachine ext4 defaults,user_xattr,acl 0 2

    The permission in /timemachine is user, not root.

    Can you please give me any clues what the problem could be?

    • July 28th, 2011 at 05:28 | #8

      Sounds like you dont have write permissions on the NFS export. Check the server nfs mount point.

  6. Mark
    July 23rd, 2011 at 13:17 | #9

    Here is the error message in Mac Terminal:

    rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-40/rsync/main.c(992) [sender=2.6.9]

  7. November 14th, 2011 at 18:04 | #10

    Andy, thanks for the comprehensive guide. I followed all your steps and at the end, I could see the disk from my Time Machine. However, when I try to do the backup, the following error:

    “The network backup disk does not support the required AFP features.”

    I’m using Lion and after a quick Google search its my understanding that under this OS there was a change on the protocol on OSX side. Do you have it working under Lion by any chance? Any suggestions? Thanks again Andy.

    • November 29th, 2011 at 00:15 | #11

      I haven’t upgraded to Lion on the machines that utilize this backup structure in our network. Once I do, I’ll be happy to post an update.

  8. es
    November 28th, 2011 at 22:52 | #12

    Thanks!
    Its are great article!

    But for me needed to add in /etc/exports two options:
    subtree_check – just for no warning at startup
    no_root_squash – allow root permissions on files to fix error 13 then TM remounting share

  9. slamp
    December 4th, 2011 at 21:23 | #13

    It’s not working in lion (error 45). I will try with netatalk instead of nfs

    • December 4th, 2011 at 23:18 | #14

      That is true from what I’m being told from my readers. I haven’t upgraded to lion, to update this article.

      Just to reiterate the articles requirements, this is for 10.6 Mac OS X.

  10. Forrest
    January 31st, 2012 at 01:37 | #15

    I don’t believe this will work on Lion :-( This is the 3rd time I’ve tried. Netatalk seems like a good alternative, although it appears to be a bit complicated to set up. This NFS method would have been ideal for my use.

  11. Matt McLaughlin
    January 31st, 2012 at 23:10 | #16

    Guide worked like a charm. I use a Freebsd server with native ZFS and xattr is already on.

    Cheers!

  12. Brian
    February 17th, 2012 at 13:40 | #18

    Agree with es, needed to set the no_root_squash on the nfs export and then it worked like a champ. Without this option I kept getting (error 13) when the backup tried to start

  13. Nina
    July 6th, 2012 at 07:40 | #19

    Thanks, great guide!
    the ifonfig-commandline should read with after (not before) as:
    ifconfig | grep en0 -A 1 | grep ether | awk ‘{print $2}’ | sed ‘s/://g’
    I had problems mounting the nfs-volume as the mac asks the nfs-server on an insecure port, using the option insecure in /etc/fstab for the backup-partition helped.

  14. Nina
    July 6th, 2012 at 15:41 | #20

    @Nina
    sorry, insecure should be set in /etc/exports as you wrote above

  15. July 13th, 2012 at 00:39 | #21

    Thanks for posting these instructions! I ran into a few problems with them on Mac OS X 10.6.8 because there are multiple users of our Mac, and I think that might make a difference. I fixed these problems as follows:

    1. Use Disk Utility to set up the mount point instead of using Go | Connect to Server…. In particular:

    a. Launch Applications | Utilities | Disk Utility
    b. Go to File | NFS Mounts…
    c. Create the mount-point there.

    2. When doing the rsync to copy the sparse bundle to the NFS directory, use “sudo rsync” instead of “rsync”, so the bundle will be copied over with the same owner that Time Machine will use when doing backups (since presumably Time Machine runs as root).

    In addition, I made a few other changes that seemed like a good idea:

    1. I specified “locallocks” as an advanced option when creating the mount in Disk Utility. Since the Mac will be the only thing editing the files in the sparse bundle, there’s no need to do locking on the NFS server.

    2. I specified “sync” as an advanced option when creating the mount (i.e., with the point above, I specified “locallocks,sync” as the advanced options). This makes the backups take a little longer but makes it much less likely that the sparse bundle will get corrupted and have to be repaired or rebuilt.

  16. Nina
    January 24th, 2014 at 19:39 | #22

    If you have problems with this tutorial for Mountain Lion 10.8+ (for 10.6.8 it works perfectly), see this nice guide here:
    http://smekkley.wordpress.com/tag/incompatible-file-system-type-nfs-error-45/

  1. January 30th, 2011 at 22:22 | #1
  2. January 30th, 2011 at 22:57 | #2
  3. January 31st, 2011 at 01:30 | #3
  4. January 31st, 2011 at 01:40 | #4
  5. January 31st, 2011 at 03:40 | #5
  6. January 31st, 2011 at 05:44 | #6
  7. February 1st, 2011 at 15:11 | #7
  8. February 1st, 2011 at 15:14 | #8