Time Machine via NFS on Mavericks

Here is my way of using nfs as time machine backup.
Avoid NFSv4 on Mavericks, it’s terribly unstable. NFSv3 is as fast as Netatalk in my environment.

1. Configure NFS server. The exports should at least have these options below.

rw,no_subtree_check,insecure,no_root_squash

2. Mounting NFS share from Mac by automount.

Create a file containing mount options. Make sure to use vers=3,resvport and locallocks, at least.

Format: “name of the mount directory you want to see in Finder” “nfs options” “nfs device directory”
e.g. vi /etc/auto_nfs
Backup -fstype=nfs,vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,
retrans=10,proto=tcp,resvport,locallocks,noacl 192.168.1.1:/srv/nfs/Mac

Edit /etc/auto_master, write mount point and filename of the text file created above.

Format: “mount point” “name of the text file you created above”
e.g. vi /etc/auto_master
/Users/Shared/NFS auto_nfs
Invoking automount.

sudo automount -vc

3. Create a disk image for time machine. Change the size to your liking, it won’t take actual space in the disk. Command below create sparsebundle image under current directory. Any volname, and sparsebundle filename is acceptable.

e.g
hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname "TimeMachine" -fs "Case-sensitive Journaled HFS+" -verbose ~/timemachine.sparsebundle

4. Move the disk image to NFS directory you mounted, and remove the local sparsebundle disk image

e.g.
rsync -avE timemachine.sparsebundle /Users/Shared/NFS/Backup/TimeMachine/
rm -rf timemachine.sparsebundle

5. Setting NFS share as time machine destination
Mount the remote sparsebundle image.
e.g.
hdiutil attach -verbose /Users/Shared/NFS/Backup/TimeMachine/timemachine.sparsebundle
Set the image as destination of time machine backup.
e.g.
sudo tmutil setdestination /Volumes/TimeMachine

6. Set sparsebundle image to be attached automatically. Probably, this step is unnecessary.
Open System Preference, Select Accounts, Select your Account, Click on Login components tab, and drag the sparsebudle image on NFS and drop it to the list.

7. Start the first backup from the GUI. I recommend using TimeMachineEditor to schedule backup if you think it’s just plain stupid to take hourly backups of home-use
laptop like me.

Disable another annoying feature of Time Machine by the command below.
sudo tmutil disablelocal

8. How to use TimeMachine in Recovery Mode
I am not sure what happens when NFS share is mounted on the MacintoshHD volume.(OS intallation partition),
so in here, I mount it on the recovery partition.

Creating mnt directory in recovery hd for mounting
i. defaults write com.apple.DiskUtility DUDebugMenuEnabled 1
ii. select show every partition in debug tab in disk utility, and mount it.
iii. mkdir /Volumes/Recovery¥ HD/System/mnt
iv. unmount the disk
v. defaults write com.apple.DiskUtility DUDebugMenuEnabled 0<

Boot into recovery mode, and mount the NFS. You might want to write a simple bash script containing these commands and place it on recovery disk for convenience.
e.g.
mount -t nfs -o vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,retrans=10,
proto=tcp,resvport,locallocks,noacl 192.168.1.1:/srv/nfs/NFS /Volumes/Image¥ Volume/System/mnt

Mount the sparsebundle image.
e.g.
hdiutil attach -verbose /Volumes/Image¥ Volume/System/mnt/TimeMachine/timemachine.sparsebundle

That’s all!
You should see your disk in TimeMachine GUI.
Don’t close the lid during recovery, otherwise it pauses.
Please leave a comment if you have any better option.