I use my NFS file sharing server to stream media to Kodi media centers installed on various devices in my local network.


1TB WD Elements 3.5" external HDD formatted to ext4 file system

I recommend you to have a clean(ish) installation of Raspbian Lite (command line only OS for Raspberry Pi) on our microSD card, see this post on how to do that.

Setting a static IP address for the Pi is also essential, and the way how to do that has changed in Raspbian version “Jessie”, you can find a tutorial here.

I’ll attach the 1TB external hard drive to my Pi, on which I’ll store my data. We’ll use the NFS server to share these data on the local network.

Let’s check the HDD’s dev identification:

pi@luckberry ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 16.1 GB, 16064184320 bytes
4 heads, 16 sectors/track, 490240 cylinders, total 31375360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009bf4f

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    31375359    15626240   83  Linux

Disk /dev/sda: 1000.2 GB, 1000202043392 bytes
255 heads, 63 sectors/track, 121600 cylinders, total 1953519616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x65ce95a6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            1985  1953503231   976750623+   f  W95 Ext'd (LBA)
/dev/sda5            2048  1953503231   976750592   83  Linux

If we’d like to format it to get a clean partition, you can do the following, but BEWARE THIS WILL ERASE EVERYTHING FROM THAT HARD DRIVE!!! Also, be very VERY careful on which /dev/sdx you use it, you could wipe the wrong disk, and there’s NO GOING BACK FROM THERE.

Let’s mount the partition.

We need to create the mount point for the disk.

sudo mkdir /media/1TB/
sudo chown -R pi:pi /media/1TB/
sudo chmod 755 /media/1TB/

First when I did this, I had to use 777 permissions on this mount point to work, which is undesirable in many ways, so after I set the disk up, I changed back to 755.

Then we mount the partition to that mount point.

mount /dev/sda5 /media/1TB

So you can now go to that folder

cd /media/1TB/

Now we create the folders we’ll need later, and set ownership and permissions for them.

One folder for general Downloads:

sudo mkdir /media/1TB/Downloads
sudo chown pi:pi /media/1TB/Downloads
sudo chmod 755 /media/1TB/Downloads

One folder for Movies:

sudo mkdir /media/1TB/Movies
sudo chown pi:pi /media/1TB/Movies
sudo chmod 755 /media/1TB/Movies

…aaand one folder for Series:

sudo mkdir /media/1TB/Series
sudo chown pi:pi /media/1TB/Series
sudo chmod 755 /media/1TB/Series

It should look something like this:

pi@luckberry ~ $ ls -la /media/1TB
total 36
drwxr-xr-x   7 pi   pi   4096 Apr 24 20:50 .
drwxr-xr-x   3 root root 4096 May  5  2015 ..
drwxr-xr-x   4 pi   pi   4096 Sep 19 20:54 Downloads
drwxr-xr-x 112 pi   pi   8192 Sep 18 16:00 Movies
drwxr-xr-x   5 pi   pi   8192 Sep  5 20:50 Series

Please not, that this mount will vanish when you reboot the Pi, so let’s mount the hard drive permanently.

pi@luckberry ~ $ sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="140A-14B7" TYPE="vfat"
/dev/mmcblk0p2: UUID="f24a4949-f4b2-4cad-a780-a138695079ec" TYPE="ext4"
/dev/sda5: LABEL="1TB" UUID="72fb2139-5b24-d001-7093-21395b24d001" TYPE="ext4"

as you can see my disk is still the same:

/dev/sda5 LABEL=”1TB”
sudo vi /etc/fstab

add this line to the bottom of it:
/dev/sda5 /media/1TB ext4 defaults,noatime 0 0

so it looks something like this:

pi@luckberry ~ $ cat /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
/dev/sda5    /media/1TB    ext4   defaults,noatime    0   0

On Raspberry Pi 2 this needs to be done for fstab to work:

sudo nano /boot/cmdline.txt

add “rootdelay=10” to the end of the first line, after “rootwait”, so it will look like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait rootdelay=10

then reboot the Pi with:

sudo reboot

After the reboot, SSH back, and check if the HDD has automounted:

mount -l | grep ext4
cd /media/1TB/
ls -la

We can set recursive ownerships like this.

sudo chown -R pi:pi /media/1TB/

Setting permissions recurively is a bit more complicated, though. These commands set a permission 755 to type d “files” (those are the directories a.k.a folders), and sent 644 to type f files, the normal files.

sudo find /media/1TB/ -type d -exec chmod 755 {} +
sudo find /media/1TB/ -type f -exec chmod 644 {} +

Finally! Installing the NFS Server

Install the NFS server-side components on the RPi using:

sudo apt-get install nfs-kernel-server nfs-common rpcbind

It does not start cause you don’t have exports, so we add the HDD’s mounted partitions into the /etc/exports file:

sudo vi /etc/exports

add the following to the bottom:


Or more recently I use:


Then the netconfig:

sudo vi /etc/netconfig

comment out lines:

#udp6 tpi_clts v inet6 udp - -
#tcp6 tpi_cots_ord v inet6 tcp - -
sudo exportfs -ra

sudo update-rc.d rpcbind enable && sudo update-rc.d nfs-common enable

sudo service rpcbind restart
sudo service nfs-kernel-server restart

And you should be good to go!