Page 1 of 1

Creating Pi Network Attached Storage (NAS)

Posted: Fri May 22, 2020 9:51 pm
by William
This is a perfect alternative to an expensive NAS drive or enclosure especially if you already own a couple of USB drives.
so what is needed to build a NAS ? Well the Pi 4 to start with but this is the Pi forum so quite obvious really.

so what else is need?
1 × External USB drives (minimum)
Mirco sd card
Ethernet Cable – 1 Meter (For Gigabit Ethernet i would advice a cat6 cable )
Raspbian Buster Lite this can be downloaded here
USB 3.0 HUB 4 ports ( if you want to add more drives)

so how do we go about this when we have acquired all items needed

Step 1. install the OS

Install the Raspbian operating system. the instructions to set up your operating system can be found on the site

Step 2. Update the OS

this can be done by updating the package list and all your packages by running these two commands

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Step 3. Install Samba

To install the Samba packages, run the following command

Code: Select all

sudo apt-get install samba samba-common-bin
Step 4. Create a folder for sharing

We need to create a directory where we can store all your files, to do this we use the following command

Code: Select all

mkdir /home/pi/shared
(or any name you like )

Step 5. Sharing folder using Samba

For sharing the above folder with Samba, you will have to modify the Samba configuration file by typing the following command:

Code: Select all

sudo nano /etc/samba/smb.conf
In addition, just below the authentication section of the file, paste this following line:
security = user

Step 6. Define Details of share

Within this file, add the following to the bottom. This text defines various details of share.

Code: Select all

path = /home/pi/shared
create mask=0777
directory mask=0777
[h4kurshare]:This defines the address and other configurations related to the shared folders. For example, the shared folder will be abe the following address: \\raspberrypi\h4kurshare. You can rename it to whatever you like to call your shared storage space as well.

path: This option contains the address of the directory that is going to be shared. If you wish to store the shared folder on an external drive, just change to path option here to point it towards your external drive.

writeable: With this option set to yes, the folder will be writable.

create mask & directory mask: This option defines the maximum permissions for both files and folder. By setting it to 0777, it allows users to read, write and execute.

public: This option is used to give permission to either give any user access to the folder or restricted access. With the option set to “no”, the Raspberry Pi needs a valid user to grant access to shared folders.

Step 7. Save changes

Now that we are done with the changes made to the file, we will now save it by pressing CTRL + X then Y and hit ENTER.

Step 8. Make a user for Samba on the Raspberry Pi

Next, we will make a user for our Samba server on the Raspberry Pi in order for us to make a connection to the shared network drive.

We will run a command to create a Samba user called “Pi”

Code: Select all

sudo smbpasswd -a pi
After running this command, you will be prompted to set a password that is up to you.
With this user “Pi” you can access the Samba share from Windows, macOS, or other Raspberry Pi devices with the ability to read and write files.
If you wish to create additional users, use the following commands

Code: Select all

sudo adduser username
sudo smbpasswd -a username
Replace “username” with your username.

Step 9. Retrieve Raspberry Pi local IP address

We will have to retrieve our Raspberry Pi’s local IP address when connecting to Samba.
This is in the event the connection fails on your home network where we can still use the IP address to connect to the Samba Share
For this, make sure that you are connected to a network by either an ethernet cable or Wifi.

Key in the following command to get your Pi local IP address:

hostname -I

That all for this guide more coming soon