Sharing An NTFS External Drive On A Linux Network With NFS

Photo of Greg Harvey
Thu, 2010-05-20 12:29By greg

For my own sanity I'm blogging this, since every time I have to do it I end up jumping through the same hoops and cursing myself for not blogging it!

I have a USB external drive on one of my machines. I want it shared across the network. It's an old Windows drive formatted as NTFS. Here are the steps:

1. On the "server" install required services and applications. As root:

$ yum install nfs-utils ntfs-3g ntfs-config fuse

FUSE should be there already, but just in case. The GUI for ntfs-3g is optional.

2. Make sure the NFS services is enabled and loads on boot:

$ chkconfig nfs on
$ service nfs start

3. Edit your NFS exports:

$ gedit /etc/exports

Add this line:

/media/freeagent *(ro,sync)

Where /media/freeagent is the mount point of your USB drive, obviously.

IMPORTANT NOTE!! In spite of the manual saying the contrary, NTFS volumes with spaces in the name are *not* supported. See this thread:
http://forums.fedoraforum.org/showthread.php?p=1215256#post1215256

If this is the case, re-label your USB drive to a safe name - for an NTFS drive, you'll need this:

$ yum install ntfsprogs

For a list of formats, see this Ubuntu page:
https://help.ubuntu.com/community/RenameUSBDrive

And borrowed from there, for reference:

Check the current label

$ ntfslabel

Change the label (128 characters maximum)

$ ntfslabel

For example:

$ ntfslabel "/media/FreeAgent Drive" freeagent

4. Export your drive:

$ exportfs -a -v

5. Restart NFS on the "server":

$ service nfs restart

6. Configure your firewall on the "server". You need to open ports 111, 2049, 4001, 4002, 4003 and 4004, for both TCP and UDP in all cases:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 4001 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 4001 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 4002 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 4002 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 4003 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 4003 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 4004 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 4004 -j ACCEPT
service iptables save
service iptables restart

Now for the client machines.

7. Install nfs-utils on the "client" computers:

$ yum install nfs-utils

8. Attempt to mount the drive:

$ mount -v -o nolock 192.168.0.155:/media/freeagent /media/freeagent

9. If that works, add the drive to the list of volumes to be mounted on start-up:

$ gedit /etc/fstab

And add this line:

192.168.1.200:/media/freeagent /media/freeagent nfs defaults 0 0

Obviously, first bit is path to network drive, second is the local mount point, the rest just leave alone unless you want to read up.

Worth noting, this *could* slow client machine boot a little if the machine hosting the USB drive is off (there will be a pause while the client searches for the network drive) but in my experience any delay is not noticeable.

10. Make yourself a coffee and look smug.

Note: This will be read only - apparently writing to NTFS from the network is not safe yet with Linux. You have been warned! It is possible, but advice is to not let network computers write to NTFS volumes. Read up on using /etc/exports and /etc/fstab for options around mounted drives and reading/writing to them.

Some errors you might see:

When restarting NFS:

Starting NFS services: exportfs: Warning: /media/Drive Name does not support NFS export.

You didn't re-label your drive and it has spaces in its label!

When mounting the drive on the client:

mount: wrong fs type, bad option, bad superblock on 192.168.0.155:/media/freeagent

That sounds really scary, but it only means you forgot to install nfs-utils on the client machine(s).

No route to host

Or something similar... almost certainly a firewall problem. Try disabling the firewall on the "server" and see if you can mount the drive. If you can, then you know your firewall rules need work. Check them.