How to share a folder on Ubuntu to Raspberry Pi 3 over local WiFi network?
I am planing to buy RaspberryPi 3 and have it connected to my TV. I also have a lot of movies on Windows partition in my dual boot Ubuntu 14.04 & Win 8 machine (Win 8 isn't used, but is there). I would like to share the movies folder to RaspberryPi over my WiFi, so that I can watch movies on TV without loading the movie file to RaspberryPi.
Can this be done and how?
my favourite method is via SSHFS.
Install openssh server on your Ubuntu machine:
sudo apt-get install openssh-server
Install sshfs on the Raspberry Pi (don't know the package name for the distro you're running), in Ubuntu:
sudo apt-get install sshfs
Connect to your ssh server by mounting a folder:
sshfs username_on_server@server_ip:/location_of/movies_on_Server /mountpoint/on_rasberry_pi
You might have to add your Rasberry Pi user to the fuser group:
sudo useradd -G {group-name} username
to unmount the remote folder:
fusermount -u /mountpoint/on_rasberry_pi
Enjoy.
In addition to the above, you could use samba shares. Instructions are here.
This is definitely supported by KODI (openELEC, Osmc or other), which is what I would install on the raspberry pi, if you want to use it as a media player for the TV, and resembles my setup.
(Though I think kodi also sees NFS)
Here is a summary of the instructions (credit goes to the original author):
Procedures
Install Samba
sudo apt-get update
sudo apt-get install samba
Set a password for your user in Samba
sudo smbpasswd -a <user_name>
Note: Samba uses a separate set of passwords than the standard Linux system accounts (stored in /etc/samba/smbpasswd), so you'll need to create a Samba password for yourself. This tutorial implies that you will use your own user and it does not cover situations involving other users passwords, groups, etc...
Tip 1: Use the password for your own user to facilitate.
Tip 2: Remember that your user must have permission to write and edit the folder you want to share.
Eg.:
sudo chown <user_name> /var/opt/blah/blahblah
sudo chown :<user_name> /var/opt/blah/blahblah
Tip3: If you're using another user than your own, it needs to exist in your system beforehand, you can create it without a shell access using the following command : sudo useradd USERNAME --shell /bin/false
You can also hide the user on the login screen by adjusting lightdm's configuration, in /etc/lightdm/users.conf add the newly created user to the line :
hidden-users=
Create a directory to be shared
mkdir /home/<user_name>/<folder_name>
Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error
sudo cp /etc/samba/smb.conf ~
Edit the file "/etc/samba/smb.conf"
sudo nano /etc/samba/smb.conf
Once "smb.conf" has loaded, add this to the very end of the file:
[<folder_name>]
path = /home/<user_name>/<folder_name>
valid users = <user_name>
read only = no
Tip: There Should be in the spaces between the lines, and also there should be a single space both before and after each of the equal signs.
Restart samba:
sudo service smbd restart
Once Samba has restarted, use this command to check your smb.conf for any syntax errors
testparm
To access your network share
sudo apt-get install smbclient
# List all shares:
smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>
# connect:
smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>
To access your network share use your username () and password through the path "smb:////" (Linux users) or "\\\" (Windows users). Note that "" value is passed in "[]", in other words, the share name you entered in "/etc/samba/smb.conf".
Note: The default user group of samba is "WORKGROUP".
It can be done with NFS.
This is useful to read about: How do I mount directories from other Linux/Unix/BSD servers? How do I mount an NFS share?
How to setup NFS in Ubuntu: SettingUpNFSHowTo
Ubuntu NFS Server Configuration
Below example shares Public directory (located in pba user home directory) to 10.0.0.1 IP address
Install NFS Server
sudo apt-get install rpcbind nfs-kernel-server
Make sharing directory and set permissions
mkdir -p ~/Public
chmod 777 ~/Public
Add new share to /etc/exports
echo "/home/pba/Public 10.0.0.1(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
rw makes the share read/write, and sync requires the server to only reply to requests once any changes have been flushed to disk. This is the safest option (async is faster, but dangerous. It is strongly recommended that you read man exports.
Export new share
sudo exportfs -ra
Restart NFS kernel server
sudo service nfs-kernel-server restart
Server is now ready.
Raspberry Pi Client Side Configuration
In below example 10.0.0.12 is a NFS server IP address with /home/pba/Public share
Install NFS, portmap and start services
sudo apt-get install nfs-common portmap
sudo service rpcbind start
sudo update-rc.d rpcbind enable
Make mount directory and mount NFS
mkdir ~/Public
sudo mount -v -t nfs 10.0.0.12:/home/pba/Public /home/pi/Public
Seeing results:
$ cd ~/Public && ls
Ubuntu file Ubuntu file~
Add line to /etc/fstab to make changes permanent
echo "10.0.0.12:/home/pba/Public /home/pi/Public nfs rsize=8192,wsize=8192,timeo=14,intr 0 0" | sudo tee -a /etc/fstab
For Windows
I've download FreeNFS for Windows. FreeNFS path set to C:\Public
.
To mount FreeNFS share mount need to be done like this
sudo mount -v -t nfs 10.0.0.12:/ /home/pi/Public