Create NAS network storage with Raspberry Pi and Samba

One of the most frequent uses of the Raspberry Pi is to create a local media storage system, commonly referred to as a NAS. Today, TipsMake.com will explain how to create a NAS on a Raspberry Pi using Samba software.

Today, TipsMake.com will explain how to create a NAS on a Raspberry Pi using Samba software.

This article will show you how to create a hard drive on a local network with Raspberry Pi and Samba, on which all multimedia devices (computer, TV .) can be accessed without having to connect to it. .

Prerequisites for installing a NAS

Above all, it is important to prepare the necessary things to do this. Obviously you'll need a Raspberry Pi, Ethernet cable, or WiFi dongle if the Pi is older than model 3, the power supply, an SD card with Raspbian installed, and finally one or more hard drives accessible over the network. Prioritize using a hard drive powered through an electrical outlet to reduce the Raspberry Pi's energy consumption.

 

Configure Raspberry Pi

Once you have all the necessary devices, 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 update is complete, create public and private folders 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

Create a NAS server with Samba

The basic configuration of the Raspberry Pi is done, you can now install the NAS. For this, we'll use Samba, a piece of software capable of managing network hard drives for access from any operating system or computer connected to the network.

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

sudo apt install samba samba-common-bin

After that, let's edit the configuration file.

sudo nano /etc/samba/smb.conf

If you want to limit the connection to your NAS by requiring authentication, go to the line

##### Authentication #####

. and add the following line just below:

security = user

Picture 1 of Create NAS network storage with Raspberry Pi and Samba

To manage your personal storage space, go to [homes]. If you want to be able to write (send files) to your NAS, make sure the file contains the following line:

read only = no

Finally, at the end of the file, let's add parameters regarding 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 restarting Samba.

sudo /etc/init.d/smbd restart

Now let's add a user to Samba. In this example user pi will be added.

sudo smbpasswd -a pi

Add a multimedia device

If you want to add a USB or hard drive for more space then obviously, that's possible. To simplify things if you want to connect multiple devices, it is best to connect / configure them one by one.

Start off by connecting the device to the Raspberry Pi. Find out what the device name when connected to Pi is. To do this, execute the command:

dmesg

In the example, the name of the media is sda1 but this could change, especially if you have multiple devices connected.

Be careful, your device must be formatted using the Linux file system, like ext3 or ext4. If not, you can format it using the following command (replace sda1 with your device name, if it's different).

umount /dev/sda1 sudo mkfs.ext4 /dev/sda1

Then create a directory where the device will be mounted for access over the NAS, and then add read and write permissions.

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

The name of the folder ( disk1 in the example ) doesn't matter, give it the name you want so that it can be easily found on the network. Once done, mount the device to this directory.

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

Mount the devices when booting the Raspberry Pi

At this stage of the installation, there's really a problem. Upon restarting the Raspberry Pi, the peripherals will not necessarily mount. To fix this, edit the fstab file .

sudo nano /etc/fstab

And for each device, add the following line at the end of the file (be careful not to confuse the device name and the directory it should be mounted on).

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

Connect to the NAS server

My NAS is configured now so next, I will explain how to connect to it. This article will not provide instructions for all operating systems, as the procedure is quite similar. For smartphones, you can connect to 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 , then select Map drive network .

Picture 2 of Create NAS network storage with Raspberry Pi and Samba

The drive letter doesn't matter, but you do need to know the Raspberry Pi's location on the network, either by its name or the IP address. If you have never changed the name of your Raspberry Pi before, you can connect to a public directory by entering raspberrypipublic or entering a private directory with a username (pi in this example) by entering raspberrypipi.

Update 20 August 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile