In the process of building the Raspberry Pi NAS storage server, we realize it through the cooperation of the Samba service and the external hard disk. First, we need to install the Samba service on the Raspberry Pi and configure its user permissions. Next, we connect the external hard disk to the Raspberry Pi and specify it as a shared directory in the configuration file of the Samba service. Finally, we can access the shared directory on other computers in the network for the purpose of data storage and backup.
Build a Raspberry Pi NAS storage server.
Introduction.
In today's digital age, the importance of data is self-evident. With the popularity of smartphones, tablets and laptops, our data volume is also growing rapidly.
To protect this valuable information, many people choose to back it up on cloud storage services.
However, cloud storage is not completely secure and may be limited by network connections.
Therefore, having a local NAS (Network Attached Storage) device becomes an ideal solution.
This article will guide you how to use Samba service and external hard disk to build a simple NAS storage server on Raspberry Pi.
Ready to work.
Hardware requirements.
1. Raspberry Pi (3B + or higher is recommended)
2. External hard disk (at least 1 TB of space required)
3. Power Adapter
4. SD card (8GB or larger is recommended)
5. USB hard disk adapter (if the hard disk is not a USB interface)
6. Network cable or Wi-Fi adapter (for connecting to the network)
Software requirements.
1. Raspbian operating system (for Raspberry Pi)
2. Samba service
3. File system tools (e.g fdisk
)
Install the Raspbian operating system.
First, you need to install the Raspbian operating system on your Raspberry Pi. You can download the latest Raspbian images from the official website and burn them to the SD card using tools like Etcher.
Then, insert the SD card into the Raspberry Pi and connect the power adapter.
After starting the Raspberry Pi, you can operate it via SSH or by connecting the monitor and keyboard directly.
Configure network connection.
Make sure your Raspberry Pi is connected to the network. If you are using a wired connection, just plug the network cable into the network port of the Raspberry Pi.
If it is wireless, follow the steps below to set it up:
1. Open the terminal and enter the following command to edit wpa_supplicant.conf
File:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
2. Add your wireless network information to the file in the following format:
text
network={
ssid="your_wifi_ssid"
psk="your_wifi_password"
key_mgmt=WPA-PSK
}
Replace your_wifi_ssid
Sumyour_wifi_password
For your network name and password.
3. Save and close the file.
Then restart the Raspberry Pi to apply the changes:
sudo reboot
Install and configure Samba services.
Samba is a software suite that allows file and printer sharing between Linux and Windows. We will use it to share our NAS storage.
1. Update the package list:
sudo apt update && sudo apt upgrade -y
2. Install Samba:
sudo apt install samba -y
3. Edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
4. Add the following at the end of the document:
text
[global]
workgroup = WORKGROUP
security = user
encrypt passwords = yes
persistent ticks = yes
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
[nas]
path = /media/pi/your_external_drive_label
available = yes
valid users = pi
read only = no
browsable = yes
public = yes
writable = yes
Pay attention to replacement your_external_drive_label
Label your external hard drive. If you don't know the label, you can use lsblk
Command to view.
5. Save and close the file.
Then restart the Samba service:
sudo systemctl restart smbd
Mount an external hard drive.
Now we need to mount the external hard drive on the Raspberry Pi. Suppose your hard drive is formatted as the ext 4 file system and you know its labels.
Execute the following command:
sudo fdisk -l
Find your hard disk device name (e.g /dev/sda1
), then create a mount point:
sudo mkdir /media/pi/your_external_drive_label
Next, mount the hard disk:
sudo mount /dev/sda1 /media/pi/your_external_drive_label
For the mount to still work after restarting, you need to add it to /etc/fstab
File. Execute the following command:
sudo nano /etc/fstab
Add the following line at the end of the file:
text
/dev/sda1 /media/pi/your_external_drive_label ext4 defaults 0 0
Save and close the file. Now, every time the Raspberry Pi starts, the hard drive is automatically mounted to the specified directory.
Test the NAS function.
Now that we have configured the Samba service and external hard disk, we are ready to test. On a Windows computer, open File Explorer and enter it in the address bar \\raspberrypi\nas
(of which raspberrypi
Is the host name of your Raspberry Pi).
If everything is fine, you should be able to see and access files on the NAS.
Summarize.
Through the above steps, you have successfully built a simple NAS storage server based on Raspberry Pi. You can use this server as a file sharing solution for your home or small office.
Of course, this is just the most basic setting.
Depending on your needs, you can also further optimize performance, security and availability.
Hope this article helps you get started and enjoy DIY!