Update: This post has been updated based on comments by users. See comments for more details.
I realize that this might be something understood by many people but last night I went to set it up and realized I needed some documentation. The documentation that I did find was rather limited so I thought I would put together a quick tutorial for setting up NFS on an Ubuntu system.
For those that aren’t familiar with NFS here is a quick breakdown of what it might be used for.
- Commonly used data can be stored centrally over an NFS share and accessible by networked machines.
- Centrally store user /home directories on an NFS share allowing them to take their user settings with them on any locally networked machine.
- Centrally share CDROM drives, USB drives and more over the network. If a machine does not have a CDROM simply share that device over NFS and get access.
Below are quick steps on installing and configuring an NFS share on your network. I set this up last night in about 5 minutes to share my media (video and audio) to the other machines on my network.
- sudo aptitude install nfs-kernel-server (install on the central machine you want to share)
- sudo <editor of choice> /etc/exports (this is the configuration file for NFS)
At this point you’ll have to list the devices or locations that you’d like to share and any specifics of that share. Below is an example of my entry and an explanation of each section.
/media/video *(ro,sync)
The first part of this entry, /media/video, represents the location that I want to “export” or share to the network. This, if you hadn’t guessed is the location of my video files.
The second part begins with *. *, as you probably know, represents everything or in this case everyone on the network. You can replace this with a hostname to limit just who can connect to your NFS share. In my case I want all of my local machines to connect so I’ve left it with *.
After that you see ro which defines “read-only”. All of my local machines can access the folder but none can make changes to any of the files. For now this is what I’d prefer. I’d hate for someone to “accidentally” erase half of the video files so its look but don’t touch access.
Now for the good part. How do I use the share that I’ve just setup? It’s quick and easy and uses our good friend the “mount” command. Below is an example of how I would mount the share I created above.
sudo mount media:/media/video /media/video
Here is a quick breakdown of that command. sudo, of course, to gain the privelege of running that command. mount is the same that you’d use to mount a cdrom or usb flash drive. media: represents the machine on the network. Why isn’t that an IP? I’ve specified media in my /etc/hosts file so I can make that shortcut. /media/video is the name of the remote share (as defined above) and /media/video is the location that I would like to mount to. I know it looks like some repetition but I like the organization. You could easily use anything in those places. (ie; sudo mount server:/home/user /home/Desktop/user)
note: the mount destination must already exist and must be empty to properly function.
Quickly, before I wrap this up. Below is an example of how you can set the NFS share to auto-mount on each boot. This would be helpful if you wanted to take advantage of the example above by centrally sharing /home folders.
sudo <editor of choice> /etc/fstab
Add the following entry (replacing with your specifics) to the bottom of that file.
example.hostname:/share_location /mount_location nfs rw,hard,intr 0 0
You’ll notice that the first part of the entry is very similar to the example for manually mounting the share. The last part, beginning with nfs, specifies the file system type (nfs, vfat, ext3, etc) and the last part specify the rest of the details for that nfs system.
I hope this helps anyone new to setting up an NFS share on their network. Some argue that a problem with Linux is lack of helpful documentation. Well, stick this in your pipe and smoke it.
technorati tags:nfs, network, filesystem, ubuntu, 6.06, 6.10