Setting up NFS on a home linux box

home-network

Home Network

NFS Server Installation

I’ve built my own home server called (Orion) you can read the details here, currently, I’m in the process of installing NFS so that I can access my files from my Linux Workstation.

Home network setup

Server IP: 192.168.1.15
Workstation IP: 192.168.1.10

Install NFS Server

sudo apt-get install portmap nfs-kernel-server

Shares

Edit /etc/exports and add the shares:

/home/backup 192.168.1.10/32(rw,sync,no_root_squash,no_subtree_check,sync)

The above shares /home/backup allows only my workstationion on my private network  to access the share.

rw makes the share read/write, and sync requires the server to only reply to requests once any changes have been flushed to disk. This is the safest option (async is faster, but dangerous. It is strongly recommended that you read man exports.

After setting up /etc/exports, export the shares:

sudo exportfs -ra

You’ll want to do this command whenever /etc/exports is modified.

Restart Services

If /etc/default/portmap was changed, portmap will need to be restarted:

sudo /etc/init.d/portmap restart

The NFS kernel server will also require a restart:

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

NFS Client Installation

sudo apt-get install portmap nfs-common

optional

Portmap Lockdown

Add the following line to /etc/hosts.deny:

portmap : ALL

By blocking all clients first, only clients in /etc/hosts.allow below will be allowed to access the server.
Now add the following line to /etc/hosts.allow:

portmap : NFS server IP address

Where “NFS server IP address” is the IP address of the server. This must be numeric! It’s the way portmap works.

Mounts

Check to see if everything works

You should try and mount it now. The basic template you will use is:

sudo mount ServerIP:/folder/already/setup/to/be/shared /home/username/folder/in/your/local/computer

so in my case, I would have:

sudo mount 192.168.1.15:/home/backup /mnt/backup

Mount at startup

NFS mounts can either be automatically mounted when accessed using autofs or can be setup with static mounts using entries in /etc/fstab.

Static Mounts

Prior to setting up the mounts, make sure the directories that will act as mountpoints are already created.

In /etc/fstab, add lines for shares such as:

servername:dir /mntpoint nfs rw,hard,intr 0 0

My fstab file looks like this, yours of course will probably look totally different

192.168.1.15:/home/backup /mnt/backup nfs rsize=8192,wsize=8192,timeo=14,intr

The rw mounts it read/write. Obviously, if the server is sharing it read only, the client won’t be able to mount it as anything more than that. The hard mounts the share such that if the server becomes unavailable, the program will wait until it is available. The alternative is soft. intr allows you to interrupt/kill the process. Otherwise, it will ignore you. Documentation for these can be found in the Mount options for nfs section of man mount.

The filesystems can now be mounted with mount /mountpoint, or mount -a to mount everything that should be mounted at boot.

References:

https://help.ubuntu.com/community/SettingUpNFSHowTo
http://www.howtoforge.com/nfs-server-and-client-debian-etch
http://nfs.sourceforge.net/nfs-howto/

Backing up my home directory to my mounted NFS filesystem.

Crontab setting to run backup.sh runs every day at 10:30

# m h  dom mon dow   command
30 10  *   *   *       /home/billy/backup.sh > /mnt/backup/backlist.txt

Saved the following as backup.sh

# Exit on error
set -o errexit
export PATH=/usr/local/bin:/usr/bin:/bin
rsync -axv –delete /home/billy/ /mnt/backup/billy/

References:

http://en.wikipedia.org/wiki/Rsync
http://rsync.samba.org/
http://samba.anu.edu.au/rsync/examples.html

About billy

Senior IT Technician working in Edinburgh, Scotland.
This entry was posted in Linux, Personal and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>