disque dur

Create a NAS with your Raspberry Pi and Samba

Mis à jour le 21 December 2017 - 0 Commentaires - , ,

One of the frequent uses of the Raspberry Pi is the creation of a local multimedia storage system, often called NAS (Network Attached Storage).

Today, we will explain how to create a NAS on your Raspberry Pi using SAMBA software.

To summarize, the article will show you how to create a hard drive on the local network with the Raspberry Pi and Samba, on which all multimedia devices (computer, TV …) can access without having to be connected to it.

Prerequisites for installing a NAS

Above all, it is important to present the necessary material for this realization. You will obviously need a raspberry pi , (an ethernet cable or wifi dongle if it is older than the third model), a power supply , an SD card with raspbian installed and finally one or more hard drives that will be accessible via the network. Preferably take hard drives powered through a power outlet to relieve the energy consumption of the Raspberry Pi.

Configuration of the Raspberry Pi

Once you have all the necessary equipment, the Raspberry is running and you are connected in SSH , you can start by updating your Raspberry Pi

sudo apt update 
sudo apt upgrade

Once the updates are complete, we will create the public and private folders that will be accessible on the NAS.

sudo mkdir /home/shares 
sudo mkdir /home/shares/public 
sudo chown -R root:users /home/shares/public 
sudo chmod -R ug=rwx, o=rx /home/shares/public

Creating the NAS server with Samba

The basic configuration of the raspberry pi being done, we will now be able to install the NAS itself. For this we will use Samba, a software capable of managing the networking of a hard drive to access from any operating system or computer connected to the network.

So we will start by installing Samba on the Raspberry Pi with the following command:

sudo apt samba samba-common-bin

After that, we will edit the configuration file.

sudo nano /etc/samba/smb.conf

If you want to limit connections to your NAS by requesting authentication, go to the line

##### Authentication #####

and add the following line just below

security = use

In order to manage the private storage spaces, go now in the game [homes]. If you want to be able to write (send files) to your NAS, make sure that the file contains the following line:

read only = no

Finally, at the bottom of the file, we will add parameters related to access to the public part of the NAS:

[public] 
  comment = public storage 
  path = /home/shares/public 
  valid users = @users 
  force group = users 
  create mask = 0660 
  directory mask = 0771 
  read only = no

Close the file by saving it and restart samba

sudo /etc/init.d/samba restart

Now we will add a user to samba. In our example we will add the user pi.

sudo smbpasswd -a pi

Add a multimedia device

If you want to add a USB key or a hard drive to have more storage, it is obviously possible. To simplify things if you want to connect multiple devices, it is best to connect/configure devices one by one.

Start by connecting your device to your raspberry pi. The first thing to do after that is to detect what is the name that the raspberry has associated with it. To do this, execute the command

dmesg

Generally, the name of the media is sda1 but this can change especially if you have several devices connected.

Be careful, your device must be formatted with an ext3 file system . If it does not, you can format it by using the following command (replacing sda1 with the name of your device if it is different).

mkfs.ext3 /dev/sda1

Then create a directory where the device will be mounted for access via the NAS

sudo mkdir /home/shares/public/disk1

The name of the folder (disk1 in the example) does not matter, put the one you want to be able to find it easily on the network. Once done, mount the device in this folder.

sudo mount /dev/sda1 /home/shares/public/disk1

Mount the devices when starting the raspberry pi

At this stage of the installation, there is indeed a problem. When restarting the raspberry pi, peripherals do not necessarily mount. To correct this, edit the fstab file.

sudo nano /etc/fstab

and for each device, add at the bottom of the file the following line (being careful not to be mistaken about the name of the device and the directory in which it must be mounted)

/dev/sda1 /home/shares/public/disk1 auto noatime 0 0

Connect to the NAS server

Our NAS is now configured so I just have to explain how to connect to it. I will not do it for all operating systems, it’s pretty similar for everyone. Know that for smartphones, you can connect with an app like File Expert for Android or File Explorer on IOS.

To log in from Windows, go to the This PC window, click the Computer tab, and then click Map network drive .

The drive letter does not matter, but you need to know where the raspberry pi is on the network. either by name or ip address. If you have never changed the name of your raspberry pi you should be able to connect to the public directory by filling \\raspberrypi\public or to the private directory with the username (in our example pi) by filling in\\raspberrypi\pi

That’s it, you now have a great NAS with your Raspberry Pi! All you have to do is install a media center on a second Raspberry Pi to have a multimedia system on top!

 

Share
Newsletter
Author:
Raspbian France
Join the Raspberry Pi community
A $35 computer, already sold at 10 millions copies
BUY THE NEW RASPBERRY PI 3
Related tutorials
Install WordPress on a Raspberry Pi (with Nginx). Create a Wi-Fi hotspot in less than 10 minutes with Pi Raspberry! How to Setup a VPN on Raspberry Pi How to create a Minecraft server with the Raspberry Pi Raspberry Pi HDMI display not working, how to solve it?
No Comments
Share
Suscribe to Newsletter
Inscrivez-vous à la Newsletter.
Vous avez aimé cet article ?
Inscrivez-vous et restez informé !