Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Saturday, January 26, 2013

Howto Raspberry Pi - Use your Pi as a secure Reverse Proxy gateway to your Web internal Sites and Services



Last update 02/01/2013





The Goal: 


You have a Raspberry Pi and want to use it as your secure Web reverse proxy gateway to access to your various Internal services through your main fully qualified domain name or IP.

Let's say:
  • You have a main router or ISP Box
  • Your Rpi will be in front of the Internet by redirecting http/https por
  • For this configuration to work from both inside and outside your home network, your domain name (here "myowndomain.com") must be associated with your public IP
  • ts from your router to your Rpi
  • You have or not internal servers providing Web sites or services your want to access from your public IP / domain name
We will use:
  • nginx as the great secure reverse proxy instance
  • SSL with auto signed or officially signed certificate to secure our web traffic
  • htpasswd to password protect your shellinbox from being visible and accessible whitout credentials
  • shellinabox to host a nice Web SSH frontend

Summary of steps: 

Step 1: OPTIONAL - Get a fully Qualified Domain Name (FQDN)
Step 2: Manage your SSL certificate
Step 3: Put a Shellinabox in your Pi ^^
Step 4: Install and configure Nginx



Step 1: OPTIONAL - Get a Fully Qualified Domain Name  

This is absolutely optional, but you could think about getting a qualified domain name to access to your home network. (a domain costs very few per year, and your can dynamically associate it with your public IP)

In many cases, when you connect from secure places (such as your company site), trying to access to a web site using its public IP will be prohibited by internals web proxies and firewalls.
By using a fqdn to associate your public IP to a real Internal domain name, your site is as official as any Internet company web site :-)

As an alternative to buy your own domain name, you can also use dynamic free domain name services such as no-ip.org, but most of company proxy will also block them.

And finally, this is just clean and beautiful ^^

In this post, i will assume for the example purpose that your domaine name is "myowndomain.com". (still the fqdn is optional)
  
Step 2: Manage your SSL certificate

Off course, we will want to secure our Web traffic using an SSL certificate, there is 2 ways to achieve this:

1. Generating an "auto-signed" SSL certificate

You can very easily generate an auto-signed SSL certificate, you will have exactly the same security and encrypting level than any official certificate but this certificate won't be officially recognized over the Internet.

That means that when connecting to your site, your Web browser will warn you about the impossibility to guaranty your security connecting to this site, and you have to accept this.

I personally prefer having an official SSL certificate :-)

2. Buy and generate an Officially signed SSL certificate

You can also buy an official SSL certificate for very few, in this case your browser will automatically recognize your certificate as valid and you won't get any warn.

There is some places where you can get a free official SSL certificate for personal use. (look for "startssl")

In both cases, Google is your friend ^^

How to generate an auto signed certificate:

Install OpenSSL:
$ sudo apt-get install openssl

Generate your self signed certificate:
sudo mkdir -p /etc/ssl/localcerts
openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/localcerts/autosigned.crt -keyout /etc/ssl/localcerts/autosigned.key
chmod 600 /etc/ssl/localcerts/*

Note: Respond to OpenSSL questions as you wish, it does not really mind as your certificate is a self-signed anyway


Step 3: Put a shellinabox in your Pi ^^

As explained before, shellinabox is a wonderfull web frontend to SSH, this way you will access to your SSH server without having to deal with an SSH client.

By the past, i wrote an article about an other SSH web frontend "ajaxterm" which is nice too, but in my opinion much more limited and low.
So i recommend to use shellinabox instead.

You will be able to access to your SSH server using standard Web ports even when connecting from places where external SSH traffic is prohibited :-) 

To install:
# sudo apt-get install shellinabox

By default, shellinabox uses the port "4200" to listen to, you can let that as it is as your nginx reverse proxy take care about redirecting our request to this internal service. 

If you want to manage your shellinabox configuration, take a look at main config files:
  • /etc/default/shellinabox
  • /etc/shellinabox/*
Default configuration is ok for us, test your shellinabox by connecting from a browser inside your network: http://<mypiserver>:4200

Note that even if we won't use it, shellinabox comes with embeded SSL auto-signed certificate configuration to redirect http to https and secure your web traffic.


Step 4: Install and configure Nginx

Ok, serious things now, let's install and configure nginx.

Nginx is an extremely powerful Opensource Web server, light secure and fast, that can be used as reverse proxy instance gateway to your internal Web services.

It is more and more used by many companies web site with high load Web Sites, do not hesitate to take a look at official sites:
I used by the past Apache running as a reverse proxy to do this job, but nginx assumes this job with great success, it's very modular and easy to maintain, this is why i recommend your Nginx.

To install:
# sudo apt-get install nginx-full


Now let's configure the beast:

First, some configuration in main config file "/etc/nginx/nginx.conf", here is a sample config file:
# /etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
 worker_connections 768;
}

http {

 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout 65;
 types_hash_max_size 2048;

 include /etc/nginx/mime.types;
 default_type application/octet-stream;

 access_log /var/log/nginx/access.log;
 error_log /var/log/nginx/error.log;

 gzip on;
 gzip_disable "msie6";

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
}

Please note that as Apache configuration style under Debian/Ubuntu, any configuration file (for site or module) included in conf.d or sites-enabled will be loaded at Nginx start

A good practice is to create a symbolic link from "sites-available" to "sites-enabled".

Let's deactivate the default web site we won't use by removing its symbolic link:
$ sudo rm /etc/nginx/sites-enable/default 

Create an htpasswd file that will contain your credentials (adapt <username>)
$ sudo htpasswd -c /etc/nginx/.htpasswd <username>

Now create your main web site configuration file, example:
  • /etc/nginx/sites-available/main
Here is a sample secured configuration:
access_log off;
add_header Cache-Control public;
server_tokens off;


# HTTP 80
server {
 listen         80;
 server_name _;
 rewrite ^ https://myowndomain.com$request_uri? permanent;
}

# HTTPS 443
server  {

 include    /etc/nginx/proxy.conf;

 listen 443 ssl;
 keepalive_timeout 70;

 server_name myowndomain.com;

 # SSL config
 ssl on;
 ssl_certificate /etc/ssl/localcerts/autosigned.crt;
 ssl_certificate_key /etc/ssl/localcerts/autosigned.key;

 ssl_session_timeout 5m;
 ssl_protocols SSLv3 TLSv1.2;
 ssl_ciphers RC4:HIGH:!aNULL:!MD5;
 ssl_prefer_server_ciphers on;
 ssl_session_cache shared:SSL:10m;

 add_header X-Frame-Options DENY;

 # DDOS protection - Tune Values or deactivate in case of issue
 # limit_conn conn_limit_per_ip 20;
 # limit_req zone=req_limit_per_ip burst=20 nodelay;

 # status for ngxin auditing
 location /nginx-status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
  }

 location / {
  rewrite ^ https://myowndomain.com/shellinabox/ permanent;
  }

 location /shellinabox/ {
  proxy_pass http://localhost:4200;
                auth_basic            "Access Restricted";
                auth_basic_user_file  "/etc/nginx/.htpasswd";
                access_log /var/log/nginx/shellinabox.access.log;
                error_log /var/log/nginx/shellinabox.error.log;
  }
}

Create the file "/etc/nginx/proxy.conf" with following content:
proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4k;

Activate your nginx web site and restart:
sudo ln -s /etc/nginx/sites-enables/main /etc/nginx/sites-available/main
sudo service nginx restart

NOTE:

For this configuration to work from both inside and outside your home network, your domain name (here "myowndomain.com") must be associated with your public IP


Now test accessing to your Web site from both internal and external access :-)

As you understood, you can manage as many internal Web sites as you need through a unique Web instance and virtual hosts. (called location in Nginx)

In the sample config, shellinabox is the default site accessible with your domain name, but you change it and/or add any other internal web sites very easily.

Just add a new location related to your internal Web site you want to be able to access and you're done :-)



Friday, January 18, 2013

Howto Raspberry Pi: Monitor your Raspberry Pi with Observium!






The Goal: 



With Observium associated with Unix agent check_mk the goal will be to monitor any available indicator (CPU, Mem, Traffic interface...) and most of all, specific Raspberry Pi main indicators dynamically allocated when running Overclocked with Turbo mode:
  • CPU Frequency
  • CORE Frequency
  • CORE Voltage
  • BCM2835 Soc Temperature

Corresponding "vgencmd" commands:
# CPU Frequency
vcgencmd measure_clock arm

# CORE Frequency
vcgencmd measure_clock core

# CORE Voltage
vcgencmd measure_volts core

# SoC Temp
vcgencmd measure_temp

There are also other indicators you may want to monitor, even i don't feed it myself useful.
The present article will take care of these 4 indicators.

Take a look here: http://www.elinux.org/RPI_vcgencmd_usage

Global list of indicators available through "vgencmd":
vcgencmd measure_clock arm
vcgencmd measure_clock core
vcgencmd measure_clock h264
vcgencmd measure_clock isp
vcgencmd measure_clock v3d
vcgencmd measure_clock uart
vcgencmd measure_clock pwm
vcgencmd measure_clock emmc
vcgencmd measure_clock pixel
vcgencmd measure_clock vec
vcgencmd measure_clock hdmi
vcgencmd measure_clock dpi
vcgencmd measure_volts core
vcgencmd measure_volts sdram_c
vcgencmd measure_volts sdram_i
vcgencmd measure_volts sdram_p


Installing Observium is out of the scope of this article, Observium installations documentations and well known and easy to read, see above.

Main sources:

I recommend to install Observium and Mysql into a central server which will request our Rpi to generate graphs and so on.

We will use an additional agent called "check_mk" to request the Rpi, system load generated by snmp and Unix agent are very limited which is very great, the Rpi is a small power device and you don't want monitoring to generate high system load!

One time you have Observium up and running, follow this guide to integrate any Raspberry Pi you want to monitor :-)



Summary of steps: 

Step 1: Install and configure snmpd
Step 2: Install check_mk agent (Unix Agent)
Step 3: Add the custom Raspberry agent script
Step 4: Observium custom application configuration
Step 5: Configure your Rpi in Observium, the easy part!

Memorandum


Step 1: Install and configure snmpd

First thing, we will begin by installing the snmpd daemon, to do so:
$ sudo apt-get install snmpd snmp-mibs-downloader
Let's configure some little things:

Edit "/etc/default/snmpd" and:
  • set: export MIBS=UCD-SNMP-MIB
  • Replace the line "SNMPDOPTS=" with the following values to prevent snmpd to log each connection (default behavior):
SNMPDOPTS='-LS 0-4 d -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'

Edit "/etc/snmp/snmpd.conf" and:
  • Comment with "#" the default line "agentaddress udp:127.0.0.1:161" which only allows connections from the localhost itself
  • Comment out the line "agentaddress udp:161,udp6:[::1]:161" to allow remote connections
  • Comment out the line "rocommunity secret <LANSUBNET>" (adapt <LANSUBNET> to the CIDR value of your LAN subnet, example: 192.168.0/24" 

Note: "secret" will the name of the snmp community, only accessible through your local network) 

  • Configure "sysLocation" and "sysContact"
  • Look for the section "EXTENDING THE AGENT" and add the following line:
extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro
  • Install the "distro" script coming from observium (to recognize the remote OS)
$ sudo wget http://www.observium.org/svn/observer/trunk/scripts/distro -O /usr/bin/distro
$ sudo chmod 755 /usr/bin/distro

Finally restart snmpd daemon:
$ sudo service snmpd restart


Step 2: Install check_mk agent (Unix agent)

We will used the great Unix agent "check_mk" called Unix agent by Observium.

If you want more information about this very cool tool, check its main Web site:
http://mathias-kettner.de/checkmk_monitoring_system.html

Install Xinetd requirement:
$ sudo apt-get install xinetd

Download and install check_mk:
$ wget http://mathias-kettner.com/download/check-mk-agent_1.2.0p3-2_all.deb
$ sudo dpkg -i check-mk-agent_1.2.0p3-2_all.deb

Verify that the package installation generated the xinetd configuration file called "
/etc/xinetd.d/check_mk".

If not (it seems this part fails under Rpi), create the file with the following content:
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2012             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

service check_mk
{
 type           = UNLISTED
 port           = 6556
 socket_type    = stream
 protocol       = tcp
 wait           = no
 user           = root
 server         = /usr/bin/check_mk_agent

 # If you use fully redundant monitoring and poll the client
 # from more then one monitoring servers in parallel you might
 # want to use the agent cache wrapper:
 #server         = /usr/bin/check_mk_caching_agent

 # configure the IP address(es) of your Nagios server here:
 #only_from      = 127.0.0.1 10.0.20.1 10.0.20.2

 # Don't be too verbose. Don't log every check. This might be
 # commented out for debugging. If this option is commented out
 # the default options will be used for this service.
 log_on_success =

 disable        = no
}


Restart xinetd:

$ sudo service xinetd restart

Finally, ensure your Observium machine willbe authorized to access to the Rpi check_mk service running on port TCP/6556.


Step 3: Add the custom Raspberry agent script


Create a new file "/usr/lib/check_mk_agent/local/raspberry":
#!/bin/bash
#set -x
echo "<<<app-raspberry>>>"
# CPU Frequency
expr `vcgencmd measure_clock arm|cut -f 2 -d "="` / 1000000
# CORE Frequency
expr `vcgencmd measure_clock core|cut -f 2 -d "="` / 1000000
# CORE Voltage
vcgencmd measure_volts core|cut -f 2 -d "="|cut -f 1 -d "V"
# SoC Temp
vcgencmd measure_temp|cut -f 2 -d "="| cut -f 1 -d "'"

Add execution right:
$ sudo chmod a+rx /usr/lib/check_mk_agent/local/raspberry

This script will be called by Observium at each poller time.


Step 4: Observium custom application configuration



Ok now a bigger part, we need to configure Observium to add our custom application has any other.
By this way, we could run this with as many Rpi as you want ;-)

To do so, we need to create and/or modify different configuration files.

Go into your Observium root directory, usually "/opt/observium"

1. "./includes/polling/unix-agent.inc.php" (modify)

Look for the section containing:
      if ($section == "apache") { $sa = "app"; $sb = "apache"; }

And add new one just under :
      if ($section == "raspberry") { $sa = "app"; $sb = "raspberry"; }

2. "./includes/polling/applications/raspberry.inc.php" (create)

Create with following content:
<?php

if (!empty($agent_data['app']['raspberry']))
{
  $raspberry = $agent_data['app']['raspberry'];
}

$raspberry_rrd  = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-raspberry-".$app['app_id'].".rrd";

echo(" raspberry statistics\n");

list($cpufreq, $corefreq, $corevoltage, $soctemp) = explode("\n", $raspberry);
if (!is_file($raspberry_rrd))
{
  rrdtool_create ($raspberry_rrd, "--step 300 \
        DS:cpufreq:GAUGE:600:0:125000000000 \
        DS:corefreq:GAUGE:600:0:125000000000 \
        DS:corevoltage:GAUGE:600:0:125000000000 \
        DS:soctemp:GAUGE:600:0:125000000000 ".$config['rrd_rra']);
}

print "cpufreq: $cpufreq corefreq: $corefreq corevoltage: $corevoltage soctemp: $soctemp";
rrdtool_update($raspberry_rrd, "N:$cpufreq:$corefreq:$corevoltage:$soctemp");

// Unset the variables we set here

unset($raspberry);
unset($raspberry_rrd);
unset($cpufreq);
unset($corefreq);
unset($corevoltage);
unset($soctemp);

?>

3. "./html/includes/graphs/application/raspberry_soctemp.inc.php" (create)

Create with following content:
<?php

$scale_min = 0;

include("includes/graphs/common.inc.php");

$raspberry_rrd   = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-raspberry-".$app['app_id'].".rrd";

if (is_file($raspberry_rrd))
{
  $rrd_filename = $raspberry_rrd;
}

$ds = "soctemp";

$colour_area = "F0E68C";
$colour_line = "FF4500";

$colour_area_max = "FFEE99";

$graph_max = 1;

$unit_text = "°C";

include("includes/graphs/generic_simplex.inc.php");

?>

4. "./html/includes/graphs/application/raspberry_corevoltage.inc.php" (create)

Create with following content:
<?php

$scale_min = 0;

include("includes/graphs/common.inc.php");

$raspberry_rrd   = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-raspberry-".$app['app_id'].".rrd";

if (is_file($raspberry_rrd))
{
  $rrd_filename = $raspberry_rrd;
}

$ds = "corevoltage";

$colour_area = "CDEB8B";
$colour_line = "006600";

$colour_area_max = "FFEE99";

$graph_max = 1;

$unit_text = "Volts";

include("includes/graphs/generic_simplex.inc.php");

?>

5. "./html/includes/graphs/application/raspberry_corefreq.inc.php" (create)

Create with following content:
<?php

$scale_min = 0;

include("includes/graphs/common.inc.php");

$raspberry_rrd   = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-raspberry-".$app['app_id'].".rrd";

if (is_file($raspberry_rrd))
{
  $rrd_filename = $raspberry_rrd;
}

$ds = "corefreq";

$colour_area = "B0C4DE";
$colour_line = "191970";

$colour_area_max = "FFEE99";

$graph_max = 1;

$unit_text = "Mhz";

include("includes/graphs/generic_simplex.inc.php");

?>

6. "./html/includes/graphs/application/raspberry_cpufreq.inc.php" (create)

Create with following content:
<?php

$scale_min = 0;

include("includes/graphs/common.inc.php");

$raspberry_rrd   = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-raspberry-".$app['app_id'].".rrd";

if (is_file($raspberry_rrd))
{
  $rrd_filename = $raspberry_rrd;
}

$ds = "cpufreq";

$colour_area = "B0C4DE";
$colour_line = "191970";

$colour_area_max = "FFEE99";

$graph_max = 1;

$unit_text = "Mhz";

include("includes/graphs/generic_simplex.inc.php");

?>

7. "./html/pages/device/apps/raspberry.inc.php" (create)

Create with following content:
<?php

global $config;

$graphs = array('raspberry_cpufreq' => 'CPU Frequency',
                'raspberry_corefreq' => 'CORE Frequency',
                'raspberry_corevoltage' => 'CORE Voltage',
                'raspberry_soctemp' => 'BCM2835 SoC Temperature',

);

foreach ($graphs as $key => $text)
{

  $graph_array['to']     = $config['time']['now'];
  $graph_array['id']     = $app['app_id'];
  $graph_array['type']   = "application_".$key;

  echo('<h3>'.$text.'</h3>');

  echo("<tr bgcolor='$row_colour'><td colspan=5>");

  include("includes/print-graphrow.inc.php");

  echo("</td></tr>");
}

?>

8. "./html/pages/apps.inc.php" (modify)

Look for the section containing:
$graphs['apache']     = array('bits', 'hits', 'scoreboard', 'cpu');

And add new one just under :
$graphs['raspberry']  = array('cpufreq', 'corefreq', 'corevoltage', 'soctemp');

Ok, we're done!



Step 5: Configure your Rpi in Observium, the easy part!


Now the easiest, add your Rpi into Observium, go to the menu <Devices>, <Add device>.



In our case:
  • Hostname: Enter the hostname or IP of your Rpi
  • snmp Community: secret

Let all the rest by default.


The Rpi shall be detected with sucess, and the Debian logo appears:


Now enter the device and go to device settings:



Go to "Applications" and activate the box corresponding to our Raspberry application:


Then, Go to "Modules" and Activate the Unix agent (disabled by default):



Great, you're done will all configuration parts, wait for a view poller execution (by default Observium proposes a cron task every 5 minutes)

You can run manually the poller under the host running Observium:
$ sudo /opt/observium/poller.php -h all

And if you want to run it into debug mode to get more details:
$ sudo /opt/observium/poller.php -h all -d


In my experience, you have to wait for 10-15 minutes before getting data being graphed.

Some screenshots with application data:

CPU Frequency:




CORE Frequency:



CORE Voltage:




BCM2835 Soc Temperature:




Great :-)



Wednesday, January 16, 2013

Howto: Raspberry Pi Root NFS share - boot your System over NFS share and definitively deal with Flash data corruption



*** Updated March 14, 2013  ***


The Goal: 


If you have a Raspberry Pi and a Linux Server (or a NAS), you shall really be interested by this post! :-)

I had a lot of issue with my main Rpi when overclocked generating File System data corruption...
And finally, the real best solution, solid and efficient has been to convert my root installation into booting rootfs over NFS.

I recommend the most easy solution to first have a running installation of your system into your Flash card and simply migrate it to root fs over NFS.

Since i've done this, never had any system freeze, corruption or event kernel panic with my Rpi overclocked to turbo mode :-)

Also, you should ensure before beginning that your system is up to date (sudo apt-get update && sudo apt-get dist-upgrade -f) and your have the last firmware version (sudo rpi-update)

Major source: 

Summary of steps: 

Step 1: Set your NFS share
Step 2: Copy your root fs into your NFS share
Step 3: Modify your Raspberry Pi boot configuration
Step 4: Adapt your Rpi fstab
Step 5: Boot your Rpi!
Step 6: Correct your swap configuration by migrating to a loop device

Memorandum


Step 1: Set your NFS share

If you have a Linux Home Server or NAS, then you probably already share data using NFS.

To set a NFS share dedicated for your Rpi Root fs, add your share into "/etc/exports":
Adapt <raspberrypi_ip> with your Rpi LAN IP or LAN subnet if you prefer
# Raspberry Root FS                                     
/data/rpi_rootfs <raspberrypi_ip>(rw,sync,no_root_squash,no_subtree_check)

Under Debian / Ubuntu, reload your NFS server config:
sudo /etc/init.d/nfs-kernel-server reload


Step 2: Copy your Rpi root fs into your NFS share

Then simply copy all of your Rpi root fs into your new nfs share, you can do it directly under the Rpi or by plugging your Flash card into a client computer:

Example with a client computer having the flash card and NFS share mounted:
cp -rav /media/mmcblk0p2/* /data/rpi_rootfs/ 


Step 3: Modify your Raspberry Pi boot configuration

The only partition you will need to keep in your Rpi Flash card will be the boot partition (first partition), containing main boot configuration files and the Rpi firmware.

To boot over NFS, we need to modify the file "/boot/cmdline.txt" (contained into the first fat partition of your Flash card) to add/correct some sections:
  • root= --> Will be pointing to "/dev/nfs"
  • nfsroot=<nfs_server_ip>:/data/rpi_rootfs,udp,vers=3 ip=dhcp (replace<nfs_server_ip> with your NFS server IP)
  • rootfstype=nfs
  • smsc95xx.turbo_mode=N --> is a workaround to prevent kernel panic under high network load (i recommend this)

Note:

In this example, we use DHCP to set the Rpi Lan IP at boot time, this is in my opinion the easiest way to do as you preset a fix address in your DHCP server for your Rpi.
Still you can also manually a fix IP at boot time.

Also note we will be using NFS V3 running under UDP for better performances. (see Memorandum for performances fine tuning)

"cmdline.txt" example with DHCP (the file must contain only one line):

Replace:
  • <nfs_server_ip> with the NFS server IP
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1
root=/dev/nfs nfsroot=<nfs_server_ip>:/data/rpi_rootfs,udp,vers=3
ip=dhcp rootfstype=nfs smsc95xx.turbo_mode=N 

"cmdline.txt" example with Fix IP(the file must contain only one line):

Replace:
  • <raspberrypi_ip> with the Lan IP of your Rpi
  • <nfs_server_ip> with the NFS server IP
  • <default_gateway> with the IP of your local gateway
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1
root=/dev/nfs nfsroot=<nfs_server_ip>:/data/rpi_rootfs,udp,vers=3
ip=<raspberrypi_ip>:<nfs_server_ip>:<default_gateway>:<mask>:rpi:eth0:off rootfstype=nfs smsc95xx.turbo_mode=N


Step 4: Adapt your Rpi fstab

Now edit the Rpi "/etc/fstab" file before trying to boot, do under your NFS server or client computer.

/data/rpi_rootfs/etc/fstab:
  • Delete the original line corresponding to your root fs and pointing to the second partition of your flash card  (/dev/mmcblk0p2), we don't need anymore as it will automatically be mounted by the firmware at boot time

Step 5: Boot your Rpi!

Ok, let's go, time to boot :-)

If you follow all steps carefully, you system should boot with no major issue.

Therefore, you will not have anymore swap available, by default Raspbian uses dphys-swapfile os use a local file as swap.

We will correct this now.


Step 6: Correct your swap configuration by migrating to a loop device

By default, Raspbian uses dphys-swapfile to generate a local file being used as swap, this won't work anymore when booting under NFS.

I don't recommend to use your Flash card as a swap partition, this may generates system freeze or kernel panics if you have data corruption:

The better way is to set a local file as a loop device that will be used a swap device, here is how.

Clean current non working swap file and uninstall dphys-swapfile:
sudo apt-get remove --purge dphys-swapfile
sudo rm /var/swap
sudo rm /etc/init.d/dphys-swapfile
sudo update-rc.d dphys-swapfile remove

Create a new swap file, create the loop swap device and activate swap (exemple with 1GB swap):
sudo dd if=/dev/zero of=/var/swapfile bs=1M count=1024
sudo losetup /dev/loop0 /var/swapfile
sudo mkswap /dev/loop0
sudo swapon /dev/loop0

Check your current swap availability:
$ free

Output example:
             total       used       free     shared    buffers     cached
Mem:        237656     213092      24564          0         24      93192
-/+ buffers/cache:     119876     117780
Swap:      1048572       1556    1047016

Make it permanent, edit "/etc/rc.local" and add this section before "exit 0":
echo "Setting up loopy/var/swapfile.."
sleep 2
losetup /dev/loop0 /var/swapfile
mkswap /dev/loop0
swapon /dev/loop0


Step 7: Other tunings


There is also some other little thing to tune:

Edit "/etc/default/rcS" and:
  • add:ASYNCMOUNTNFS=no

Edit "/etc/sysctl.conf" and:
  • add or set: vm.min_free_kbytes = 12288 
This will ensure the system will always have 12Mb or RAM free to prevent kernel panic risk, your may try lower value if your prefer.


Memorandum

  • NFS version and fine tuning
You may want to try different settings to get the better performance possible.

First, if you test your write speed, using dd will be very easy:

Create a 10 Mb file test:
$ dd if=/dev/zero of=/tmp/test.file bs=1M count=10

Output sample:
10+0 enregistrements lus                                                                                                      
10+0 enregistrements écrits                                                                                                   
10485760 octets (10 MB) copiés, 1,52525 s, 6,9 MB/s

You may want to try with different NFS version, change in cmdline.txt:
  • Change the section nfsroot "vers=2/3"
You may want to try TCP versus UDP
  • Change the section nfsroot  "udp" or "tcp"
You may want to try different values of "rsize" and "wsize", example with NFS V3 and TCP:

Example:
  • root=/dev/nfs nfsroot=<nfs_server_ip>:/data/rpi_rootfsrsize=32768,wsize=32768,tcp,vers=3

In my case, it did not really change anything, so i kept kernel default values for wsize and rsize, udp with NFS V3.

  • Netfilter Iptables
When modifying your Iptables configuration, keep in mind that NFS traffic with your NFS server will result in system halt.

Applying default outbound policy to DROP (usually "iptables -P OUTPUT DROP") will in system crash.
You should apply instead "iptables -P OUTPUT ACCEPT" which will permit any outbound traffic from your Rpi (not a big deal, usually you trust your own machine)

Also you can ensure to accept NFS traffic with your NFS server before applying any other rules.


















Sunday, September 16, 2012

Howto Raspberry Pi : OpenELEC on Raspberry Pi, get a great XBMC experience on your Raspberry Pi





*** Updated April 5 2013  ***

Major changes:

04/05/2013 - Remote control section update, mention about CEC
03/16/2013 - New advancedsettings.xml version
03/05/2013 - overclocking correction
02/11/2013 - Advancedsettings.xml corrections
01/18/2013 - Major review: Download location, SSH activation, Themes locations...
12/03/2012 - Rpi 512MB update / Recommended Build
13/11/2012 - Overclock corruption workarounds, Last build test, note about missing videos when used as client of main XBMC
23/10/2012 - Image builds location changed / Add link to upgrade script as alternative
10/15/2012 - Recommended "stable" build
11/09/2012 - Update Backup & Restore
10/09/2012 - Update issue amendment
09/29/2012 - Add Verified Wireless section
09/28/2012 - Add a conservative mode in case of constant corruption
09/26/2012 - Turbo Mode data corruption workaround
09/24/2012 - New Turbo mode
09/21/2012 - Add memorandum section
09/21/2012 - Fit to screen correction and turbo mode announcement
09/20/2012 - Fit to screen section
09/19/2012 - Add backup / restore section
09/18/2012 - Add upgrade section - Add recommended themes
09/16/2012 - First version




The Goal: 

Get a fully functional XBMC Media Center on Raspberry Pi !

The Raspberry Pi is a very cheap and interesting small computer created by the Raspberry foundation for educational purposes.

Therefore, it comes with a GPU able to decode HD Video, a great community works on this device and allow us today to use it as a real XBMC Media Center.


Major sources: 

To help you setting up Openlec on your Raspberry Pi, don't hesitate to take a look at following pages:

My others XBMC related posts and guides:
http://youresuchageek.blogspot.fr/search/label/XBMC

OpenELEC Raspberry Pi FAQ:
http://openelec.tv/forum/124-raspberry-pi/40979-raspberry-pi-faq

OpenELEC WIKI for Raspberry Pi:
http://wiki.openelec.tv/index.php?title=Building_and_Installing_OpenELEC_for_Raspberry_Pi

OpenELEC Forum for Raspberry Pi: If you have any issue, this is the place to go!
http://openelec.tv/forum/124-raspberry-pi

Official XBMC Website and Forum:
http://xbmc.org/
http://forum.xbmc.org/

eLinux.org full description of available advanced values for Raspberry Pi:
Interesting posts for Raspberry Pi:



Summary of steps: 

Step 1: Install OpenELEC on your SDCard
Step 2: Boot your Raspberry Pi and first setup
Step 3: Activate SSH (default is off)
Step 4: Connect to your Raspberry Pi and setup config.txt
Step 5: Configure your advancedsettings.xml
Step 6: Sound Setup
Step 7: Set up XBMC and your Media Library
Step 8: Customize Skin
Step 9: Remote Control
Step 10: Optional - Verified Wireless Interfaces
Step 11: How to update OpenELEC
Step 12: How to backup and restore
Conclusion
Memorandum
FAQ & issues

Let's start !


Step 1: Install OpenELEC on your SDCard


First thing, if you don't already have one, i would recommend you to get a "Class 10" SDHC Card, XBMC will be much more powerful on such cards.

Off course, this will still works on any SDHC Class SD card.

Download Last OpenELEC Build for Raspberry Pi:

Edit 01/18/2013: Previous download locations are outdated, to get the very last Rpi OE version, please use the download link in main OpenELEC Website: (look for Raspberry Pi)

http://openelec.tv/get-openelec/

********************************************** OUTDATED **********************************************
Edit 12/03/2012:  Recommended build: http://sources.openelec.tv/tmp/image/OpenELEC-RPi.arm-devel-20121124031454-r12577.tar.bz2

Note: This build is compatible with both 256MB and 512MB Raspberry, take a look here:
http://forum.xbmc.org/showthread.php?tid=140518&pid=1246709#pid1246709

Note for 512MB Raspberry:
If you have a 512MB Raspberry with a previous OpenELEC version installed, you should restart with a fresh install. (or move your current config.txt to config.txt.old before upgrade)
The required gpu mem option will automatically be set depending on your Raspberry Pi hardware.

You could choose to compile yourself OpenELEC for your Raspberry Pi, therefore i advise you to download last OpenELEC build on:

*********************************************************** **********************************************

These images are provided in Bz2 tar archive, when downloaded just extract it using your Desktop (right click then extract here) or in command line:
http://openelec.tv/get-openelec/$ tar -xjf OpenELEC-RPi.arm-devel-*.tar.bz2

Note: For Windows users, you may need an Archive Software such as 7zip to extract this archive

You will get a new directory "OpenELEC-RPi.arm-*", just go in this extracted directory to begin the creation of your SD-card.

If you are using Linux:

Real easy, just insert your Flash card into your card reader.
Your Flash card should identified as "/dev/sdb" (/dev/sda being your first drive), ensure this is the case (in case of you have more than one drive connected) using "mount" command.

Then, Go into the new directory and just execute:
$ sudo ./create_sdcard /dev/sdb

If your are using Windows:

Go to:
http://www.squirrelhosting.co.uk/hosting-blog/hosting-blog-info.php?id=9



Step 2: Boot your Raspberry Pi and first setup


Insert your Flash card and boot your Raspberry.
OpenELEC will boot within a few minutes and XBMC will open.

Set screen:

With no additional configuration, you may have some "fit to screen" issues, in XBMC UI and play back also.

If you have some issues, proceed as follows:

Depending on your TV/Screen and configuration, you may try 2 methods, one manipulating overscan values and one other with UI zoom tuning.


Method 1: Set overscan - RECOMMENDED

Note a reboot is required.
Also "overscan_scale" is an experimental set, test with and without.

Try to set in your config.txt overscan settings (see Memorandum to learn how to update config.txt):
Note: Adapt overscan position values to your TV/screen
# Make display smaller to stop text spilling off the screen
overscan_scale=1 # http://www.raspberrypi.org/phpBB3/viewtopic.php?f=67&t=15700
disable_overscan=1
overscan_left=57
overscan_right=59
overscan_top=20
overscan_bottom=20

This worked perfectly for me.

Depending on your TV/Screen you can also just try: (did not worked for me)

You can also just try to disable overscan:
disable_overscan=1

Also test some overscan values (above) and check your TV config (set full mode...)



Method 2: Set UI Zoom 


This method also worked for me, therefore the first method should be preferred to avoid issue when playing back.

An easy way to resolve your fit to screen issue could be to customize UI zoom (by probably -6 or -8%).

To do so, do as follows:




When done, do not hesitate to calibrate your screen:







Step 3: Activate SSH (default is off)

Edit 01/18/2013: SSH activation through OpenELEC OS Addon

SSH is now off by default and can be activated using the OpenELEC OS addon, under the section "Services".

To access to the OpenELEC OS Addon:

- Main menu "Programs" / Sub-menu "OpenELEC OS"
- Mai menu "Parameters" then Programs

Choose to activate the SSH daemon under the section Services, and reboot.



Step 4: Connect to your Raspberry Pi and setup config.txt

Identify the IP Address of your Raspberry Pi, to do so you can use XBMC system information.

In XBMC, Go to "parameters", then scroll down and go to "System Information".

Finally go to the Network panel to know your device IP Address:




Now that you know your IP Address, connect to your Raspberry;

Default password is: openelec

If you are on Linux:

Open a Terminal and go into SSH:
$ ssh root@XXX.XXX.XXX.XXX

If you are on Windows:

Download putty (freeware) and connect with SSH to your host


Setup your config.txt:

Edit 01/18/2013: config.txt coming with new builds now contain all required information to correctly set your main settings like Overcloking values, still information above are correct

*****************************************************************************************************************************************************************
DISCLAIMER ABOUT OVERCLOCKING:

Overclocking is not officially supported by OpenELEC, if you do so this is at your own decision and own risk.
Overclocking feature may result in file system corruption, data losses, crashed or global instability.
OpenELEC developers won't give any warranty about those risks until a fix is officially supported.

Therefore, Overclocking on Raspberry Pi will not break your guarantee if you use the new Turbo Mode which is described bellow. (only setting overvoltage without dynamic frequency allocation would break your Raspberry's warranty)

Overclocking is still under work in OpenELEC and Raspberry Pi in general, this is an experimental feature and you should be prepared to restore your installation in case of trouble. (see section How to backup and restore)

*****************************************************************************************************************************************************************


Note: See Memorandum section for a full config.txt sample


Default CPU frequency of Raspberry Pi is 700Mhz, you can check it as follows:
cat /proc/cpuinfo

You should see something like "BogoMIPS : 697.95" which confirms this frequency.

Do as follows:
mount -o remount,rw /flash
vi /flash/config.txt

OVERCLOCKING:

*********************************************************************************

Edit 09/23/2012: The Raspberry foundation introduced recently a new overclocking mode which sets on demand frequencies, you can now overclock your Raspberry Pi without breaking the guarantee.
Ensure to have the very last OpenELEC build!

Data Corruption:

Many people have data corruption and instability with higher overclocking modes, this seems to be related to high values of overvoltage.

For example, i have myself the case with a 8GB Class 4 that gets instantly corrupted when any overclock mode is set, where the same manufacturer Class 10 never got corrupted, still this is not related with class type SD card.

Anyway, you when your setup is done, see backup and restore section, this way if you have data corruption you could easily restore your flash card without re-installing.

Workaround : Set initial_turbo in config.txt

Edit 09/28/2012: If you have file system corruption with your settings, try to set:
initial_turbo=30
Seehttp://openelec.tv/forum/124-raspberry-pi/47056-turbo-mode?limit=20&start=20

It will force turbo mode after boot for the time set (max 60 secs) and should help preventing data corruption.

If even with this setting you still have Data corruption, try to comment "overvoltage=2" in Medium mode.

And if finally this still fails to work without file system corruption, i advise you to go back a more conservative overclocking mode which will work in most casse:

Conservative Overclocking mode:
arm_freq=850
gpu_freq=325
sdram_freq=425

If after all, you can't get any stable situation with overclocking mode enable, then simply disable it :-)
OpenElec works also very fine in default mode, moreover you should remember that higher CPU/GPU/Ram frequency does not change anything in playback quality ^^

*********************************************************************************


Then go in insert mode (press key "i") and set your overclock settings.

Based on my tests, i would recommend this settings, but you can change, test or prefer what ever you want.

I could not get stability on higher overclocking model than Medium.

Be sure not to set "turbo_force=1" (or to set it to "0") because it would deactivate dynamic frequency. (and break your guarantee)

See Memorandum at the end of this post to see other overclocking modes and how to check activity.


force_turbo=0
#Medium
arm_freq=900
core_freq=333
sdram_freq=450
over_voltage=2

If you are using an HDMI connection, i also recommend to add:
# Force HDMI 
hdmi_force_hotplug=1

Then save your file (press ":wq!") and:
mount -o remount,ro /flash
reboot

After reboot, you can see in kernel messages (run command "dmesg") CPU frequency dynamic allocation depending on your config:
bcm2835-cpufreq: switching to governor ondemand
bcm2835-cpufreq: Freq 700000->900000 (min=700000 max=900000 target=900000 request=900000)
bcm2835-cpufreq: Freq 900000->700000 (min=700000 max=900000 target=700000 request=700000)


Using the following command will also return current CPU frequency:
vcgencmd measure_clock arm


Mode "governor demand" confirms dynamic frequency allocation, and you can also notice CPU frequency changes depending on system load.


MPGE2 and VC1 Support:

If you want MPEG2 and VC1 Support, the Raspberry foundation now allows us to buy 2 cheap licences that will activate this.

So simply go to Raspberry's site:
http://www.raspberrypi.com/

You will need your CPU serial number, which you can easily get using the command:
cat /proc/cpuinfo

Or if you prefer, Go in XBMC, Parameters > Scroll down > System information and you will find you CPU serial number.

Look for the value next to "Serial" and Enter it into the Raspberry's site.

You will receive your licence keys within a few hours or days, when done add your keys to your config.txt as follows:
# MPEG 2 Hardware acceleration
decode_MPG2=XXXXXXXXXX

# VC1 Hardware acceleration
decode_WVC1=XXXXXXXXXX



Step 5: Configure your advancedsettings.xml


Now you need to configure your advancedsettings.xml file for XBMC, using this file you will ask XBMC to apply some tunes to improve UI performances:

  • Deactivating RSS feeds that consumes CPU
  • Activating Dirty Region
  • Tuning Thumbnails and Fanart resolution
  • Tuning Network memory buffer (note: not really proved this changes anything!) 

I advise you to access to the share called "Userdata" using your File Browser and navigating to your Network and OpenELEC host.



Then, use any text editor (example Gedit for Linux and Notepad for Windows) and create a new file called "advancedsettings.xml" with the following content:

Updated March 16, 2013: New advancedsettings.xml version

Note: This is new version of the advancedsettings.xml adapted to ARM processor like the RPi, if you have any issue with thumbnails quality due to the older file version, please delete your folder "~/.xbmc/userdata/Thumbnails", ensure you have the following advancedsetings.xml file and reboot 

The option "useddsfanart" must be set to false, explanation (thanks to Anonymous commentary):

"This settings allows XBMC to use your GPU rendering fanart and some other images. This will make loading images considerably faster, especially on systems with slower processors (e.g. Intel Atom based systems). Do not use this option on ARM based systems (Apple TV2/iOS/RPi/many Android systems) as it is likely to degrade performance because DDS images are not supported."


<advancedsettings>
   <fanartres>540</fanartres>
   <imageres>512</imageres>
   <useddsfanart>false</useddsfanart>
   <lookandfeel>
 <enablerssfeeds>false</enablerssfeeds>
   </lookandfeel>
   <bginfoloadermaxthreads>2</bginfoloadermaxthreads>
</advancedsettings>


Old version:


<advancedsettings>
   <fanartheight>540</fanartheight>
   <thumbsize>512</thumbsize>
   <lookandfeel>
 <enablerssfeeds>false</enablerssfeeds>
   </lookandfeel>
   <bginfoloadermaxthreads>2</bginfoloadermaxthreads>
</advancedsettings>


When done, finally reboot!



Step 6: Sound Setup


In XBMC, setting the sound will be enough easy.

There is 2 possibilities, or you want a sound output through HDMI, or you will use your analogical connection through the jack connection provided.

In XBMC, go to parameters > sound configuration and set HDMI or analogical.

Also, if your TV does not take this in charge (or the sound system connected to your TV), ensure to unset sounds protocols.

Finally, please note that OpenELEC on Raspberry Pi does not uses ALSA for the sound ouput but OpenMixer (OMX), so don't try for now to use as far an example an external USB soundcard if you need an Optical connection, that won't be possible as for now...

Also, it will be much better to have a sound system able to decode DDS and so on, if you don't the CPU/GPU will have to downmix the sound, which causes more usage.
Some file could be hard to play for this reason.

Note: Without any DDS hardware support, you may issues with some MKV files, this is causes by software sound conversion using CPU required when your sound system does not support it.


Step 7: Setup XBMC and your Media Library


Now that your XBMC installation is ready to use, you need to configure your Media Library, and some few settings depending on your taste. (skins...)

I recommend you to take a look at other guides i wrote for XBMC, you will find fully applicable ways to manage your Library.

http://youresuchageek.blogspot.fr/2012/06/xbmc-install-and-config-howto-for-linux.html
Go to Step 9

The Raspberry Pi is a very small device, if you are used to htpc don't expect to get the same kind of performances while scanning your Media Library, this will take a long long time ^^

I would recommend to use it as client of an other main XBMC installation that will take care about managing the Media Library and sharing it through SMB or NFS with an automatically shared Database. (Mysql)

Note about Mysql sharing: By the past i had some issues (missing videos) because of my XBMC master and slave version were using different versions of Mysql db (internal XBMC versions).
Ensure you always have most up to date possible XBMC versions when sharing over Mysql to avoid these kind of issue.


Consider your sharing Method:

If you are sharing your Media Files through your Network (from a NAS or share by another computer), you will probably wonder about the best way to set the Media Player.

Take a look at my post to configure Media Library sharing between your XBMC instances:
http://youresuchageek.blogspot.fr/2012/09/howto-xbmc-share-and-sync-your-media.html

Files shared from a Windows computer (even Windows Server) should be shared and accessed by XBMC using SMB protocol.

Files shared from an Unix / Linux Operating system should have better performances when accessed by NFS.

Therefore, in my configuration with all tests i've made, i noticed instability with NFS sharing mode, while SMB share were very stable, even shared from a Linux based system.
So, i would recommend SMB sharing in our configuration.

You don't have to mount your Network shares in your Raspberry Pi to act as a client, just browse when you add a Video source to the protocol of your choice, XBMC will care about that.




Step 8: Customize skin


By default XBMC is provided with Confluent skin.
In my opinion, in our configuration the UI works good enough to keep it.

Therefore, i would recommend to deactivate Fanart back screen to get better performances:




Edit 01/18/2013: With last OpenELEC builds, number of older themes are not available anymore under the main XBMC repository because they're not yet fully compatible with Frodo.

Still some of theme now have dedicated Frodo version, like the Quartz theme i recommend for your Rpi.

You can download it here:
https://github.com/pecinko/quartz

Download the theme as a Zip file, then proceed to manual installation under XBMC extension manager inside Parameters.

Here are some themes known to work good on Raspberry Pi, my preference goes to "Quartz" which real fast and good looking:
  • Quartz
  • Rapier
  • SLIK
  • Xperience1080

Some Quarz screenshots on Raspberry Pi:







Step 9: Remote Control

CEC - Consumer Electronic Control


Controlling XBMC using a remote control is in my opinion something primordial for any nice media center solution.

If you are lucky, you have a quite recent TV which is CEC compatible :-)

Note: CEC stands for Consumer Electronics Control, a protocol built into HDMI that allows for one appliance to control another)

Then the good news, The Raspberry hardware in addition with libcec included in OpenELEC is fully CEC compatible :-) 

You simply have nothing to do! Just plug and boot, very impressive.

Your remote control will work out of the box, i've tested it several time and it works very very good!



Generic MCE Remote control


If you're less (lucky), then i recommend you to get a cheap MCE Remote that will work out of the box in OpenELEC and XBMC.

I've tested and validated to work out of the box on OpenELEC for Raspberry:

600-hfx-vista

Philipps RC197
http://cgi.ebay.fr/Mando-HTPC-Media-Center-MCE-Multimedia-Philips-RC197-Receptor-Remote-Control-/271056452988?pt=LH_DefaultDomain_186&hash=item3f1c393d7c#ht_2183wt_1434


Validated to work out of the box by others:

MCE r6 1039



Many others should also work!



Step 10: Optional - Verified Wireless Dongle


Wireless Interfaces known to work out of the box under OpenELEC:

Here are some verified Wireless interfaces that works out of the Box in OpenELEC, many others way work but haven't been tested by myself or by people comments confirmation.

  • Leguang LG-N18 150Mbps IEEE802.11 b/g/n USB 2.0 Wi-Fi Wireless Network Adapter
  • Silver Crest IEEE802.11 b/g/n USB 2.0 Wifi Dongle (rtl8192 chipset)
  • TP-Link TL-WN821N V2.0 300mbps IEEE802.11 b/g/n USB 2.0 Wifi Dongle

Feel free to add comments on this posts for any verified Wireless dongle under OE.


Wireless Configuration:

To configure your Wireless interface, nothing more simple:

  • Plug you Wireless interface
  • Check your interfaces status (ifconfig), if you Wireless interface works out of the box you should get a new interface normally called "wlan0"
  • Go to OpenELEC OS Settings addon (Parameters > Addons > Enabled Addons > Program)
You have to know:


  • Your Wireless SSID (eg the name of your Wireless Network)
  • Your Wireless Encryption mode, WEB or WPA
  • Your encryption Key











Step 11: Upgrade OpenELEC


As for now, the automatic update process through OpenELEC Addon does not seem to work for Raspberry. (as far as i have seen)

Still you can update manually, which is easy enough anyway and the recommended way.

Edit 09/20/2012: With last OpenELEC builds, this is not required anymore to manually upgrade the bootloader by copying files from "3rdparty/bootloader" to "/flash"

Edit 10/09/2012: Thanks to xbs who gave the right answer, temporarily deactivating overcloking avoids update issues using the standard method

How to update:


*****************************************************************************************************************************************************************

IMPORTANT - Issue while overclocking mode enabled 

If you have any overclocking mode enabled, i recommend for now to temporarily deactivate overclocking while applying upgrade, if you don't you have many chances to break your system.

To do so:

- Rename /flash/config.txt to anything you want (eg. mv /flash/config.txt /flash/config.txt.off) - The goal is to deactivate Overclocking while we are updating

- Apply update as follow (copying SYSTEM* and KERNEL* to upgrade, reboot)

- When update is done (you have rebooted), rename config.txt to normal name to reactivate Overcloking

- Reboot (to apply)

You're done :-)


*****************************************************************************************************************************************************************


Edit 10/23/2012: You may be interested with the following script that allows to achieve update in terminal within an SSH sessions. (pay attention to overclock issues when upgraded as in the manual way)
See:
https://github.com/xsteadfastx/rpi-openelec-upgrade



1. Download last version in your computer (See Step1 to get the proper URL)

2. Extract files

3. Connect to your Raspberry SMB share "Update" and copy files located in the directory "target" you previously extracted:
  • KERNEL and KERNEL.md5
  • SYSTEM and SYSTEM.md5
4. Finally reboot, the update process will automatically occur



Step 12: How to backup and restore


Your should consider about backing up your installation, the only element really required to be backed up is the main xbmc directory which contains all of your data.

I personally recommend the method using Partclone or dd. (Partclone will be faster but has some requirements)

Partclone will require that partitions you want to restore from previously backed up have exactly the same size.

Using the well known tool "dd", there is no requirements to restore but the operation requires more time as dd also considers blank spaces as data.

Using tar to backup the main xbmc folder will also works but you may have to recreate your flash card (if you system is broken) and cover the system itself.


Method 1: Using "partclone"

You can also use this alternatively method with Linux and Partclone:

Install Partclone:
$ sudo apt-get install partclone

How to backup:

Insert your card into your computer and do as follows:
$ sudo umount /dev/sdb1 && sudo umount /dev/sdb2
$ sudo fsck -yf /dev/sdb2
$ sudo partclone.fat -c -d -s /dev/sdb1 -o raspi_openelec_sdb1_mm_dd_yyyy.img
$ sudo partclone.ext4 -c -d -s /dev/sdb2 -o raspi_openelec_sdb2_mm_dd_yyyy.img

How to restore:

Insert your card into your computer and do as follows:
$ sudo umount /dev/sdb1 && sudo umount /dev/sdb2
$ sudo partclone.fat -r -d -s raspi_openelec_sdb1_mm_dd_yyyy.img -o /dev/sdb1
$ sudo partclone.ext4 -r -d -s raspi_openelec_sdb2_mm_dd_yyyy.img -o /dev/sdb2



Method 2: Using "dd"

You can also use this alternatively method with Linux and Partclone:

How to backup:

Insert your card into your computer and do as follows (ensure your flash card is seen as sdb!)
$ sudo dd if=/dev/sdb of=raspi_openelec_mm_dd_yyyy.img bs=1M

How to restore:

Insert your card into your computer and do as follows (ensure your flash card is seen as sdb!):

$ sudo dd if=raspi_openelec_mm_dd_yyyy.img of=/dev/sdb bs=1M



Using dd will restore any partition without any other requirements.


Method 3 : Simple method using tar

How to backup:

Boot your Raspberry Pi and create a Tar archive of your XBMC folder:
# cd /storage
# tar -cvzpf /storage/xbmc_raspi_backup_mm_dd_yyyy.tar.gz .xbmc

How to restore:

To restore, simply re-create your flash SD-Card using Openelec.
Then boot your Raspberry Pi, use a SCP client to connect (WinSCP for Windows, native SSH /desktop integration / GFTP for Linux) and copy your previously backed up Archive directly in root Home Folder.

Then restore (adapt DIRECTORY to the folder where resides your tar.gz file)
# cd /storage
# tar -xvzpf DIRECTORY/xbmc_raspi_backup_mm_dd_yyyy.tar.gz



Conclusion:


As for now, XBMC with OpenELEC works very great for such a small device that could seem really low powerful.

I noticed a real low CPU usage using specified customization, providing you a smoothly XBMC Interface.

CPU Usage:

For information, with last OpenELEC build, i can observe a very low CPU Usage when IDLE, around 15-20 % not more.

Note: You should see very different CPU usage values in XBMC System Information Panel, this is caused by screen rendering. See Post #12 on http://openelec.tv/forum/124-raspberry-pi/44834-speed-comparison-with-xbian)

My Raspberry is connected trough the local Network and access to an XBMC Shared Library (Using SMB and Mysql), to be honest almost all videos 720p/1080p plays with no issues.

Therefore, Huge HD Video files will probably be difficult or impossible to play, you should avoid having files with a size bigger than 13-14 Gb... (when playing over your Network)

As a conclusion, i have to say that i am positively surprised by this small animal capacity, even if i would not change my main HTPC for a Raspberry Pi, this is very interesting and it makes a real good second XBMC client :-)

OpenELEC guys have done a real good job for this device, thank you!

Feel free to comment!



Memorandum:

  • How to update config.txt to set your Raspberry Pi parameters:
Log in to your Raspberry with ssh, and update your config.txt:
mount -o remount,rw /flash
vi /flash/config.txt

  • Official 5 Overclocking settings with New Turbo mode:
Don't set "force_turbo" to value "1", let the default value (0)

None
force_turbo=0
arm_freq=700
core_freq=250
sdram_freq=400
over_voltage=0

Modest
force_turbo=0
arm_freq=800
core_freq=300
sdram_freq=400
over_voltage=0

Medium
force_turbo=0
arm_freq=900
core_freq=333
sdram_freq=450
over_voltage=2

High
force_turbo=0
arm_freq=950
core_freq=450
sdram_freq=450
over_voltage=6

Turbo
turbo_mode=0
arm_freq=1000
core_freq=500
sdram_freq=500
over_voltage=6

How to check:

Check your kernel messages using the command "dmesg", you will see such messages which confirms the Turbo mode:
bcm2835-cpufreq: switching to governor ondemand
bcm2835-cpufreq: Freq 1000000->700000 (min=700000 max=1000000 target=700000 request=700000)
bcm2835-cpufreq: Freq 700000->1000000 (min=700000 max=1000000 target=1000000 request=1000000)


  • Monitor CPU frequency, temperature and others 
Using the following command will return current CPU frequency:
vcgencmd measure_clock arm

If you want, add this script to your storage:

sysinfo.sh
#!/bin/bash

echo -e "\n###############################################"
echo "#       RASPBERRY PI SYSTEM INFORMATIONS      #"
echo "###############################################"

echo -e "\nCPU current Frequency: `vcgencmd measure_clock arm`"
echo "CORE current Frequency: `vcgencmd measure_clock core`"
echo "CORE current Voltage: `vcgencmd measure_volts core`"
echo "CPU current Temperature: `vcgencmd measure_temp`"

echo -e "\nFirmware Version: `vcgencmd version`\n"

echo -e "Codecs Status:"
echo "`vcgencmd codec_enabled H264`"
echo "`vcgencmd codec_enabled MPG2`"
echo "`vcgencmd codec_enabled WVC1`"

echo


And add this script to your "~.profile" if you want it when you log in with SSH, or add an alias to call this script, or whatever you want :-)

  • A sample current config.txt:
# config.txt - In OpenELEC edit this file as follows:

#################################################
# mount -o remount,rw /flash                    #
# then edit and save your modification using vi #
# sync                                          #
# mount -o remount,ro /flash && reboot          #
#################################################

####################
# VARIOUS SETTINGS #
####################

# Force HDMI even if unplugged or powered off
hdmi_force_hotplug=1

#####################
# OVERSCAN SETTINGS #
#####################

# Make display smaller to stop text spilling off the screen
overscan_scale=1 # http://www.raspberrypi.org/phpBB3/viewtopic.php?f=67&t=15700
disable_overscan=1
# Adapt overscan values to your needs
overscan_left=57
overscan_right=59
overscan_top=20
overscan_bottom=20

############
# LICENCES #
############

# Licences for MPEG2 and VC1
decode_MPG2=xxxxxxxxxx
decode_WVC1=xxxxxxxxxx

###########################################################
# OVERCLOCKING MODE - REQUIRES TURBO MODE (recent builds) #
#                                                         #
# Uncomment one of the section you want to use            #
# After reboot use command "vcgencmd measure_clock arm"   #
# to get current CPU frequency                            #
##########################################################

# If you have any data corruption using Turbo Mode and overclocking
# to with this setting uncommented

#initial_turbo=30

# If this still fails, try to use Medium mode whitout "over_voltage=2"
# If this finally still fails, forget about this until this gets fixed
# Use a more conservative mode that will works fine in any cases:

# Conservative (unofficial mode)
#arm_freq=850
#gpu_freq=325
#sdram_freq=425

# Official Raspbian Overclocking modes:

# None
#force_turbo=0
#arm_freq=700
#core_freq=250
#sdram_freq=400
#over_voltage=0

# Modest
#force_turbo=0
#arm_freq=800
#core_freq=300
#sdram_freq=400
#over_voltage=0

# Medium
arm_freq=900
core_freq=333
sdram_freq=450
over_voltage=2

# High
#arm_freq=950
#core_freq=450
#sdram_freq=450
#over_voltage=6

# Turbo
#arm_freq=1000
#core_freq=500
#sdram_freq=500
#over_voltage=6




FAQ & Issues:

- Resolution and fit to screen issues:

If you still have issues with resolution, i've seen in this post an interesting config.txt setting, adapt to your needs:

http://openelec.tv/forum/124-raspberry-pi/38818-raspberry-pi-feedback?limit=20&start=160#44907
# Set stdv mode to PAL (as used in Europe)
sdtv_mode=2

# defines the aspect ratio for composite output (3 = 16:9)
sdtv_aspect=3

# Force the monitor to HDMI mode so that sound will be sent over HDMI cable
hdmi_drive=2

# Set monitor mode to DMT
hdmi_group=1

# Set monitor resolution to 1080p 50Hz
hdmi_mode=31

# Pretends HDMI hotplug signal is asserted so it appears a HDMI display is attached 
hdmi_force_hotplug=1

# Make display smaller to stop text spilling off the screen
overscan_scale=1 # http://www.raspberrypi.org/phpBB3/viewtopic.php?f=67&t=15700
disable_overscan=1
overscan_left=57
overscan_right=59
overscan_top=37
overscan_bottom=37



- Fail to play back ISO of DVD and DVD files:

This depends on many factors (the way you created your iso files and so on), still playing back with success ISO of DVD including Menu and DVD files is not absolutely guarantee.

You could think about converting into MKV files which will play perfectly!