Wednesday 2 March 2011

Setting Up an XBMC Shared Library on Your LG-NAS

I bought an LG-NAS N2B1 to be a HomeFile Server.


Everything was fantastic until I decided to expand my digital empire to a dedicated Home Media System. I wanted to run XBMC on both computers whilst being able to share their libraries.

There is an excellent Lifehacker Guide on how to do this if you want run a MySQL database on one computer and leave it running. However the LG NAS has a built in MySQL server. Surely I can use that.


Well apparently not because LG has the port to access the MySQL database closed over a network.

It makes no sense to have a NAS fileserver and have to run a PC all the time to access a shared library.

After searching a couple of forums and learning how to install a custom firmware I came up with this work around

I hope you find it helpful. It took me a while to figure this out. If you know a quicker way please share.

STEP 1. ASSIGN A STATIC IP TO YOUR NAS

So your NAS IP does not jump around we want to lock the IP to a static number.

This is fairly straightforward.

Log on to your NAS by going: (you can find this using the NAS tools provided, or by clicking info or properties once you have mounted a volume) 
NAS_IP:8000
(i.e. 100.0.0.00 etc)

Log on using your username and password.

Then go to Network -> Interface.

Next set an IP and make a note of it. 

If you IP is something like 
101.0.0.3 
It might be an idea to set it to
101.0.0.99 so that you will easily remember it. 



Ta Da. Nice and easy.

STEP 2. OPEN THE LG MySQL PORT

Enable MySQL Server


For security the MySQL port is closed on the the LG NAS. So we have to now we have to enable the MYSQL server and then open the port so XBMC can access it.

Enabling MySQL is the easy part.

Log back on to your NAS by going:
NAS_IP:8000
(i.e. 100.0.0.00 etc)

Log on using your username and password.

Go to Web Services. Enable MySQL.




Open the MySQL Port Using SSH. 

Install Tantalus Firmware


The next step looks tricky but is fairly straightforward as long as you follow my instructions.

The LG default FIRMWARE does not allow you to access the files that we need to change.

The easiest way around this is to the the Tantalus Firmware. This is a custom firmware that builds opens up options like SSH (so you can access the filesystem) and a couple of other nifty features.

I installed it without any problems on my N2B1 LG-NAS, and it works on any N2R1 series models with a build for N1T1.

There is of a course a risk involved here. So BACKUP EVERYTHING. Config and Data.

If the firmware update fails it could potential swipe your drive. So make sure you are happy to continue.

Go to the Tantalus site and download the latest firmware build.

Once you have done this log back on to your NAS by going:
NAS_IP:8000
(i.e. 100.0.0.00 etc)

Log on using your username and password.

Then go to SYSTEM - FIRMWARE




Select the firmware and let it install. This should take a couple of minutes and restart the NAS.

Once it has restarted check your settings are the same and your data is still there.

Enable SSH.

Under your new settings you will notice SHELL unders Services.

Select this and then ENABLE SSH.


With this enabled we can log into the filesystem.

INTO THE RABBIT HOLE : SFTP

I am using a MAC but the theory should work well across Linux or Windows.

OSX has a rather nice SSH interface built into Terminal. For windows you will need to download PuTTY

 For browsing the files I am using CYBERDUCK which will has a Windows version. So the instruction will remain the same.

First we must locate the MYSQL Configuration Settings.

To do this Open Cyber Duck

Select SFTP. Input your NAS IP address

USERNAME 
root
PASSWORD
root




Click Connect. 

Now navigate to the / directory. It will open in root.

Navigate to 

/etc/mysql





Select the my.cnf folder

Select Edit and choose the text editor of your choice.

Then find the line 48

bind-address = 127.0.01

and change it to

bind-address =  {YOUR NAS IP or 0.0.0.0 - to listen for everything}


Save it.

INTO THE RABBIT HOLE : SSH COMMAND LINE



This is where those unfamiliar with command line interfaces might get confused.

We now need to be able to issue the NAS with commands.

You can close Cyberduck

Now open your SSH Command Line program of choice. PuTTY for Windows. Or Terminal for Mac

These instructions are for terminal but you should be able to follow them in PuTTY.

Select. FILE -> OPEN REMOTE CONNECTION


In the box next to Connect Enter

ssh root@YOURNAS IP.


Hit connect.

Input your password as 

root

Now input

mysql -u root -p mysql

Input your MYSQL password. This will be the one we set on at Step 2. When we enabled MySQL.



If you are unsure return to the Web Service page on the LG NAS Page.

Once entered we need to issue the following commands.

update user set host = '%' where user = 'root';

then

update db set host = '%' where user = 'root';

then

flush privileges;


then


\q


Once we have done this we then need to restart MySQL

Simple paste in

/etc/init.d/mysql restart


Now you should be able to access the port from outside the network.


Create a Database for XBMC.


With that done we now need to create a DATABASE for XBMC to use.

Return to the NAS back end and log in.

Under the new heading SERVICE MANGER you need to select PackageManager and install phpMyAdmin


This will enable you to easily setup your database.

Follow the link once the install completes.

It should be something like

http://lgnas/phpMyAdmin-LG-NAS


Login with the username
root
and password that you set at STEP 2.

Now simply create two databases

xbmc_video
xbmc_music


Then open each in turn. Go to PRIVILEGES


Add a new User
Username
xbmcHost
'Any Host'
Password
xbmc






Grant All Privileges onWildcard Name (username\_&)

Then Check All Global Privileges and click GO



STEP 3. CUSTOM DATABASE FOR XBMC

After all that this is very much the easiest step.

If you have an existing Database for XBMC. Go into Settings / Video / Export 

Now navigate to 

MAC HD \ Users \ YOUR USERNAME \ LIBRARY \ APPLICATION SUPPORT \ XBMC \ USERDATA

Create a file called

advancedsettings.xml

Now paste in the following information.

<advancedsettings>
<videodatabase><type>mysql</type><host>{NAS IP}</host><port>3306</port><user>xbmc</user><pass>xbmc</pass><name>xbmc_video</name></videodatabase>
<musicdatabase><type>mysql</type><host>{NAS IP}</host><port>3306</port><user>xbmc</user><pass>xbmc</pass><name>xbmc_music</name></musicdatabase>
 </advancedsettings>

Click Save. 

Open XBMC. Then go to setting and import your library.

You can check back using MyPHPADMIN to check the tables are populated



They will look like this if you have done everything correctly.

Trouble Shooting

One problem that cropped up during my attempts to get the NAS working was a odd error. Where I was able to import the library and it appeared correctly as above but with only 14 tables.

Checking my LOG ( user / library / logs / xbmc.log - on mac ) I found the following error

ERROR: SQL: Undefined MySQL error: Code (1071)Query: CREATE UNIQUE INDEX ix_path ON path ( strPath )
This problem is caused because the default Language the database uses UTF8 causes some glitches with certain characters. If you have actors in your database with accents on characters in their names the whole database creation process stalls and XBMC gets very confused.

The fix to this is to go into MyPHPadmin and drop the whole database and start over.

You can then create a new database for both xbmc_video then xbmc_music and use the following SQL command.

(You could also do this through SSH in terminal if you prefer) 


'ALTER DATABASE `xbmc_video` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci'
Then

ALTER DATABASE `xbmc_music` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci
Or alternatively use the command to create and define the databases in one go.

CREATE DATABASE IF NOT EXISTS xbmc_video DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci
Then

CREATE DATABASE IF NOT EXISTS xbmc_music DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci 
You can then simply restart XBMC and reimport your library.





-------------

I HOPE YOU HAVE FOUND THIS HELPFUL.

REMEMBER THIS TUTORIAL IS AD SUPPORTED ;-)




4 comments:

  1. thanks for this man. looking forward to testing @ home tonight.

    ReplyDelete
  2. I try this guide an all the steps work perfect but when i go in to xbmc an looking for my video there not there - what did i do wrong ?

    ReplyDelete
  3. I followed this step by step and it worked perfectly. My only mistake was I used ssh instead of ftp to edit the my.cnf file. I normally use nano but had to use vim and used :q! to save the file instead of :wq It wasn't until i ran netstat -nap until I saw that it was only bound to 127.0.0.1 That was totally my fault though. Great Guide.

    ReplyDelete
  4. Olá tem como republicar as imagens quero fazer um meu LGnas

    ReplyDelete