First bake of your Raspberry Pi

22 Sep

Introduction

This is a short tutorial on how to bring up your Raspberry Pi for the first time and make it run something simple and fun.

In order to know that we accomplished what we want to, lets set the goal first. At the end of this short tutorial, we should be able to

  • Boot Raspberry Pi using an OS image (server grade, not desktop grade)
  • Run a webserver and a light blogging software on Raspberry Pi
  • Run a few automated scripts that collects a few simple statistics on the system and present this information as regular blog post

What we need

In order to accomplish our simple goal, we need the following bill of materials

  • Wiring and powering
    • Raspberry Pi device
    • A MicroUSB power supply (The minimum recommended power is 700mA at 5v. Most of the current day devices should support that. I personally use one of the power supplies that came with either of these devices – HTC Android phone, Asus Nexus 7 Android tablet or LG Nexus 4 Andriod phone. In a nutshell – you may not have to buy a power supply, you can use a redundant one that is eating dust around.)
    • A HDMI-HDMI cable (I run my Raspberry Pi without a monitor. I temporarily connect it to my TV during first builds, to do any inital configuration. Rest of the time, I connect to the device using SSH sessions from other computers.)
    • A USB keyboard. Please use a very basic keyboard that doesn’t draw too much power. Finding one should be fairly easy.
    • A class-4 or better SD Card of size 4GB or more.
    • A network cable
  • Display and connectivity
    • A monitor or TV that can take HDMI input. If you have a monitor that supports DVI only, you may have to use a HDMI-DVI cable instead.
    • A router or switch port on your home or office network to connect the Raspberry Pi to. I recommend a DHCP enabled network port for ease of use
    • A computer with network connection and SD card slot to download the OS and build your SD card.

Getting to know your Pi

At this time, I strongly recommend going thru this quick start guide, so that you are familiar with the device’s ports and connections.

Installing the OS on SD Card

I would normally do it the old fashioned way – by downloading the Raspbian Wheezy OS image and keeping it for multiple installations. I use my Mac or Linux system to prepare the SD Card and dumping the OS image using dd command. You need to be very careful and shouldn’t overwrite the primary hard disk on your system while taking this approach.

If you prefer to do interactive installations, download NOOB software from here. The NOOB software is interactive and offers you a few choices while guiding thru the installation process.

The rest of the tutorial is based on Raspbian Wheezy OS. If you prefer to install any other OS, the instructions might slightly change.

Booting the Pi

  • Connect the HDMI cable to monitor or TV
  • Insert the USB keybaord into one of the USB ports
  • Insert the network cable and connect the other end to the switch port or router.
  • As a last step, insert the micro USB power supply. Note that there is no additional power switch to Pi. Once you insert the power cable, it starts booting.

Once the system boots to a login prompt, login with the default username and password ( pi / raspberry ). Check if you are connected to Internet. If you see any issues, you might want to refer to the Raspberry Pi Forum.

Scenario

Here is a very simple scenario we are envisioning to accomplish on this Raspberry Pi.

There are three users setup on the system: boat, pi and tiger. The boat user is the one that collects the metrics and reports. The metrics collected are:

  • How long the system is up, how many users are currently on the system and the load on the system
  • How many pi users are on the system
  • How many tiger users are on the system

The metrics are collected by the boat users once in about 10 minutes and each collection is reported as a blog post.

Additional Software

For accomplishing our scenario, we need

  • A webserver running on the system: Let us use Apache as our webserver. If you prefer, there are other choices like Nginx or Lightttpd. However, this tutorial covers only apache2
  • A blogging software: Blosxom is one of the simplest blogging software around. It works on flat files (no DB installation required) and the blogging process is very simple – add a new post in the form of a new file that has the text either in text or HTML format.

Blosxom works by reading files in a given directory and displaying those files as a blog. Each file is treated as a separate blog entry. The first line of the file is treated as title of the blog post. The timestamp of the file is attributed to the blog post as publish time.

This approach of Blosxom fits our bill – periodically check a few metrics on the system and report these metrics. All we need to do is to collect all the metrics in one file and the file gets displayed as a blog post by Blosxom.

Updating/Installing the packages

It is a good practice to update the lists and upgrade the packages. Use the following commands to udpate the packge lists and then upgrade the packages.

sudo apt-get update
sudo apt-get upgrade

Once you are done, your Raspberry Pi should be running the latest version of the packages installed on the system. Now, I would recommend installing Apache webserver.

sudo apt-get install apache2

Once you install apache2, make sure that you have Apache up and running. Execute the following command and then visit the Raspberry Pi device using a browser (e.g. 192.168.0.109).

sudo service apache2 start

Now you should be greeted with the popular and familiar “It works!” greeting.

Configuring the rest of it

Now, let us create the users boat and tiger.

sudo useradd -m -U -d /home/boat boat
sudo useradd -m -U -d /home/tiger tiger
sudo passwd boat
sudo passwd tiger

Let us now configure the directory for our Blosxom blog and get it ready. For simplicity, I suggest we make this directory to be owned by the boat user.

sudo mkdir /var/www/LifeOfPi
sudo chown -R boat.boat /var/www/LifeOfPi

Once you reach this point, lets install and configure the blogging software – Blosxom. Blosxom is downloadable from here. You must download the file to your desktop and then copy it to the Raspberry Pi (using SCP is what I recommend.)

Assuming that the file (with .tar.gz extension is downloaded and copied over to the home directory of the boat user, you can extract it and copy it over to the apache directory.

Let us start with becoming the boat user. For the rest of the tutorial, the commands are executed with the id of the boat user.

sudo su - boat

Extract the software and copy it over to the web server’s directory.

tar xzf blosxom-2.1.2.tar.gz 
cp blosxom-2.1.2/blosxom.cgi /var/www/LifeOfPi/index.cgi

Now view the file /var/www/LifeOfPi/index.cgi and make the following two changes (if you prefer, you can change more parameters and the code offers decent explanation of each of the parameters):

# What's this blog's title?
$blog_title = "Life Of This Pi";
# Where are this blog's entries kept?
$datadir = "/home/boat/blosxom/data/";

Now, create the directories for  scripts and data.

mkdir /home/boat/blosxom/data
mkdir /home/boat/scripts/

Create the script that collects sample data and dumps to the file. The script is created with the name /home/boat/scripts/whatismylife.sh

#!/bin/sh

myts=`date +%y-%m-%d-%H-%M-%S`
myfile="/home/boat/blosxom/data/post-${myts}.txt"
mydate=`date`
mypi=`who | grep "^pi" `
mynpi=`who | grep "^pi" | wc -l `
mytiger=`who | grep "^tiger" `
myntiger=`who | grep "^tiger" | wc -l `
myuptime=`uptime`

echo "What the boat says at [$mydate]\n" >> $myfile
echo "At [$mydate], I have $mynpi Pi-s and $myntiger Tiger-s.\n<br>" >> $myfile
echo "<br>At that very minute, my sailing status looks like this: \n<pre>\n" >> $myfile
echo "$myuptime" >> $myfile
echo "\n</pre>\nPi-s on the system: \n<pre>\n" >> $myfile
echo "[\n$mypi\n]" >> $myfile
echo "\n</pre>\nTiger-s on the system: \n<pre>\n" >> $myfile
echo "[\n$mytiger\n]" >> $myfile
echo "\n</pre>\n" >> $myfile

Make the script executable

chmod +x /home/boat/scripts/whatismylife.sh

For the boat user, add a crontab entry that looks like the following line, so that the script gets executed every 10 minutes.

*/10 * * * * /home/boat/scripts/whatismylife.sh

To start with, execute the script once manually.

/home/boat/scripts/whatismylife.sh

Now, you can see the blog running on your Raspberry Pi device by visiting the URL of the blog (if your Raspberry Pi’s IP address is 192.168.0.109, then the url would be http://192.168.0.109/LifeOfPi/ ).
Here is a sample screenshot from my Raspberry Pi running Blosxom.

RPi Screenshot

Hope you liked this tutorial and your Raspberry Pi. Happy Baking!

Costs of Data Center Outages

10 Sep

This post at VirtualHosting.com discusses several interesting metrics and forecasts. They include

  • Data transfer metrics from/to Data Centers
  • Top causes for Data Center Downtimes
  • Top Cloud Outages due to Data Center Downtimes
  • Projected outage costs

As cloud based services become more and more prominent, the reliance on data centers is pushed from end customers to cloud service providers. That way, data center outages are going to get more visibility while they are hosting cloud service providers than while hosting end customers.

In other words, while consumers appear to be moving more towards cloud based services, the cloud based services themselves become more reliant on the data center services that cut across multiple geographic regions.

Here is the graphic for quick access, from VirtualHosting.com

Data Centers Downtime
Data Centers Downtime

Pi: Ready To Serve

02 Sep

I got hooked onto Raspberry Pi in recent weeks. Here are a few factors that contributed to this fanciness towards the device

  • Simplicity of the device
  • Ability to compile accessories from existing gear
  • Potential of the device to serve to a wide range of use cases
  • Ability to start simple and then dig deeper
  • Potential in Education
  • Low cost

As discussed in some of my tweets, the device I got a few months ago has been successfully running a blogging software that is used to test the resilience of the system while running automated tasks and a web server stack. More details on the stack later.

After being thoroughly impressed with the device, I ordered (from element14) a bunch of devices as spares and giveaways. Finally I got my hands on these devices and managed some time to unpack these.

 

Pi-Ready-2013-09

 

I am compiling a series of notes to get these devices up and running. These notes help me in distributing these devices effectively and make them useful for the target audience. As a first batch, these devices are most likely to go to educational institutions that I frequently visit as a guest faculty.

 

Knock, Knock. Who is this?

18 May

Viruses knock your doors quite often. You should ask the right questions before letting anyone in.

For the last 2+ weeks, a specific version of Skype virus is on unleash and impacted many people I know. The virus looks more like a nuisance initially, but has the potential to impact the infected systems to a greater level.

The virus spreads itself with a message that looks like this “When was the last time you saw this photo [link]”. This message is broadcasted to all the contacts of a compromised account. Once the recipient clicks on the link, multiple things are observed to happen to the system. Firstly, the message is now broadcasted to the contacts of the newly compromised account. Secondly, the system leaves a trace of itself on the system. More often, the firewalls on the impacted Windows systems are turned off and the skype settings for the user are set in such a way that arbitrary programs can be executed by skype sessions.

The virus also appears to have two variants, in terms of the messages it sends – the URL can be a generic URL or a personalized URL that includes the skype id of the recipient. The second variant, IMO, has a better hit rate – who would normally ignore a link that is so personalized?

There are multiple fixes recommended for impacted systems/accounts.

  • Make sure that skype settings are changed to not execute arbitrary / external code. Instructions at this post would help.
  • Make sure you run Malwarebytes or any other good anti-virus
  • Make sure that your Windows firewall is turned on.

Not clicking on such links is a prerequisite though.

 

 

Bind, linux and resilience

11 Mar

Last month was a pleasant milestone for one of the servers I manage – the server is up for more than 1000 days and actively serving public DNS queries.

$ uptime
 19:52:37 up 1013 days,  2:44,  2 users,  load average: 0.00, 0.00, 0.00
$

The configurations on the device change on a weekly basis, the server serves a few thousand queries every hour. The queries served cover few tens of domains and reverse pointers for large IP blocks.

Given the amount of activity and the dynamism involved, this uptime shows the stability and resilience of the bind program and the underlying Ubuntu linux.

Despite being fully satisfied with bind, the latest one I am getting fascinated by is tiny-dns. Key take-aways from tiny-dns include ability to cache queries and being able to serve PTR/A records off the same configuration lines. Segmenting the responses based on originating (source) IP block is also quite simple in tiny-dns.

Hope to bring up a few production systems in tiny-dns to ensure that we have a choice.

Netflix Open Source – Inauguration

07 Feb

Today, Netflix conducted the inaugural open house of its opensource applications.This is the first ever public event of Netflix in its opensource efforts that started almost three years ago.

 

Netflix OSS Inauguration

There are several opensource projects that Netflix lined up for this event. Here are the ones I personally liked

  • Asgard: Web application for application deployment and cloud management. I like the simplicity and focus of this web application. Primarily speaking the AWS language, this is a great tool.
  • Denominator: This project doesn’t feature yet on Netflix’s github page (at least at the time of the writing) but this is something very close to the challenge I face regularly – How to ensure the name services integrity and availability in business continuity situations.

Visit Netflix’s opensource page at http://netflix.github.com/. This site presents you with a familiar Netflix streaming interface to the company’s new baby.

Netflix OSS

The next meetup is scheduled for March 13th.

 

Clouds, outages and tracking

17 Nov

As many businesses are transitioning some or more of their internal and external services to cloud, cloud incidents start having a bigger impact. The impact can range from productivity hit for employees to crippled services to customers.

There are several trackers for uptime of services like DNS, webhosting, VPS and mail. However, the concept of cloud is more towards the infrastructure view than service view. The availability metrics for infrastructure are often discussed, debated and hardly agreed upon. That puts could availability metrics to an age-old turf – more qualitative than quantitative.

There are some interesting efforts in the past like Cloutage, but they seemed to fizz out in the recent past. Even their tracking methods are status/event driven than metrics driven.

Adrian Cockcroft started tracking the cloud outage reports on his blog earlier today. He is trying to compile information based on scope and cause of the outages involved. That I think will be an interesting list to watch, till we get more concrete, metrics driven could outage reports.

Solaris diskspace calculation in Megabytes

04 Nov

Someone asked me how they can compute the diskspace (used/available) in Megabytes. The goal is to get the info in Megabytes only and report it, so that other programs can make use of it in automation.

As a backdrop – the df command in Solaris supports the -k switch, which computes the diskspace in kilobytes. Unlike linux, which supports switches for human readable formats (-h) and blocksize switch (-B), the df command in Solaris has limited number of switches.

Here is a small code snippet that can get you the file system utilization (for a given file system – in this case /) in Megabytes.

 

$ df -k / | tail -1 | awk ‘{ print $1, $2/1024, $3/1024, $4/1024, $5, $6 } ‘

rpool/ROOT/solaris-161 476612 230165 246197 49% /

$

 

The idea is to grab the kilobyte numbers and divide them by 1024. Depending on your need, this snippet can be further improved to display the output in various formats (like sizes in GB or drop some fields.)