Wednesday, January 14, 2015

Some Nerd Notes - Multiple kodi/xbmc Raspberry Pi's

I've finally been trying to set up a second Raspberry Pi running Raspbmc (Kodi) ... and it's been a mission!

So I thought I'd document what I've found (and the pitfalls that don't seem to be documented).

Firstly, ssh into the Raspberry Pi you intend to use as your server. The defaults are:
Username: pi
Password: Raspberry

Firstly, sharing the files:

Uh-oh....

Okay, here's the problem. For some strange reason, the pi doesn't always mount the USB drives on boot. I used uuid's as I didn't want the uncertainty of the two drives that I've got having different designators when udev finds them. So here's what that part of /etc/fstab looks:

 /dev/disk/by-uuid/73321d6f-daeb-4201-b300-c37d3d3c91a8   /srv/nfs/movies ext4     defaults,noatime 0 2  
 /dev/disk/by-uuid/f2e5e6bd-9b11-4d1c-b399-a75d69931a5b   /srv/nfs/tv   ext4     defaults,noatime 0 2  


You'll need to find out which drive is which by running this command:






ls -l /dev/disk/by-uuid/

and:

mount

You should be able to figure it out from there....

Given that Raspbmc is a Debian based distribution, it makes sense to use NFS shares - Kodi supports it and it has less overhead than CIFS/SMB.

Setting up the server:

This should be easy right? Really really simple... But... unfortunately...
So loads and loads of tutorials will tell you that all you have to do is install nfs-kernel-server and set up your exports. This just won't work. There's a couple of problems to solve first.

rpcbind

I'm not sure this is necessary (I'd love it if someone could give this a go without this step).

This isn't enabled by default and is needed by nfs-common. Furthermore, update-rc.d just isn't set up correctly. So... you can't just tell it to load up on default runlevels. Instead you have to issue this command:

sudo update-rc.d rpcbind enable S 2 3 4 5

Get a blank slate

It seems even though rpcbind AND nfs-common are both installed by default, they just won't play nice. So issue the following command:

sudo apt-get install --reinstall rpcbind nfs-common nfs-kernel-server

If everything has gone right, you should get a warning about there being no exports.

Set up the directory structure for exports

This bit may seem a little unnecessarily fiddly, but bear with me.

To keep things a little cleaner, I'm going to create a directory: /srv/nfs and from there, create the directories I want to share. For me that's:

/srv/nfs/tv
/srv/nfs/movies

Set up the exports file

In /etc/exports add the following lines:

/srv/nfs        192.168.3.0/24(ro,no_subtree_check,insecure)
/srv/nfs/tv     192.168.3.0/24(ro,no_subtree_check,insecure)
/srv/nfs/movies 192.168.3.0/24(ro,no_subtree_check,insecure)

They're read-only (this could be fixed later - change the ro to rw) at this stage. Make sure the directories match up to your own. Change the allowed IP range and subnet to match your own.

Finishing Up

The boring bit... testing. Okay, so now the settings are all there. We need to get those settings refreshed. Use the following command:

sudo service nfs-kernel-server restart

And finally, test it:

showmount -e localhost

It should now show all of your exports.

Setting up shares on the clients

Your server also needs to be a client. This is so that we can generate the database so that all of your Raspberry Pi's can use the same information. So start with the server. For this bit, you need to be sitting in front of the TV that the server is installed on.

Go to: Videos ▶ Files ▶ Add Movies ▶ Browse ▶ Network Filesystem (NFS)

Do this on all of your clients (and try to set them all up in the same way).

Sharing the Library

Setting up the server

By default, kodi (xbmc) uses sqllite which seems great for a single machine! But not so good when you need to share that database. So we need to use mysql. SSH into the server again.

Firstly, we need to install mysql. Issue the following command:

sudo apt-get install mysql-server

Set up a kodi user for the database:

mysql -u root -p

Use the password you entered during the mysql-server installation.

CREATE USER 'kodi' IDENTIFIED BY 'kodi';
GRANT ALL ON *.* TO 'kodi';
/q

Setting up Clients

Remember, your server is a client. So do this on your client first. This requires being in ssh.

cd ~/.kodi/userdata

Create a file called "advancedsettings.xml" (Using nano... it's just easier). In it, put in the following:
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>192.168.3.70</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>192.168.3.70</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>

Save the file and exit it. Now... this same file can be used on all of your clients. So copy it over...
scp advancedsettings.xml pi@192.168.3.71:/home/pi/.kodi/userdata

Rinse and repeat for each client.

Populating the Database

Set up your content USING THE NFS SHARES! This is important. You can do this from a client, just to be sure. I don't recommend trying to update the library from multiple clients at the same time (where the server is a client...) - this caused my server to crash.

More reading:

I ended up having to debug this as it all broke again. If it breaks for you, or you want to avoid it breaking, check out this post.

No comments:

Post a Comment