Using a Raspberry Pi for Network Attached Storage
You want to use your Raspberry Pi as Network Attached Storage (NAS) by accessing a large USB drive attached to your Raspberry Pi from computers on your network.
The solution to this problem is to install and configure Samba. To do this, issue the commands:
$ sudo apt-get install samba $ sudo apt-get install samba-common-bin |
Now, attach the USB hard drive to the Raspberry Pi. It will automatically mount in your /media folder. To check that it’s there, use the command:
$ cd /media $ ls |
The drive should be listed with whatever name you gave it when you formatted it. It will automatically mount itself whenever the Raspberry Pi reboots.
You now need to configure Samba so the drive can be shared on the network. To do this, you first need to add a Samba user (pi). Enter the following command and type in a password:
$ sudo smbpasswd -a pi New SMB password: Retype new SMB password: Added user pi. |
You now need to make some changes to the file /etc/samba/smb.conf, so enter the command:
$ sudo nano /etc/samba/smb.conf |
The first line you’re looking for is near the top of the file:
workgroup = WORKGROUP |
You only need to change this if you plan to connect from a Windows machine. This should be the name of your Windows workgroup. For Windows XP, the default is MSHOME; for newer versions of Windows, it is HOME. (But check on your Windows network.)
The next change to be made is further down the file in the Authentication section. Find the line:
# security = user |
Remove the # from the front to turn security on.
Finally, scroll right to the end of the file and add the following lines:
[USB] path = /media/NAS comment = NAS Drive valid users = pi writeable = yes browseable = yes create mask = 0777 public = yes |
Save the file and then restart Samba by entering the command:
$ sudo /etc/init.d/samba restart |
If all is well, your USB drive should now be shared on your network.
Discussion
To connect to the drive on a Mac, just select Go→Connect to Server from the Finder menu. Then enter smb://raspberrypi/USB in the Server Address field. You will see a login dialog box, where you need to change the username to pi (Figure 2-10).
If you are connecting to the NAS from a Windows machine, then the exact procedure will vary depending on your version of Windows. However, the basic principle is that at some point, you will need to enter the network address, which should be \\raspberrypi\USB (Figure 2-11).
You will then be prompted for the username and password before you can use the NAS disk (Figure 2-12).
If you are a Linux user, this command should mount the NAS drive for you:
$ sudo mkdir /pishare $ sudo smbmount -o username=pi,password=raspberry //192.168.1.16/USB /pishare |
See Also
You may wish to change your Raspberry Pi’s network name to something inappropriate like piNAS (see Recipe 2.4).