Wall's Corners Wall's Corners Author
Title: Adding NAS Functionality to Raspberry Pi
Author: Wall's Corners
Rating 5 of 5 Des:
I know this is kind of random, but I have been asked by one of my superiors to build a company NAS device using Raspberry Pi. At least this...

I know this is kind of random, but I have been asked by one of my superiors to build a company NAS device using Pi. At least this job will allow me to kill two birds with one stone by creating something practical while having fun!

So what is a NAS? A shared server?

Let’s find out by first doing a Google search.

Raspberry Pi NAS

What is a NAS?

NAS (Wikipedia)

“Network-Attached Storage (NAS) is a file-level computer data storage server connected to a computer network providing data access to a heterogeneous group of clients. NAS is specialized for serving files either by its hardware, software, or configuration. It is often manufactured as a computer appliance – a purpose-built specialized computer.[nb 1] NAS systems are networked appliances which contain one or more storage drives, often arranged into logical, redundant storage containers or RAID.”

I used to think that NAS was the same as a shared server, but it’s actually more of a dedicated file server. Even though I want to play around some more with Raspberry Pi, I don’t think I’ll be able to turn it into a dedicated server at this time. So for now I’d like to at least build something that could be turned into a NAS device in the future.

Can a NAS Device be built using Raspberry Pi?

I do not yet have the skills to do all the research and build this on my own completely from scratch. So at this point, I decided to tap into the knowledge and expertise of my more experienced peers. I used Google to look for some reference sites.

Raspberry Pi NAS: Build a Raspberry Pi Samba Server

It looks like this is possible by using a package called Samba. Now, I know that this implementation is feasible, so I feel I can move forward with some confidence!

What is Samba?

Samba (Wikipedia)
Samba is a free software re-implementation of the SMB/CIFS networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Windows clients and can integrate with a Windows domain, either as a Domain (DC) or as a domain member.

 

File Server (Wikipedia)
File storage functionality that allows us to store files onto areas on a server known as shared folders. It implements the functionality of NAS. File servers can be configured with access rights so it can be used to provide access to files to specific users.

It is kind of difficult to explain it in words, but it looks like this package is needed to allow people to read and write data from Windows onto .

Let’s Try to Build a NAS Device! First, Samba Installation

Although I could build a large capacity NAS device using an external hard drive, first I would like to make it so that a Raspberry Pi SD card can be used directly as a shared area. The SD card I am currently using is 8GB with approximately 3GB of free space. For a basic NAS this should be enough. I will now enter a command using the LX Terminal.

Code-Example
1
sudo apt-get install samba

The installer verifies the amount of space needed, then we can enter [Y]. It takes a few minutes to complete the installation so we can relax for a little bit.

Verify the Version of Samba

When we carry on with an installation, learning as we go along, quite often we can become stuck further down the line due to not knowing the difference between versions.
Maybe the information that we had researched actually corresponded to an older version, forcing us to start all over again! (And for a beginner, avoiding this can be fairly difficult.) So, in order to avoid this as early as possible, let’s make sure to verify the version of Samba that we have installed.

Code-Example
1
smbd -V

Enter this command in the LX Terminal. Make sure the ‘-V’ is in upper case, since entering it in lower case will cause an error.

rasp06_img02

It tells me that the version is 3.6.6.

Prepare the NAS Directory

Next I would like to create a directory named “all” that everybody can access.
But first let’s prepare the space for storing the data on Raspberry Pi.

Code-Example
1
/home/pi/nas_all/

For now, I have prepared a folder just like this one!

I want other users to be able to use the folder. Let’s configure the access rights for the folder. Right-click on the folder and open “Properties”. Click on the “Permissions” tab to configure access control.

rasp06_img03

Permissions define the access control rules with regard to three types of users: Owner, Group, and Other Users. For each type we can select one of the four access rights: Read and Write, Read Only, Write Only, or None. By default, only the Owner has Read and Write rights, and all other users have Read Only rights.

I would like the folder to be used by everyone, so I should configure all of them with read and write permissions.

Customize the Configuration File

Samba’s configuration file is called “smb.conf”
The file is located here:

Code-Example
1
/etc/samba/smb.conf

I wondered whether I could edit it using the editor, so I tried opening it with the file manager, but I was unable to edit or copy it.

When I looked into it, I found out that this was because I had not logged in as “root” user.
I was actually logged in as the Raspberry Pi default user “pi”, so I used the command line to make a backup of the configuration file.

Code-Example
1
sudo cp -p /etc/samba/smb.conf /etc/samba/smb.conf.org

cp: copies a file
-p: optional parameter. It preserves the owner, group, permissions, and timestamp.

I copied the file to a new file called “smb.conf.org” located in the same directory as the original file.
Note that if we do not specify the “sudo” command, we will get a message saying “You do not have permission” and we will not be able to run the command.
Now, let’s edit the configuration file.

Code-Example
1
sudo nano /etc/samba/smb.conf

nano: open the file with the text editor (nano). If the file does not exist, then we can create a new one.

The screen looks a bit different from the usual command entry screen. The editor displays the contents directly onto the screen.
Here we also have to use the “sudo” command! If we do not run this command with administrator rights, we will not be able to write to the file.

rasp06_img04

The bottom of the screen displays various operational commands available. The ^ symbol means “while holding the [Ctrl] key”.
Use the arrow keys or the mouse to move the cursor to the bottom of the file (somehow I could not touch the scroll bar) and add the minimum required parameters.

smb.conf – The configuration file for the Samba Suite

Be careful as the configuration items in smb.conf may vary depending on the version.
The version we are using is 3.6, so let’s move onto this page for reference.

What we want to do is create a directory called “all” in “home/pi/nas_all” with “write” permission for “everybody”.
Let’s apply these values to each configuration parameter:

Code-Example
1
2
3
4
[all]
path = home/pi/nas_all
guest ok = Yes
read only = No

The first item is the section name. This is the name that is displayed when it is accessed by a user. We can add any name except for [global], [homes], and [printers].
The other parameters have the following meanings:

path: specifies the directory accessed by a user when connecting to the service.
guest ok: means the same as “public”. The default value is “No”.
read only: configures the write permissions on the file. It is the opposite of “writable”. The default value is “Yes”.

rasp06_img06

Once we have finished entering the settings, we can save the file. We want to “WriteOut”, which is the second command from the left on the top row, so we enter [Ctrl]+[O].
This displays the filename. Because we want to overwrite the file, we just press Enter.

Once it is saved, the editor goes back to the main menu, and we can “Exit”, which is on the bottom left of the screen, by pressing [Ctrl]+[X]. This takes us back to the command line.

When I checked the file by opening it directly, my additional strings had been added correctly! This completes the Samba configuration.

Run Samba

So now let’s try running Samba!

Code-Example
1
sudo service samba restart

service: carries out operations on the specified service, such as start, stop, status, etc.
restart: it restarts the process.

Once we have entered the command, we can verify this by using a machine on the same network.

rasp06_img07

We can now see that “RASPBERRYPI” is displayed on the network. If we go in,

rasp06_img08

We see that the ‘all’ folder is displayed!

Let’s check that the “read only=no” configuration has taken effect.
If we can carry out all file operations, such as creating new files, copying files, etc. inside the “all” folder, then everything is working correctly.

Now, let’s stop the service.

Code-Example
1
sudo service samba stop

On Raspberry Pi, enter the command to terminate Samba.
At this point, when we try to access “RASPBERRYPI” from Linux we can no longer access it. This verifies that Samba has been stopped successfully.

I tried turning the power off on the Raspberry Pi and restarted it again. I did not have to do anything special and I was able to connect from Windows.
Once it is installed, Samba seems to restart itself .

At this point, a thought came into my mind:

Entering all these commands is tiresome!!
Isn’t there a much easier way?

Samba’s Configuration Tool: SWAT

I want to reduce the amount of work required when entering the commands! As I looked into how to do this, I found out that there is a Samba configuration tool called SWAT.

Let’s try installing it now!

SWAT

SWAT (Samba Web Administration Tool) is a standard a browser-based management tool provided by Samba. This tool allows us to use a web browser to manage Samba, including changing configuration settings and starting/stopping the service. This removes the cumbersome need to edit the Samba configuration file directly.

First, we enter a command as usual. The package name was fine just as “swat”.

Code-Example
1
sudo apt-get install swat

Once the installation is complete, we access the following URL from a browser:

Code-Example
1
http://localhost:901/

(*If specifying the hostname, then use it instead of “localhost”)

At this point I was asked for my ID and password (but I don’t remember setting this), so I just tried using the login ID and password for the ‘pi’ account and it logged me in.

rasp06_img10

For some reason, there are too few menu items… I can’t see any configuration screens that correspond to some of the configuration items on “smb.conf” such as “global” and “printers”.

When I looked into it further, I found out that SWAT also needs to be run as the ‘root’ user.
But the default user for Raspberry Pi is ‘pi’, so we’ll need to create a new user ‘root’.

Let’s go back to LX Terminal once again and enter a command.

Code-Example
1
sudo adduser root

When I entered the command for adding a user, I got the error saying “adduser: user ‘root’ already exists.”
It looks like the “root” user had already existed from the beginning! So the system did not just have the “pi” user after all!

When I looked into it, it turned out that the “root” user did exist but it had just been deactivated.
Plus I found out that the default password was blank. So let’s set a password right now.

Code-Example
1
sudo passwd root

Use “sudo” to force the execution of the command. The password needs to be entered twice, so simply follow the instructions on screen.

Maybe it is because I am using “sudo” but I can now set the password as many times as I like without being asked for the old password.
(Is this what it means to have administrator rights?)

From now on, I will log in again using the root account and continue on.
Once everything is ready, I access SWAT once again.

rasp06_img11

If you can see 8 different icons in the header, then the operation was a success!
From “HOME”, “GLOBALS”, “SHARES”, and “PRINTERS” we can update the configuration settings in “smb.conf”.

Try Using SWAT!

Let’s try checking the “all” directory that we created earlier!
As we are accessing a directory that we have created ourselves, we click on the “SHARES” icon.

rasp06_img12

This launches a new screen. From the list, select “all” and click on the “Choose Share” button next to it on the left.
The button on the right is the ‘Delete’ button so be careful!

rasp06_img13

When I used a default browser, the text boxes were not displayed correctly so I tried again using a browser called NetSurf.
(*With NetSurf, the “Set Default” button and other buttons do not seem to work correctly, so it looks like it is better to use “Midori” when actually making changes to the configuration.)

Here we can see that the fields “path”, “read only”, and “guest ok” contain the values that we set earlier from the command line.

If new settings have been added or old settings have been changed, then click on the “Commit Changes” button to save the new configuration.

This really makes Samba easier to use!
Although the tool does run a little slowly, compared to the command line it’s a lot less work!

Summary

Our Raspberry Pi NAS is done!

But having said this, if left like this everybody would be able to access the NAS, which would be a concern from a security standpoint.
And using it for shared folders, it definitely looks like the NAS would be useful for personal or corporate directories that require users to log in. Now there is only a little bit left until I can achieve my final objective!

In the next article, I will be using and customizing SWAT so that we can employ the Raspberry Pi as a corporate NAS.

Share This:

View more at: http://yoursmart.mobi

About Author

Advertisement

Post a Comment

 
Top