Simple NAS with a Raspberry PI

Gerwin JansenEE Topic Advisor
Apple, Debian, EE, Hardware, MBP, Oracle, Raspberry PI, Shell Scripting, SQL, Testing, Tibco, Windows
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:
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.
  1. Install a SD card with Raspbian
  2. Startup and configuring your RPI
    • 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.
  3. 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:
      [] 1163.294609] usb-storage 1-1.3.4:1.0: USB Mass Storage device detected
      [] 1163.296269] scsi host0: usb-storage 1-1.3.4:1.0
      [] 1164.330052] scsi 0:0:0:0: Direct-Access              Patriot Memory   PMAP PQ: 0 ANSI: 0 CCS
      [] 1164.386652] sd 0:0:0:0: Attached scsi generic sg0 type 0
      [] 1166.867096] sd 0:0:0:0: []sda] 31309824 512-byte logical blocks: (16.0 GB/14.9 GiB)
      [] 1166.867806] sd 0:0:0:0: []sda] Write Protect is off
      [] 1166.867849] sd 0:0:0:0: []sda] Mode Sense: 23 00 00 00
      [] 1166.868448] sd 0:0:0:0: []sda] No Caching mode page found
      [] 1166.868487] sd 0:0:0:0: []sda] Assuming drive cache: write through
      [] 1166.905454]  sda: sda1
      [] 1166.909389] sd 0:0:0:0: []sda] Attached SCSI removable disk
    • 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.
  4. 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:
      root@raspberrypi:/home# df
      Filesystem     1K-blocks    Used Available Use% Mounted on
      rootfs          15079896 2574784  11842140  18% /
      /dev/root       15079896 2574784  11842140  18% /
      devtmpfs          218636       0    218636   0% /dev
      tmpfs              44584     264     44320   1% /run
      tmpfs               5120       0      5120   0% /run/lock
      tmpfs              89160       0     89160   0% /run/shm
      /dev/mmcblk0p1     57288   19400     37888  34% /boot
      /dev/sda1       15276976   38224  14439676   1% /home/samba
    • 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.
  5. ​    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/
    • Edit the samba config file using: vi /etc/samba/smb.conf and add 2 share definitions under Share Definitions:
        comment = Public
        path = /home/samba/public
        valid users = @users
        force group = users
        create mask = 0664
        directory mask = 0771
        writable = yes

        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\shared or
    • 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
  6. 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!
Gerwin JansenEE Topic Advisor
Apple, Debian, EE, Hardware, MBP, Oracle, Raspberry PI, Shell Scripting, SQL, Testing, Tibco, Windows

Comments (5)


Hi Gerwin
Very useful information :)

Voted Good Article :)

Yashwant Vishwakarma
Imran SaeedIT Technical Director

What is the transfer rate if 5-10 Users are connecting to the box?
Gerwin JansenEE Topic Advisor
Most Valuable Expert 2016
Community Leader 2022


>> 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.
Gerwin JansenEE Topic Advisor
Most Valuable Expert 2016
Community Leader 2022


Thanks and you're welcome :)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.