In my previous article, I added an USB HDD (WD PiDrive) to Raspberry Pi and showed you how to make the file system more reliable by setting up software RAID. Now, it is time to turn Raspberry Pi into a NAS (Network Attached Storage) device.
There are many benefits to set up a NAS using Raspberry Pi. Low power and quite operation are the two main reasons that are most important to me. Of course, high performance is needed, there are better solutions out there.
Samba was originally designed for Windows systems to share file and print services. It was later on adopted by many Unix systems and is available under GNU GPL license. To install Samba, run the followings:
sudo apt-get install samba samba-common-bin
Create a directory in your file system for sharing. e.g. /home/disks/raid/netshare
cd /home/disks/raid mkdir netshare
Next step is to edit smb.conf
sudo emacs /etc/samba/smb.conf
Update the workgroup in smb.conf. For example, if your Windows Workgroup is “MYGROUP”, update workgroup as follows:
workgroup = MYGROUP
At the end of smb.conf add the followings:
[pishare] comment = Raspberry Pi RAID path = /home/disks/raid/netshare browseable = yes writeable = yes only guest = no create mask = 0770 directory mask = 0770 public = no write list = thomas
(where thomas is the user name)
Also make sure that you apply proper permissions and group in the
chown thomas /home/disks/raid/netshare chgrp users /home/disks/raid/netshare chmod 770 /home/disks/raid/netshare
After saving the edits, restart Samba server as follows
sudo service smbd restart
What it does is that it shares your local folder /home/disks/raid/netshare on your local network as ‘pishare’. By setting ‘only guest’ and ‘public’ attributes to no, it requires user to login in order to access the pishare network folder
Adding Samba user
Run the following command to add a Samba user on your Raspberry Pi . In the following example, ‘thomas’ is my Unix user name. The following command sets the password for ‘thomas’ to access Samba.
sudo smbpasswd -a thomas [New SMB password:] <-- enter a password (could be different from your unix password)
Map the Samba Folder on Windows
On Windows, you may map the Samba folder to a drive. Here is how:
- Open file explorer.
- Right click on ‘This PC’
- Select ‘Map Network Drive’ and it opens the following dialog box. Click on ‘Browse’ button to select the Samba folder made available from your raspberry Pi. In my case, it is \\THOMAS-DESKTOP\pishare
You will be prompted to enter username ‘thomas’ and your Samba password. Once they are entered, your network drive (Z:) is available.