Showing posts with label installation. Show all posts
Showing posts with label installation. Show all posts

Wednesday, November 27, 2013

Raspbian Installation


The Raspberry Pi is a great little device that can be used for hardware hacking, environment monitoring, electrical engineering, media center and anything else one can imagine.  But, the Raspberry Pi does not come with an Operating System.  So first things first, we need to install one.  The absolute most popular distribution is Raspbian, based on Debian Wheezy.

Write Image

Raspbian comes as a disk image, which needs to be downloaded and written to a SD card.  The SD card needs to be at least 4 GB and at least a class 4 (speed).  The SD card will then be inserted into the Raspberry Pi and finally powered on.  I will be using Linux to write the disk image to the SD card.  If you are using Windows, you can use the "Win32DiskImager" tool (See Connecting to the Pi).


The following will download Raspbian and write it to the SD card.  At the time of this writing, the latest version of Raspian is 2013-09-25-wheezy-raspbian.zip.  Adjust the file name if latest has changed.  The disk image is about 600 MB so be patient as it downloads.  Writing a 600 MB image to an SD card is also slow (about 7 minutes), so additional patience will be needed here as well.

# wget http://downloads.raspberrypi.org/raspbian_latest
# unzip 2013-09-25-wheezy-raspbian.zip
# sudo dd if=2013-09-25-wheezy-raspbian.img of=/dev/sdh bs=1M

The /dev/sdh is the device node my USB SD card reader/writer appeared as.  I used dmesg, after connecting the USB device, to determine this.

Now that we have the image written to the SD card, we can plug it into the Raspberry Pi and power it on.  To make life easier one should connect an HDMI (or RCA video) to both the Raspberry Pi and a TV, connect a USB keyboard and mouse (optional), connect network via Ethernet (optional), connect finally connect power through a USB Micro cable.  The Raspberry Pi will now begin to boot, and you should see the boot process, with a little raspberry image logo, on your TV.

raspi-config

On the first boot, you will be presented with the text dialog based raspi-config tool.


This tool can be used to configure a variety of features, but for now it is important to just "Expand Filesystem".  This will take our 600 MB image and expand it out to the full size of our SD card, which can vary in size.

The other 3 options I like to change at this point are User Password, Boot to Desktop, Time Zone (found under Internationalization Options), Hostname (under Advanced Options), and Memory Split.

If you would like to announce to the world your usage of the Raspberry Pi, select the Add to Rastrack option, which will add this Pi to the online Raspberry Pi Map.  Others can then see your Pi on the Rastrack map.

If you need to modify these configurations at a later time, the raspi-config tool can be rerun with:

# sudo raspi-config

The raspi-config tool can also be run over SSH, if that is more convenient.

Once you are happy with your changes, quit out of raspi-config.  It will ask if you would like to reboot, if needed, and you should.

Desktop vs Headless

There are two modes the Raspberry Pi is commonly run in: desktop and headless.  Raspbian defaults to booting to headless mode.

With desktop, one is interested in interacting with the Pi through a GUI with mouse and keyboard.  Within raspi-config, you will want to set the "Boot to Desktop" option and also modify the "Memory Split" to the 64 MB default, or higher.  The "Memory Split" determines how much memory is allocated to the GPU.

With headless, (Raspian's default) one is interested in interacting remotely with the Pi through SSH or a web interface.  You will want to set the "Boot to Console" option and drop the "Memory Split" to a minimal 16 MB.

Default Login

Raspbian is setup with a default user by the name of "pi".  The default password for user pi is "raspberry", unless this was changed within raspi-config.


Networking

The Raspberry Pi is far more useful with network access.  Simply connect an Ethernet cable to Raspberry Pi and it should acquire an IP address on boot.  To determine your IP address, run the "ifconfig" command.

# sudo ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:28:ea:55
          inet addr:10.10.10.47  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...

With the IP address, you can now connect to the Raspberry Pi over SSH, which opens a world of possibilities.

Wireless access is also possible, but you will need to purchase a WiFi dongle and modify some configuration files.

System Update

Lastly, there are constantly changes being made to the packages installed.  Raspbian (Debian based) uses APT for package management.  To keep your system updated, you should occasionally run the following commands:

# sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get dist-upgrade  # (optional)

APT Package Management

A quick overview of APT package management... (I use the package "screen", a terminal multiplexer, in this example

To install a package: (apt-get install [package])

# apt-get install screen

To uninstall a package: (apt-get remove [package])

# apt-get remove screen

To search for a package: (apt-cache search [package])

# apt-cache search screen

To see package informaiton: (apt-cache show [package])

# apt-cache show screen



RaspBMC Media Center Installation


The Raspberry Pi can be used as a media center.  The Raspberry Pi media center can serve up media such as music, videos and pictures.  There are a number of distribution options based on XBMC the "Open Source Home Theatre Software".  The two most popular are RaspBMC and OpenELEC.  The following is a quick guide for installing RaspBMC.

Write Image


First, download latest RaspBMC image and write to SD card:
# wget http://downloads.raspberrypi.org/raspbmc_latest
# gzip -d raspbmc-2013-10-02.img.gz
# sudo dd if=raspbmc-2013-10-02.img of=/dev/sdh bs=1M

I used Linux to write the image to the SD card.  If you are using windows, you can use the "Win32DiskImager" tool (See Connecting to the Pi).  The raspbmc-2013-10-02.img.gz was the available version at the time of this post, adjust the file name as needed.  The /dev/sdh is the device node my USB SD card reader appeared as.  I used dmesg, after connecting the USB device, to determine this.

First Boot

Connect an HDMI cable to both the Raspberry Pi and a TV.  If you are planning to serve media files up from another server (across NFS / CIFS), connect a network cable.  Although it is possible to use wireless, it is recommended to use at least a Fast Ethernet wired cable, otherwise the video performance may suffer.  Connect power, and watch the Raspberry Pi boot.

On the first boot, you will be asked to configure a few of options, such as locale and time, within a text based dialog wizard.  The configuration options are minimal compared to Raspbian's raspi-config.  The Raspberry Pi will reboot again, this time into RaspBMC windows manager (pictured above).

You are now ready to start using the RaspBMC Media Center.

Serving Media from USB

The quickest way to play media is to copy the media files to a USB drive, and connect this to the Raspberry PI.  From here, it is just a matter of browsing to the files you wish to play.

Service Network Media over NFS

If you are like me, you have a massive file server in the basement housing your collection of music, videos and photos.  To remotely gain access to these files, we can mount an NFS (or CIFS) share.

The NFS tools are already available, but to mount an NFS share we need to first enable the RPC Binding service.
sudo service rpcbind restart
sudo update-rc.d rpcbind defaults

Next we can  mount our NFS share:
sudo mkdir /pub
sudo mount myserver:/pub /pub

Adjust "myserver" and "/pub" to match your server name and NFS share.

To make this available on boot, add the following to /etc/fstab:
myserver:/pub      /pub            nfs     defaults        0 0

Now you will have full access to your media from your Raspberry Pi.

DVD Playback

The Raspberry Pi can also playback MPEG encoded videos, but first you will need to purchase a MPEG-2 license from RaspberryPi.com for about $4.  After waiting about 72 hours for your license key to arrive by email you can then add your license key to /boot/config.txt.  Now you will be able to play your MPEG encoded videos through RaspBMC.