Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
The Rasberry PI is a low cost piece of hardware that you can have a lot of fun with through experimenting and building/working on projects like media players, running a low cost computer, build data loggers etc. - see: https://www.raspberrypi.org
For this project, I took a spare Raspberry PI (RPI) and created a low cost NAS with it. I've used a RPI, a 2.5" bus powered hard drive and a USB hub with a 5V/2A power supply. The RPI itself cannot power the hard drive through USB. But, when connected via the hub, it works like a charm.
Put the SD card created in the previous step in your RPI and connect power, wait for the RPI to boot
Log on with the pi user (password: raspberry) - note that a notice is displayed that the RPI is not fully configured. You can ignore this message for now. If you have the RPI connected to a display (HDMI), you will see the configuration menu. Do not configure it now.
Change to root using: sudo su
Update Raspbian using: apt-get update followed by apt-get upgrade (this could take some time). The upgrade will ask you about additional disk space usage, answer Y(es).
Now configure the RPI by giving the raspi-config command.
A 9 option menu is displayed, we only need to look at the first 4 options.
Choose option 1: Expand Filesystem and acknowledge the next screen.
Choose option 2: Change User Password and change the password for the pi user.
Choose option 3: Enable Boot to Desktop/Scratch and select the "Console Text console ..." option.
Choose option 4: Internationalisation Options and change Locale, Timezone and Keyboard Layout as required
Select Finish to complete the RPI configuration and select Yes to reboot the RPI.
After the reboot, log on again with the pi user (password: <you changed it>). Note that you now do not get the notice about configuration, as your RPI has been configured.
Attaching the USB drive
Verify that you supply your Raspberry with at least a 5V/1A power supply, 5V/2A is better (using a powered USB hub)
Use a drive of about 500Gb or more that you can spare for experimenting
Attach the (bus powered) drive to your USB hub that you've connected to the RPI.
To see what device name it has use this command: dmesg:
Look for the USB Mass Storage message, the example below is showing a 16Gb device that is attached as sda - take note of this device name.
Configure the USB drive for use
Change to root using: sudo su
Using the command fdisk - remove existing partitions: fdisk /dev/sda (note: use device name from the step above)
To delete existing partitons, use: d
When no more partitions exist, create one new partition using: n, p, 1, []default], []default]
Then change partition type to Linux using: t, 83 and write changes to disk using: w
Now create the filesystem using: mkfs.ext4 /dev/sda1 -c (option -c will check disk for errors before creating file system). If you don’t want to wait a long time then leave out the -c option.
Create a mount point in /etc/fstab for the USB drive: vi /etc/fstab and add a line like this: /dev/sda1 /home/samba ext4 defaults 0 0
(I’m mounting under /home but you can also mount under /mnt if you like)
Create the directory that you are mounting to: mkdir /home/samba
Mount the USB drive manually for testing: mount /dev/sda1 /home/samba
After mounting you can show the available space using the df command:
Space is shown in 1K blocks, I have around 14.5 Mb available (I'm using a thumbdrive for testing).
Reboot the RPI using the reboot command, logon again and verify that the USB drive is mounted automatically.
Install and configure Samba
Change to root using: sudo su
Install Samba using: apt-get install samba samba-common-bin samba-tools - the installer will ask you about additional disk space usage, answer Y(es).
The installer will start Samba when installation has completed:
[] ok ] Starting Samba daemons: nmbd smbd.
Now all that needs to be done is configuring Samba. I'll show how to create 2 shares, one group share and one public share. The public share is writable for everyone (anonymous) and the group share for all users, like the pi user.
Create a backup copy of the samba config file using: cp /etc/samba/smb.conf /etc/samba/smb.conf.org
Edit the samba config file using: vi /etc/samba/smb.conf and add 2 share definitions under Share Definitions:
[public]
comment = Public
path = /home/samba/public
valid users = @users
force group = users
create mask = 0664
directory mask = 0771
writable = yes
[shared]
comment = Shared
path = /home/samba/shared
force user = nobody
browsable = yes
public = yes
writable = yes
Uncomment this line under Authentication by removing the #: security = user
Under the Global section add: guest account = nobody
Create the 2 directories that will be shared and set access rights: #mkdir /home/samba/public /home/samba/shared
#chown root:users /home/samba/public /home/samba/shared
#chmod 775 /home/samba/public
#chmod 777 /home/samba/shared
Add a Samba password for the users you have, like this: #smbpasswd -a pi
After configuring is done, restart Samba to load the new configuration:
root@raspberrypi:/home# /etc/init.d/samba restart
[] ok ] Stopping Samba daemons: nmbd smbd.
[] ok ] Starting Samba daemons: nmbd smbd.
Now you can test Samba by connecting (mapping) a network connection to: \\raspberrypi\sharedor \\raspberrypi\public
You need a username and password (pi + samba password) to connect to public. Create a test folder will show you that the folder was created by the pi user:
root@raspberrypi:/home/samba/public# ls -l
total 4
drwxrwxr-x 2 pi users 4096 Aug 16 23:03 Test
If you connect to shared (without username and password) and create a test folder, you will see no owner (nobody):
root@raspberrypi:/home/samba/shared# ls -l
total 4
drwxr-xr-x 2 nobody nogroup 4096 Aug 16 23:06 test
Some notes
The Rasberry PI is not a very fast device when it's about IO and since the drive is USB connected, don't expect commercial NAS performance. But it's a cheap device to play with.
I was able to copy about 2.5Mb per second to the Raspberry PI NAS, compared to a similar setup with a BananaPI where I got about 17.5Mb per second
Data is stored on a single drive, no RAID or other means of data protection is available.
Thanks for reading this article. If you find it useful, you can click 'Good Article' below. If not, any feedback is welcome so I can update/improve this article. You can always send me a message. Thanks!
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
>> What is the transfer rate if 5-10 Users are connecting to the box?
The total transfer rate would be the same, so the 5-10 users would share bandwith, that's why it's a simple NAS.
The other device I mentioned (BananaPI) is a lot faster because it has a SATA interface to which you can connect a harddisk directly.
Thankyou Gerwin I've had my Rasp PI XBMC for about 5 years and now understand how to take it further than just a media device for mp4 on a SD card
XBMC is now Kodi.
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Comments (5)
Commented:
Very useful information :)
Voted Good Article :)
Regards,
Yashwant Vishwakarma
Commented:
Author
Commented:The total transfer rate would be the same, so the 5-10 users would share bandwith, that's why it's a simple NAS.
The other device I mentioned (BananaPI) is a lot faster because it has a SATA interface to which you can connect a harddisk directly.
Commented:
XBMC is now Kodi.
Author
Commented: