Want to create your own personal cloud? In this tutorial, you will learn what Network-Attached Storage (NAS) is and how you can transform your own Raspberry Pi into a full-fledged NAS server.
A Network-Attached Storage or NAS is a centralized storage device for storing data in a network. It allows you to share files from the NAS to all the devices connected to your network. With a NAS, you can easily share music and movies, seed a file 24/7, and even use it as the primary backup for your PC.
Compared to cloud storage, it is scalable, has no monthly fees, and most importantly, doesn’t monitor your usage. NAS, even the DIY Raspberry Pi ones, are scalable in that you can add additional memory if you ever need it. For instance, one Synology NAS has 5 racks for HDD or SSD. If you used up the first 1 TB HDD, you could always add another to fulfill your storage needs. This without the additional monthly fees cloud storage services often charge!
Furthermore, it is completely private. Since it only lives within your network, you can be sure no megacorp is monitoring your usage.
Pre-built NAS is sturdy, convenient, and more appropriate if you’re looking for a long-term solution. However, they can get expensive fast. If you want to try it out first, you can use a Raspberry Pi as a trial NAS and decide if you need an upgrade later. If you realize you don’t need a NAS after all, you can always revert the Pi into any other purpose.
That said, a Raspberry Pi NAS is still a great project. And if you bought the Pi as a learning platform, I highly recommend making it even just for the knowledge you’ll get from experience.
Building the Raspberry Pi NAS
The first thing you need when building a Raspberry Pi NAS from scratch is the storage device. The microSD just won’t cut it. You can use a flash drive, an HDD, or an SSD. You can use an external hard drive, or if you have a spare HDD laying around somewhere, you can use a SATA-to-USB cable to connect it to the Raspberry Pi. In this tutorial, we will use an HDD (Hard Disk Drive) with a USB-SATA cable.
Configuration of the Raspberry Pi
As always, update first your Raspberry Pi OS to the newest version.
sudo apt update sudo apt upgrade
After the update is complete, create the public and private folders accessible with the NAS. Then change the public folder’s owner to root and the group to the current user. Finally, allow read, write, and execute permissions on the current user and group while read and execute only for others.
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
Now that we’ve finished setting up the Raspberry Pi as a NAS server let’s work on installing the NAS software itself. In this tutorial, we will use Samba.
Samba is an open-source re-implementation of SMB (Server Message Block), a network protocol originally used between a Microsoft client and server. It was created to allow Windows clients to a Linux host’s file and print services. With Samba, Windows computers can read, write, or execute files without knowing it is from a Linux host.
Moreover, the current version of Samba offers interoperability between Windows and Linux systems and any other popular operating system or computer connected to the network.
To install Samba on your Raspberry Pi, enter the command below.
sudo apt install samba samba-common-bin
Then, edit the configuration file using the nano text editor.
sudo nano /etc/samba/smb.conf
You can limit the connections to your NAS by adding authentication. In the Samba configuration file, press CTRL + W and search for “Authentication.”
##### Authentication #####
Now, add the line below.
security = user
Then scroll down and find [homes]. It’s under the Share Definitions section. Change the read-only line to No. This will allow you to write files to your NAS so that you can send and save files to it.
read only = no
Finally, add the public parameters below. Save the file and exit.
[public] comment = public storage path = /home/shares/public valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no
Restart the Samba service to enable the changes.
sudo /etc/init.d/smbd restart
There should be a GUI that pops up after restarting the Samba service. It will ask for your SMB password for client authentication. Otherwise, you can enter the line below to add user “pi” and assign a password manually.
sudo smbpasswd -a pi
Register a Storage Device
At this point, you can already access all of Raspberry Pi’s memory with any connected device in your network. If you don’t have a flash drive or an external storage drive to extend the Pi’s memory, you can skip to the last section to see how to access the NAS server.
You can add multiple storage devices to a Raspberry Pi NAS, but it is best to configure things one by one to simplify the procedure.
First, connect a storage device. Identify the storage device’s name by entering the following command.
If you’re connecting the first storage device, the name should be sda1. You must format your device with a Linux file system, such as ext3 or ext4. If it isn’t, you can format it using the command below.
umount /dev/sda1 sudo mkfs.ext4 /dev/sda1
Next, create a directory, change the owner, and change the read, write, and execute permissions just like what we’ve done with the Raspberry Pi’s main memory (SD Card).
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
Finally, mount the device on the folder.
sudo mount /dev/sda1 /home/shares/public/disk1
Mount the Devices When Starting the Raspberry Pi
To make the storage device mount automatically during startup, we must edit the fstab file.
sudo nano /etc/fstab
Now for each device you registered, add the following line to the bottom of the fstab file. It would be best to change the device name and the designated directory for every registered storage device to the Raspberry Pi NAS.
/dev/sda1 /home/shares/public/disk1 auto noatime,nofail 0 0
Access the NAS Server
To access the Raspberry Pi NAS, go to This PC, click the Computer tab, and then click Map network drive.
After that, a prompt will ask you for the network folder you’d like to map. You can use any drive letter you want. If you have never changed the name of your Pi, you can connect to the public directory by entering
\\raspberrypi\public or to the private directory with the username (in our example
pi) by entering
\\raspberrypi\pi. Also, for smartphones, you can connect to the NAS using an app like File Expert for Android or File Explorer on IOS.
There you have it! You now know how to make a Raspberry Pi NAS using only a Raspberry Pi and an optional storage device.
Sign Up & Get at Least Two $5 Coupons Now: https://jlcpcb.com/quote