Mounting network shares

From OpenELEC
Jump to: navigation, search

This guide will show you how to access media from your NAS on your OpenELEC computer and make them permanently available.

To mount files, we need to get access to your configuration files on the OpenELEC files.

Fortunately, OpenELEC shares this folder so you can access it from your computer (unless you've removed it previously).

If you have experience with Linux, you can use SSH to open a terminal to your OpenELEC machine (there are guides on how to do this elsewhere on the site); the configuration files are held in /storage/.config and you can use vi or nano to edit them.

Contents

New Method

Since OpenELEC 4.0.x you can now use systemd to control network mounts. It is a little more complicated, but makes it easy to enable and disable.

Systemd CIFS sample mount

/storage/.config/system.d/storage-music.mount

 [Unit]
 Description=cifs mount script
 Requires=network-online.service
 After=network-online.service
 Before=kodi.service

 [Mount]
 What=//192.168.0.31/Music
 Where=/storage/music
 Options=username=myusername,password=mypassword,rw
 Type=cifs

 [Install]
 WantedBy=multi-user.target

And here is what all this means.

Description=test cifs mount script
  • The description should be used to explain what this servicefile is for
Requires=network-online.service
  • Network mounts *require* 'network-online.service' which checks if the network is online
After=network-online.service
  • Our scripts must start *after* 'network-online.service', on timeout and if 'network-online.service' fails we can not mount and this scripts fails too
Before=kodi.service
  • Usually we mount networks shares because we want they available *before* XBMC starts. So XBMC has access to this mounts from beginning. Note: this slows down the boot!
What=//192.168.0.31/Music
  • The share we want mount
Where=/storage/music
  • Where we want mount this share
Options=username=myusername,password=mypassword
  • Any options you usually use with the "-o" parameter in the mount command
Type=cifs
  • Filesystem type
WantedBy=multi-user.target
  • The target is used by 'servicectl enable <name_of_this_file.mount>' to link this service to a runlevel for starting on boot. usually 'multi-user.target' is ok here.

Slashes "/" MUST BE REPLACED with dashes "-" with .mount as extension. This means, if we want mount to "/storage/music" (see above "Where=/storage/music") then this file must be renamed to 'storage-music.mount'

Enabling the CIFS mount

This mount can then be enabled via ssh with the command

systemctl enable storage-music.mount

Systemd NFS sample mount

/storage/.config/system.d/storage-movies.mount

[Unit]
Description=test nfs mount script
Requires=network-online.service
After=network-online.service
Before=kodi.service

[Mount]
# The share we want mount
What=192.168.0.31:/movies
Where=/storage/movies
Options=
Type=nfs

[Install]
WantedBy=multi-user.target

And here is what all this means.

Description=test nfs mount script
  • The description should be used to explain what this servicefile is for
Requires=network-online.service
  • Network mounts *require* 'network-online.service' which checks if the network is online
After=network-online.service
  • Our scripts must start *after* 'network-online.service', on timeout and if 'network-online.service' fails we can not mount and this scripts fails too
Before=kodi.service
  • Usually we mount networks shares because we want they available *before* XBMC starts. So XBMC has access to this mounts from beginning. Note: this slows down the boot!
What=192.168.0.31:/movies
  • The share we want mount
Where=/storage/movies
  • Where we want mount this share
Options=
Any options you usually use with the "-o" parameter in the mount command
Type=nfs
  • Filesystem type
WantedBy=multi-user.target
  • The target is used by 'servicectl enable <name_of_this_file.mount>' to link this service to a runlevel for starting on boot. usually 'multi-user.target' is ok here.

Slashes "/" MUST BE REPLACED with dashes "-" with .mount as extension. This means, if we want mount to "/storage/music" (see above "Where=/storage/music") then this file must be renamed to 'storage-music.mount'

Enabling the NFS mount

This mount can then be enabled via ssh with the command

systemctl enable storage-movies.mount

Notes

The CIFS mount may require a username/password to work. Test it via command line using the mount command first.


Old Method

If you don't know Linux, then you can simply follow the guides below. From a Windows PC, open an explorer window and browse to the IP address of the OpenELEC machine. If you don't know what the IP address is, go to the menu of the OpenELEC machine and click the "Info" button on your remote control (or the i key). This will open a page that shows the IP address, so type this into the address bar of the explorer window. For example, if your IP address is 192.168.1.92, browse to:

 \\192.168.1.92

Once the window appears, open the Configfiles share. This will show you all the configuration files for your OpenELEC machine.

You create a file called autostart.sh (If it does not exist yet).

Open the file with a UNIX compliant text editor like | Textpad. Windows' built-in editors like Notepad and Wordpad may cause problems, so don't use them.

And copy the following code into the file:

 #!/bin/sh
 (sleep 30; \
 COMMAND_THAT_RUNS; \
 )&

if you want to mount a cifs (samba) share replace COMMAND_THAT_RUNS with the following, substituting the ip, user and mountpoints by your own.

 mount -t cifs -o username=user,rw //10.0.0.101/music /storage/music

if you want to mount a nfs (Version 4) share replace COMMAND_THAT_RUNS with the following, substituting the ip and mountpoints by your own.

 mount -t nfs 10.0.0.101:/storage01 /storage/mount -o nolock;

if you want to mount a nfs (Version 3) share replace COMMAND_THAT_RUNS with the following, substituting the ip and mountpoints by your own.

 mount -t nfs 10.0.0.101:/storage01/shared/music /storage/music -o nolock;


Example 1:

If we're running a NAS or Linux server with an NFS share of /nfs/music, an IP address of 192.168.1.2 and we're going to mount it at /storage/music we'll have a autostart.sh that looks like:

 #!/bin/sh
 (sleep 30; \
 mount -t nfs 192.168.1.2:/nfs/music /storage/music -o nolock; \
 )&

Example 2:

If we're running a Windows server (or Linux server with SAMBA) with a share called tvseries, an IP address of 192.168.0.30 and we're going to mount it at /storage/tvseries we'll have a autostart.sh that looks like:

 #!/bin/sh
 (sleep 30; \
 mount -t cifs -o username=user,rw //192.168.0.30/tvseries /storage/tvseries; \
 )&

There needs to be a username, ohterwise you will get a error when mounting.

Example 3:

Again, if we're running a Windows server (or Linux server with SAMBA) with a share called tvseries, an IP address of 192.168.0.30 and we're going to mount it at /storage/tvseries, but this time we need to use the username gilphilbert and the password mysecret we'll have a autostart.sh that looks like:

 #!/bin/sh
 (sleep 30; \
 mount -t cifs -o username=gilphilbert,password=mysecret,rw //192.168.0.30/tvseries /storage/tvseries; \
 )&

Example 4:

We want more then one share, in this case your autostart.sh will look like this:

 #!/bin/sh
 (sleep 30; \
 mount -t nfs 10.0.0.101:/storage01 /storage/nfs01 -o nolock; \
 mount -t nfs 10.0.0.102:/storage02 /storage/nfs02 -o nolock \
 )&

In the end reboot the machine and you can start using the share(s).

Example 5: Advanced

Here we do something a little more creative. we try to ping the server until it answers and then mount. Shares will be mounted under /media/share1 and so on...

Change the server and shares variables to your server and shares settings.

 #!/bin/sh
 n=1
 
 server=192.168.1.1
 shares="share1 share2"
 # can be nfs for nfs or cifs for samba or windows shares
 type=nfs
 
 until ping -w 1 -c 1 "$server" &>/dev/null ;do
   sleep 1
   n=$(( n+1 ))
   [ $n -eq 30 ] && break
 done
 for share in $shares ;do
   [ -d /media/$share ] || mkdir -p /media/$share
   if [ $type == cifs ];then
     mount -t $type //$server/$share /media/$share
   elif [ $type == nfs ];then
     mount -t $type $server:/$share /media/$share
   fi
 done
 ln -sf /media /storage/media

Notice that here we dont use the ( ... )& that is because we want the shares mounted before xbmc starts.

Note on cifs: if you use cifs share you might need to add the username= and password= options from above, joust add them to the cifs mount command.

a link is created from /media to /storage/media

Linux Commandline help (Mostly Eden)

Lets say we want to mount 2 nfs shares in the 2 following locations:

 /storage/nfs01
 /storage/nfs02

First you login to your openelec machine, using ssh.


Then you do the following:

 cd /storage
 mkdir nfs01
 chown openelec:openelec nfs01 (Not sure about this one but its working for me, might also work with just root being the owner.)
 mkdir nfs02
 chown openelec:openelec nfs02 (Same as above)

Next check if the autostart.sh file is already in place or not:

 cd /storage/.config
 ls -la

This wil give you a list of files in the .config directory.

If the autostart.sh file is already there do:

 vi autostart.sh

Else do:

 touch autostart.sh
 chmod +x autostart.sh
 vi autostart.sh

If you know vi, then just make the file look like you want, an example is shown below.

If you don't know vi, then press "i" and paste the example in there, then press "ESC", then press shift ":", you will get a commanline like thing, at the bottom of your screen, enter "w" and press <enter>. Press shift ":" again, in the commandline like thing enter "q" and press <enter>. This will save and quit the file.

autostart.sh sample (For more exaples see the Eded/Frodo howto):

 #!/bin/sh
 (sleep 15; \
 mount -t nfs 10.0.0.101:/storage01 /storage/nfs01 -o nolock; \
 mount -t nfs 10.0.0.102:/storage02 /storage/nfs02 -o nolock
 \
 )&

Troubleshooting

nfsv3 vs nfsv4

If you are using nfsv3, your remote path might look like /storage01/somedir/stuff, if you are using nfsv4 it might look like /storage01

Update: NFSv4 is not supporten by OpenELEC, it needs idmapd to work...

 # mount -t nfs -o vers=4 server:/share /storage/share
 mount: NFSv4 not supported
 mount: mounting server:/share on /storage/share failed


Nothing happends

Try running your mount command from the commandline to see if that gives you any errors:

 mount -t nfs 10.0.0.102:/storage02 /storage/nfs02 -o nolock

If that doesnt work try running the autostart file from the commandline, to see if you get any errors:

 cd /storage/.config
 ./autostart.sh

Catagory:Configuration

Personal tools
Namespaces
Variants
Actions
Donate
Navigation
Wiki help
Toolbox