Welcome to part two of our Raspberry Pi with OpenElec tutorial. Part 2 of our tutorial will focus on speed and stability improvements for our Raspberry Pi.
At this point, you should have an overclocked Rasberry Pi with OpenElec installed, booting from the SD card with the “Storage” partition on the USB drive. You should NOT have a wireless dongle plugged in or any other USB devices, save for a keyboard.
The reason you don’t want to plug-in another USB device is because we weren’t very specific when we coded the “cmdline.txt” file. We basically told the OS to mount the “Storage” partition to the first USB device the OS identifies. If you have a wi-fi dongle (heh… dongle, funny word) plugged in, the OS might try to mount the “Storage” partition to the wi-fi dongle, which obviously won’t work. Later in this tutorial, we are going to edit the “cmdline.txt” file to uniquely identify our USB drive and mount the “Storage” partition to that regardless of what other USB device you plug into the Raspberry Pi.
Before we get into the next steps, I’m going to talk a bit about the programs we will be using.
SFTP stands for (Secure File Transfer Protocol) and is just like FTP (File Transfer Protocol) except it’s, you know… secure and stuff (feel free to Google if you want something more technical.) SFTP uses port 22 by default and we will use it to transfer files from our computer to the “Storage” partition the Rasperry Pi. This is where you’ll need either Cyberduck (Mac) or FileZilla (PC) that I listed in part one of this tutorial.
Secure Shell is a cryptographic network protocol for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers. If you read that and thought, “English mother f*****, do you speak it?!?!”, then you’re probably my buddy Mitch, or you’re my other buddy Dave and you just thought of Mitch and laughed. Fear not baby birds, I’m gonna feed you. SSH is a little window on your computer that allows you to send commands to the Raspberry Pi and for the Raspberry Pi to send information back to you. We are going to use it to keep an eye on how much processing power the Raspberry Pi is using, kind of like Task Manager on a Windows computer. OpenElec enables SSH by default, and you can login with the default username “root” and password “openelec“. If you’re on a Mac, you’ll use Terminal if you’re on a Windows machine, you’ll use Putty.
- Tweak the GUI settings within XBMC to turn off resource heavy features that may slow down your Raspberry Pi
- Create the “advancedsettings.xml” file that contains other settings that will speed up your Raspberry Pi and keep CPU usage within an acceptable range
- Find out the UUID of the USB drive that contains your “Storage” partition and edit the “cmdline.txt” file to mount the “Storage” partition to your USB drive specifically instead of the first USB device is sees
GUI Settings on XBMC
If you’ve followed the directions precisely as stated thus far, you may find yourself sitting in front of a screen with a OpenElec wizard dialog on the screen asking you to go through some basic settings, but with no way to control the device. There are a few ways to control the Raspberry Pi.
Method #1 (The Easy Way)
Plug in a USB keyboard to the Raspberry Pi (May require reboot of the Raspberry PI). See? That was easy right?
Method #2 (The Hard, but Lazy Way)
This is the hard way because it requires that you SFTP into your Raspberry Pi, edit the “guisettings.xml” file manually and reboot; that’s the hard bit. The lazy part is where you don’t have to go find a USB keyboard and instead get to download an app on your phone or tablet, enter some settings, and then configure the rest of the XBMC interface from your couch like a slacker should.
Step 1: Find out the local IP address of your Raspberry Pi, you can find this by logging into your router and seeing which IP address your router assigned the Raspberry Pi.
Step 2: SFTP into the Raspberry Pi using Putty or Cyberduck. Both programs will want you to enter the local IP, set to port 22, use the username “root” and the password “openelec” (without the quotes).
Here are my config screens for each application.
Once you’ve successfully SFTP’d into your Raspberry Pi, you’ll navigate to “.xbmc/userdata/” and find the “guisettings.xml” file. You’ll then want to copy that file to your desktop and open it using either “Textpad” or “TextWrangler”.
***NOTE*** If you can’t see the files beginning with a period like “.xbmc” then your FTP program is not configured to see hidden files. Head to the settings of your application and enabled view of hidden files and folders.
Here’s how you navigate to the file:
Once you open the file, you’re going to look for the following bit of code (I did a search for “web server”).
<services> <airplay>false</airplay> <airplaypassword></airplaypassword> <devicename>LivingRPi</devicename> <esallinterfaces>false</esallinterfaces> <escontinuousdelay>25</escontinuousdelay> <esenabled>true</esenabled> <esinitialdelay>750</esinitialdelay> <esmaxclients>20</esmaxclients> <esport>9777</esport> <esportrange>10</esportrange> <upnpannounce>false</upnpannounce> <upnprenderer>false</upnprenderer> <upnpserver>false</upnpserver> <useairplaypassword>false</useairplaypassword> <webserver>true</webserver> <webserverpassword>xbmc</webserverpassword> <webserverport>8081</webserverport> <webserverusername>xbmc</webserverusername> <webskin>webinterface.default</webskin> <zeroconf>false</zeroconf> </services>
You’ll want to edit your setting to closely match mine. Set the server to “true“, then you can choose whichever port you want to use and the username and password you want to use (don’t mess with any other settings in this file). Then save this file, upload it to the “/userdata” directory of your Raspberry Pi, overwriting the one that is there, and restart the Raspberry Pi. After the restart, you can use whichever app you want on your phone or tablet to navigate XBMC.
Turn These Things Off
Now that we can control XBMC, let’s go through the OpenElec wizard and then adjust some settings to make it run faster.
In the OpenElec wizard, choose these options:
- English ( I presume since you’re reading this )
- US Keyboard ( Again, since you’re reading this )
- Set Hostname to something like “BedroomRPi” ( Your choice really )
- Turn on SSH, Turn off Samba
In the settings, make your screens match the ones below (If I don’t show a menu in the screenshots below, you can leave them at their defaults. Some settings, like your screen resolution, will vary. Mostly you’re looking at things I have turned off in the screenshots below):
I should comment here that the settings are not an exact science. I’ve read through many forums from different times and different releases of OpenElec (even Rasbmc), and different people point to different GUI settings for speed improvements. Your results may vary and you may want to test a few of these toggles to see what’s important to you and how much slow down you can live with.
Creating the “advancedsettings.xml” File
***Note*** If you don’t want to make the file yourself and don’t care what settings I’m suggesting and what they do, you can download the “advancedsettings.xml” file for the Raspberry Pi below.
The “advancedsettings.xml” file is not created by default on any XBMC installation. This is a file that is similar to the “guisettings.xml” file that we edited above, but instead of changing features that you can turn on and off in the GUI of XBMC, it turns things on and off that you can’t see in the GUI. We’re going to use this file to enable features that will help to speed up the Raspberry Pi by limiting how much processing power it uses to perform functions.
<advancedsettings> <network> <cachemembuffersize>5282880</cachemembuffersize> </network> <fanartres>560</fanartres> <imageres>256</imageres> <gui> <algorithmdirtyregions>3</algorithmdirtyregions> <nofliptimeout>0</nofliptimeout> </gui> <lookandfeel> <enablerssfeeds>false</enablerssfeeds> </lookandfeel> <bginfoloadermaxthreads>2</bginfoloadermaxthreads> </advancedsettings>
After you paste the content into the text editor, save the file as “advancedsettings.xml” and then upload it to the “/userdata” folder of your Raspberry Pi using the SFTP program we used earlier in this tutorial. Be sure to save the file as “advancedsettings.xml” and not “advancedsettings.xml.txt“. Some text editors may try to save it that way and it will not work. If you got the .txt extension then you’re probably being lazy and using notepad or textedit, don’t do that. When finished, reboot (unplug and plug back in) the Raspberry Pi.
Here’s what all these settings mean. You can find out more about these settings and the “advancedsettings.xml” file at this website.
<cachemembuffersize> = Number of bytes used for buffering streams ahead in memory XBMC will not buffer ahead more than this. WARNING: for the bytes set here, XBMC will consume 3x the amount of RAM When set to 0 the cache will be written to disk instead of RAM, as of v12 Frodo.
<fanartres> = Specify the resolution that cached fanart should be resized to in pixels. The width is automatically calculated as being 16/9* height. Only images that are exactly 16×9 and equal to or greater than this resolution will be cached at this size – all other images will be cached using . The default value is 1080.
<imageres> = Specify the maximal resolution that art should be resized to in pixels. The width is automatically calculated as being 16/9* height. The image will be resized to fit within this size. e.g. an image that is 2000×500 will be cached at size 1280×320. An image that is 500×800 will be cached at size 450×720 using the default value of 720.
<algorithmdirtyregions> = Enable dirty-region processing. Dirty regions are any parts of the screen that have changed since the last frame. By not re-rendering what hasn’t changed, big speed gains can be seen. Because all GPUs work differently, only Mode 3, combined with nofliptimeout=0, is guaranteed to be safe for everyone, but current timing issues with nofliptimeout keep this from being the default.
<nofliptimeout> =Specifies the timeout in milliseconds after which XBMC will not flip the graphics buffers anymore when nothing has been rendered, this lowers both CPU and GPU usage.
- -1: disabled
- 0 or higher: timeout in milliseconds (0 is default)
<bginfoloadermaxthreads> = Control the number of threads in the background info loader thread pool (thumb generator, flagging, etc). Useful for tuning platforms that are low on CPU, like Intel Atom based systems. (Note, this item will be removed in the next release of XBMC (Gotham).
Verifying CPU Usage on Raspberry Pi
We are now going to use our SSH utility discussed at the beginning of this tutorial to login to our Raspberry Pi and see if the CPU usage is at an acceptable level. For this you’ll need Terminal on your Mac or Putty on your Windows machine.
Here are the commands:
ssh root@YourRaspberryIPAddress openelec top
For example, here is what my terminal window looks like:
***NOTE*** You will not see any letters on the screen when you type your password; this is normal. Just type the word “openelec” without the quotes. To stop the “top” command from running type “ctrl + c“.
If you look in the pictures above, when the results from the “top” command show up, you’ll see the cpu usage for xbmc.bin. You’ll want to try to navigate around the UI in XBMC and watch this number while you’re doing it. You’ll see it jump up as you’re moving around in XBMC, but it should settle back down to 15-30% in a few seconds. If it doesn’t and instead stays steady at 90% or more, you have an issue. Try rebooting, maybe adjust the GUI settings until you can keep your CPU from idling at 90% usage. If my settings aren’t working for you, you may want to google it a bit to see if there’s some new info out there. These settings worked for me though.
Get the UUID of your USB Drive
As I stated at the beginning of the tutorial, the way we configured the “cmdline.txt” file was a bit vague. The reason we did it that way is because we need a command line utility on linux to run the commands (at least with the method I’m giving you.) Since OpenElec runs on linux, we can simply use our SSH utility to run the commands we need to find out the UUID.
Make sure your Raspberry Pi is on and then login via SSH using the commands we used to get to the “top” screen. Type “ssh [email protected]” (replacing the IP I have here with the local IP address of your Raspberry Pi), then type your password (openelec) then hit enter. Once you’re into the Raspberry Pi, we want to type the following commands.
This command will spit out a window that has a ton of information, but you’re looking for text that looks something like what I have below (It will be near the end of what the command outputs).
[ 5.387198] sd 0:0:0:0: [sda] 31457280 512-byte logical blocks: (16.1 GB/15.0 GiB) [ 5.388139] sd 0:0:0:0: [sda] Write Protect is off [ 5.388169] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00 [ 5.389005] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [ 5.396185] sda: sda1 [ 5.400502] sd 0:0:0:0: [sda] Attached SCSI removable disk
The part we want to pay attention to is where it says [sda]. That’s probably what yours says, but if it shows something different like [sda2] then you’ll want to use that for the next command in place of where I have sda.The next command you’ll run is…
ls -l /dev/disk/by-uuid/ | cut -d' ' -f 9- | grep sda
This will output a screen that has a line that looks like the following…
10 Dec 31 1969 e27f5b75-ff33-cf01-e05d-4375ff33cf01 ../../sda1
From the string above, e27f5b75-ff33-cf01-e05d-4375ff33cf01 is the UUID for your USB drive. Copy this to a text file somewhere for a second for safe keeping and close out your terminal window, we finished with that.
Next, you’ll want to turn off your Raspberry Pi and remove the SD card. Take that SD card and plug it into the computer you used in part one of this tutorial. We want to update the “cmdline.txt” file and change it from:
boot=/dev/mmcblk0p1 disk=/dev/sda1 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 ssh
boot=/dev/mmcblk0p1 disk=UUID=e27f5b75-ff33-cf01-e05d-4375ff33cf01 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 ssh
Note the difference in the two. Of course you’ll put your UUID in place of mine, save the file, and replace the file that’s on the SD card with the new “cmdline.txt” file that you just created. Place the SD card back into the Raspberry Pi, make sure you plug the USB drive into the top USB port on the Raspberry Pi, and plug the power back in.
Now when your Raspberry Pi starts up, it will only mount the “Storage” partition to the USB drive and not any other USB device. You should now have no problems booting up when you use another USB device like a USB wi-fi dongle or USB hub in the bottom USB port on the Raspberry Pi.
***NOTE*** If you ever move your “Storage” partition to another USB drive, you will need to perform this process over because that USB drive will have a different UUID.
So let’s recap what we did in this tutorial. You Should have gone through and configured your GUI settings in the XBMC interface to turn off things like RSS and background fan art to speed up the Raspberry Pi. We then created the “advancedsettings.xml” file to add a few more tweaks that will give us some speed improvements and keep our CPU usage low. We verified that low CPU usage by logging into our Raspberry Pi via SSH and using the “top” command to view the “xbmc.bin” CPU usage stats. Then we modified the “cmdline.txt” file to force the “Storage” partition to mount to our USB drive and no other.
At this point, you should have a lean, mean, over clocked XBMC machine ready to play your 1080p movies on your big screen.