Mount a Remote Drive via NFS

From AwkwardTV

Jump to: navigation, search

Contents

Overview

NFS is a file sharing method, like SMB or AFP. You can combine mounting with ATVFiles to view files on a server with an AppleTV-like experience.

You would probably pick NFS over SMB if you don't have devices that don't support it well (like Windows computers).

Installing support

AppleTV software 1.0

Mounting NFS shares on APTV software 1.0 works "out of the box"

Later versions

For later versions of AppleTV software, you need to obtain the /sbin/mount_nfs file and place it on the AppleTV.

This is similar to the process for mount_smbfs, although it doesn't require kernel extensions, so is less complicated.

You will have to already enabled SSH access on your AppleTV.

Using a SCP/SFTP client, copy MacOSXUpdCombo10.4.9Intel.dmg to the AppleTV. The location doesn't matter, but the steps below assume /Users/frontrow/Documents

SSH to the AppleTV and mount the DMG:

sudo -s
SOURCE='/Users/frontrow/Documents'
hdid /$SOURCE/MacOSXUpdCombo10.4.9Intel.dmg
cd /
pax -r -z -f /Volumes/Mac\ OS\ X\ 10.4.9\ Combined\ Update\ \(Intel\)/MacOSXUpdCombo10.4.9Intel.pkg/Contents/Archive.pax.gz \
  './sbin/mount_nfs'
umount /Volumes/Mac\ OS\ X\ 10.4.9\ Combined\ Update\ \(Intel\)/

Mounting

You need a folder to act as a mount point - the place that the NFS server's files will appear. The folder can be anywhere; for this example, we'll make it /Users/frontrow/Remote.

You can do this with an SCP/SFTP client or using SSH:

mkdir /Users/frontrow/Remote

Then, you should test your mount:

sudo mount_nfs mediaserver.local:/mediafiles /Users/frontrow/Remote

You should now be able to see your server's files.

If you get an error, you may have to tweak the options on your server or on the client (mount_nfs man page). Often, the problem is related to the resvport option, especially when connecting to a Linux server, for example: sudo mount_nfs -o resvport mediaserver.local:/mediafiles /Users/frontrow/Remote

Your test mount will go away when you reboot (or when you issue sudo umount /Users/frontrow/Remote).

Mount on Startup

You should mount shares on startup if you want to depend on them being there.

StartupItem

This method of using a StartupItem is similar to that used for mount_smbfs, although it doesn't require kernel extensions, so is less complicated.

SSH into the appletv, and issue the following set of commands to create the necessary folders and scripts:

sudo -s
mkdir /System/Library/StartupItems/MountShares
cd /System/Library/StartupItems/MountShares
cat > MountShares <<END
#!/bin/sh
. /etc/rc.common
 
# The start subroutine
StartService() {
    mount_nfs "mediaserver.local:/mediafiles" /Users/frontrow/Remote
}

# The stop subroutine
StopService() {
    umount /Users/frontrow/Remote
}

# The restart subroutine
RestartService() {
   umount /Users/frontrow/Remote
   mount_nfs "mediaserver.local:/mediafiles" /Users/frontrow/Remote
}

RunService "$1"
END
chmod a+x MountShares
cat > StartupParameters.plist <<END
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
    <dict>
        <key>Description</key>
        <string>Mount Shares</string>
        <key>OrderPreference</key>
        <string>Late</string>
        <key>Provides</key>
        <array>
                <string>Network Shares</string>
        </array>
        <key>Uses</key>
        <array>
                <string>Network</string>
        </array>
        <key>Requires</key>
        <array>
                <string>Network</string>
        </array>
    </dict>
</plist>
END

If you would like to understand what's going on, here's some reference material:

/etc/rc.local

Note: there seems to be some disagreement on whether this works.

ATV v1.1 (not the safe update) seems to ignore /etc/rc.local

You might want to try adding this to your rc.local file to make it happen every time you reboot. So:

sudo echo "mount_nfs  ipaddress:/share /mnt/remoteshare/">>/etc/rc.local

that adds the first line to the end of the rc.local file which is run every time the system boots.

For some reason this doesn't always work and in some cases the rc.local file doesn't exist. A way around it is to use su. su is a rather dangerous command as it effectively allows you to log in as root so use it wisely!

Copy /usr/bin/su from your local OS X installation to the same location on the AppleTV.

Then issue these commands

sudo su -

touch /etc/rc.local

echo "mount_nfs  ipaddress:/share /mnt/remoteshare/">>/etc/rc.local

This will log you on as root, create the file (only if it doesn't exist), add the changes to it. You can then check the changes have been made by typing:

cat /etc/rc.local

and checking the last line in the file.

Once you're happy, issue this simple command to exit the root shell:

exit

Note: if you don't have a local OS X machine, you can type

sudo bash

instead of

sudo su -

Note: Recently the automatic mounting stopped to work and I figured out, that a pause of 5 seconds before the mount command in /etc/rc.local helps.

sleep 5
Personal tools