Network-attached storage (NAS)

Now we have seen how to setup a single external HDD let's take a look at creating a Network-attached storage (NAS) device. This is particularly handy if you have a number of machines on your home network, such as Macs or Windows PCs, and want to create a central storage device for files that they can all access.

Setting up the NAS builds up the work we completed in the first part of this chapter.

The technology we will use to achieve this is Samba. Samba is an open source application suite that provides both file and print sharing services. It re-implements the SMB/CIF protocol and was originally aimed at Windows users.

You can read more about this at the Samba website by visiting https://www.samba.org/samba/what_is_samba.html.

For now, all you need to know is that it will allow you to network your Raspberry Pi 2 and use it as a storage medium on your home network.

Let's start by grabbing the packages we need to set things up.

We can use apt-get to grab the Samba packages and install them onto our device:

Once the installation process has completed we need to edit the configuration file. This can be found in the ./etc/samba directory:

Find and edit the following line:

It should be changed to the following line:

What we have done here is remove the comment activating this line in the configuration. If the file does not contain this line you can add it yourself.

We can now add our NAS Samba configuration as follows. Add it to the end of the file, below any other configuration settings:

The first line [NAS] is the name of the share. You can label this whatever you like.

Following this we have the comment. This is a description text associated with the share. This can be a plain text string explaining what the configuration is for.

After this we include the path. This is the path to our mounted HDD, for example,/ext4/ or /.

Next we include the list of valid users permitted to access the share. Here we use @users. The next line includes force group. Here we specify the UNIX group name that will be assigned for all users who access the share.

The create mask and directory mask follow on the next two lines. This contains the permissions that all directories on the share are given by default including when they are created.

The final setting read only is set to no. This allows users to add files to the share.

Save the file and exit.

We can now test that the NAS is working.

First of all, we will restart the Samba server to pick up our configuration changes.

At the command line, run the following command:

Next, connect your user to Samba as follows:

You will be prompted to enter a password for the pi user.

We can now test the network share is working from external devices. Follow the steps in the next section for the device you have. Instructions are included for Mac, Linux, and Windows: