Skip to content

Shared directory

Setup a shared directory on Raspberry Pi

The following notes are used to setup a shared network drive that can be accessed by other computers on your network. The drive is to be connected to the Raspberry Pi through the USB 3.0 port of the Raspberry Pi. The software that will enable the file sharing is called Samba.

Note that this can be achieved on any Linux box, however these notes are specific to setting this up on a Raspberry Pi.

[1] Partition and Format the USB Drive as Ext3

  • unmount the drive if it's mounted by running sudo umount /dev/<partition>. If it fails, then you know the drive is not mounted.
  • run sudo mkfs.ext4 /dev/<partition> to set the file system of the partition
  • run sudo parted and them type print all to see all the drives and partitions on the machine, or
  • Run lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL,UUID,FSTYPE

[2] Create the shared directory

  • Create a drive in the /mnt/ directory of the Raspberry Pi by running sudo mkdir /mnt/shared-pi

[3] Mount the drive

  • Run sudo mount /dev/sda1 /mnt/shared-pi
  • Run df -h to confirm that the drive is mounted and that it is in the correct location
  • The drive needs to be automatically mounted every time the Raspberry Pi is rebooted, therefore run sudo vim /etc/fstab to edit the file
  • Add the following at the bottom of the file:
# Shared network drive
UUID=<uuid> /mnt/shared-pi ext4 defaults 0 0
  • Test that the automatic mounting will work by un-mounting the drive running sudo umount /dev/sda1
  • Run df -h to confirm that the drive is not mounted
  • Run sudo mount -a to automatically mount the drives specified in the /etc/fstab file. If something went wrong, you will have to edit the file
  • Run df -h to confirm that the drive is mounted once again

[4] Install Samba

  • Run sudo apt update
  • Run sudo apt install samba samba-common-bin smbclient cifs-utils
  • Choose "Yes" for the DHCP setting

[5] Edit Samba directory settings

  • Run sudo vim /etc/samba/smb.conf to edit the Samba settings
  • Add the following to the end of the file:
[shared-pi]
  path = /mnt/shared-pi
  read only = no
  public = no
  writable = yes
  create mask = 0777
  directory mask = 0777
  guest ok = no
  • Comment out all the lines related to the [homes] share to make the user's home not visible
  • Save the changes to the file
  • Create a samba password for the "pi" user to access the shared drive, run sudo smbpasswd -a pi
  • Restart the Samba service to make sure the configuration has taken effect, run sudo /etc/init.d/smbd restart and sudo /etc/init.d/nmbd restart
  • Run systemctl status smbd to check the status of the samba service

[6a] Connect to the shared drive from MacOS

  • Open finder
  • Click on Go > Connect to Server...
  • Write smb://<ip_address>
  • Click "Connect"
  • Enter in the username and password

[6b] Connect to the shared drive from TV

  • Install VLC on Google TV
  • In the settings, set it to use Samba version 1
  • Enter in user and IP address

[6c] Connect to the shared drive from Android

  • Install third-party file manager that has Samba client

[6d] Connect to the shared drive from Windows 10

-

[6e] Connect to the shared drive from Ubuntu


Test the transfer speed to the USB 3.0 drive

  • Run sudo hdparm -Tt /dev/sda to see the transfer speed between the Raspberry Pi and the external USB 3.0 attached drive
  • Note: the transfer speed of USB 3.0 is about 350 MBps

Test the transfer speed over the network (MacOS)

  • Make note of the file size in MB
  • Use a stop watch to time the transfer and convert the time to seconds
  • Divide the size by the time which will give you MBps

Test the transfer speed over the network (Windows)

  • Windows gives you a running average transfer speed in the popup window

Note

  • The transfer speed of 1 GbE is about 125 MBps
  • The transfer speed of 100 MbE is about 12.5 MBps