In this Lab, we go through the steps to prepare the Raspberry Pi board for the projects in the course. this includes selecting the OS and setting it up on the SD card, connecting the Pi, and booting it.
The Lab also goes through setting up the network interfaces (both wired and wireless) and remote connecting into the Pi
3. Steps to Prepare the Pi
1. Select the Operating System to use
2. Load the SD Card with the chosen Operating System
3. Plug in the SD Card in the Pi and make the other
Connections
4. Boot the Raspberry Pi
5. Configure the Pi
6. Setup the Network (Using the Wired Ethernet Interface)
7. Setup the Wireless Network Connection (Using a WiFi
Module)
8. Connect remotely to the Raspberry Pi from the host
machine
• Via SSH
• Via VNC
5. Selecting the Operating System
• The Raspberry Pi supports a lot of operating Systems
• Some of these OS’s are officially supported by the Raspberry
Pi Foundation, and others are not officially supported
• The officially supported Operation systems are listed in the
Raspberry Pi Official site (the download page)
http://www.raspberrypi.org/downloads/
• Most of the supported operating systems are based on Linux
distributions, however there are exceptions (such as the RISC
OS)
• For an exhaustive list of operating systems that was tested to
run on the Raspberry Pi,
http://elinux.org/RPi_Distributions/
10. Raspbian
http://www.raspbian.org/
• The most popular OS for the Raspberry Pi
• Based on Debian Linux Distribution (Debian Wheezy)
• Most projects available online use it, hence this will be our
selection
13. Download Raspian
• We will need to download the Raspbian OS image from,
http://www.raspberrypi.org/downloads/
14. Loading the SD Card
• Now we need to load the selected OS image to the SD Card
• Note this is not a simple copy of a file, so simple cp will not work
• A copy of a file means the file resides inside a file system
• The file can be divided into multiple blocks
• The file meta-data for the file will be written to the filesystem
• Instead, we want to dump the raw image byte by byte to the desired
location in the SD Card (no meta data, no inode, no dentry, just byte
transfer)
• This require using a different technique,
• If the host is a Windows machine
• Use Fedora ARM Installer
• Use Win32 Disk Image Writer utility
• If the host is a Linux machine
• Use the dd command on the CLI
15. Windows Machine Host:
Using Fedora ARM Installer
• Download the zip file from
http://fedoraproject.org/wiki/Fedora_ARM_Installer
• Extract the zip file
• Run the fedora-arm-installer-2 executable (as Administrator)
16. Windows Machine Host:
Using Win32 Disk Image Writer
• Download the program from
http://win32diskimager.sourceforge.net/
• Install the program
• Run as administrator
• Keep in mind that this operation will erase the contents of the
chosen device
• This program is designed to,
• Write a raw disk image to a removable device
• Backup a removable device to a raw image file
17. Linux Machine Host:
Using the dd Command
• First step, we need to identify the device name for the SD Card
Reader in your host machine
• This can be done by listing contents of /dev before and after
inserting the SD Card, or using df -h command before and
after inserting the SD Card
• Note that sometimes, ubuntu fails to detect the SD card
• Let us assume it is /dev/sdd1
• Next, we will need to unmount the device (the whole device,
and not just the partition)
$ sudo umount /dev/sdd
• Next, we will need to dump the image file to the SD Card
(assume that the file is ~/my-image.img)
$ sudo dd bs=4M if=~/my-image.img of=/dev/sdd
22. What Does this Image Contain ??
• This image contains,
• SD Card partition table (describing the partitions on the SD Card)
• 2 Partitions
• One FAT partition
• One EXT4 partition
• The windows partition contains files that are read by the GPU at
the board boot up which includes the Linux Kernel Image
• The Linux partition contains the root filesystem for Linux
• The Linux partition will be mounted by the Linux Kernel during
the startup procedure
25. Loading the SD Card
Using NOOBS
• NOOBS stands for (New Out Of Box Software)
• It contains multiple Official Pi distributions
• To set it up, you need first to download the NOOBS zip file and
extract it in your host machine
http://www.raspberrypi.org/downloads/
28. Preparing the SD Card
• You may go to the os/ folder and delete the distribution images that
you are not interested in, this will reduce the data size that will need
to be copied to the SD Card
• First Step:
• You need to make sure the SD Card is in its initial state (delete the
partition table)
• This is done via the windows command-line tool diskpart (note that
other tools may not be able to perform this task)
http://www.winability.com/delete-protected-efi-disk-partition/
• Second Step:
• Format the SD Card as one FAT32 partition
• Use the tool SD Formatter
https://www.sdcard.org/
• Third Step:
• Copy the downloaded NOOBS files into the SD Card (normal copying
of files)
32. Booting the Pi
• Now prepare for booting the Pi,
• Install the SD Card into the Pi
• Connect a keyboard and a mouse to the Pi through the USB ports
• Connect a monitor to the Pi through the HDMI Cable
• After all connections are done, connect the power through the
micro-USB connector
• At the first boot of the Pi:
• A graphical user interface will appear
• A list of distributions will be shown, you need to select one of them
to install (or multiple)
• The GUI gives you the option to add an additional empty ext4
partition for data
• Once done selection, push the install button
• The Pi will run through installation of the distribution
• This includes reorganizing the partition table on the SD card to create
the needed ext4 partitions
35. Partition Table (after Install)
• The SD Card will have 3 partitions:
• FAT32 partition
• This is used for recovery (read by the GPU)
• Size is around 800 MB
• vfat partition
• A Linux partition mounted at /boot
• Contains the bootloader binary read by the GPU, elf files, kernel
image, and kernel configuration files
• ext4 partition
• Linux Root File System (/)
• Constitutes most of the SD Card space
37. Loading the SD Card
Using BerryBoot
• Berryboot is a boot management tool for the Raspberry Pi
• It provides nice features,
• It allows the user to install multiple OSs and select at boot time
• It allows the user to put the distributions on another storage
device (such as a hard disk connected to the USB interface). The
SD card will still be the starting point, but the root file system will
be on the other device
• It allows the user to put non-official or customized distributions
• It downloads the desired distribution directly from the internet
(using either the wired or the wireless connection)
38. Setting up the SD Card
• You will need to download the Berryboot zip file and extract it
http://sourceforge.net/projects/berryboot/
• Then the SD Card will need to be cleaned (delete partition
table) using diskpart tool
• Then it should be formatted in a FAT32 partition (using the SD
Formatter)
• Then copy the Berryboot files to the SD Card (normal copy)
• Insert the SD card in the Raspberry Pi and Boot it
• Berryboot will prompt you to select the desired OS
• The Berryboot installer will,
• Create the new partitions
• Reformat the SD Card partitions
• Download the desired Distribution from the internet
43. Setting Up the Pi
• Now you can connect the Pi to the needed peripherals
• This includes,
• Keyboard and Mouse using the USB connectors
• Monitor using the HDMI interface
• Network connection through the LAN cable (we will talk about setting it up
later)
• WiFi Dongle through the USB Connector (to be discussed later)
• Of course you will need to insert the SD Card in its slot
• Once all connections are done, you can connect the power through the
micro-USB connector
• WARNING:
• All connections must be done before power is applied to the Pi
• Even though the USB is theoretically hot pluggable, it is recommended that
you don’t connect/disconnect any USB device while the board is powered
• Not following that, may result in excessive current surges that may reboot
the Pi or even destroy it
• Also, keep in mind that the Pi power may not be able to support too many
peripherals, so consider connecting one of the USB connectors to a powered
USB Hub, and connect the other devices to it
45. Boot Sequence
• When the Pi is powered up,
• The ARM processor remains off, SDRAM is disabled, and the GPU
core is the one that starts the booting procedure
• The GPU starts executing the first stage bootloader which is
stored in the ROM on the SoC (not on the SD Card)
• This firmware mainly enables the GPU to access the SD Card, and
read a FAT32 Partition on it
• The first file read from the SD Card is the second stage bootloader
(bootcode.bin). The GPU reads this file and executes it
• The job of this stage of the bootloader is to enable the SDRAM
and it loads and runs start.elf
• The last bootloader stage start.elf reads the kernel image
(kernel.img), configuration file(config.txt), and kernel command
line parameters (cmdline.txt), then it loads them in memory, and
wakes up the ARM core
46. Boot Sequence
GPU On-Chip First
Stage Bootloader
bootcode.bin
start.elf
Linux Kernel
GPU
ARM
Enables GPU to read the SD Card
Enables GPU to read a FAT32 Partition
Enables the SDRAM
Loads and runs start.elf
Loads the Kernel image
Starts the ARM Core
Boot the Kernel
Normal Operation
47. cmdline.txt
• The cmdline.txt file contains parameters that are passed to
the kernel when it is booting
• There are a lot of possible parameters that can be passed to
the kernel
• Some important parameters:
console=tty1 (Kernel messages should be sent to tty1)
root=/dev/mmcblk0p2 (Root filesystem exists in this device)
rootfstype=ext4 (Root filesystem type is ext4)
48. Booting the Pi
• The first time the Pi boots, it will open an initial configuration
screen (will be discussed later in this lecture)
• Perform the required configuration, or exit the configuration
tool
• Then, the Pi shows the login prompt, and asks the user to
login to it, the factory settings for login info are,
Username: pi
Password: raspberry
• Now the user will be accessing the command line interface
• To use the GUI, just use the command,
$ startx
52. Raspberry Pi Configuration
(The raspi-config tool)
• Some initial configurations need to be performed on the
Raspberry Pi
• This is done using the raspi-config tool
• This tool is initiated automatically on the first boot of the
Raspberry Pi
• However, if you need to initiate this tool at a later time, just
use the command from the Pi Prompt,
$ sudo raspi-config
54. Overclocking the Pi
• By default, the ARM core runs at 700MHz
• Sometimes, it is required to boost the ARM Core performance
by increasing its clock speed (overclocking it)
• The ARM Core can be overclocked up to 1GHz
• Both the GPU Core and the SDRAM can be overclocked as well
• Keep in mind that overclocking the Pi is not recommended
unless you really need it. It generates more heat and may
destroy the SoC or reduce its lifetime
• If you overclock the Pi, it is recommended to use a heatsink or
a fan to dissipate the generated heat from the chip
60. Setup the Ethernet Connection
• All you need is to plug the LAN cable into the Ethernet port,
and your Raspberry Pi should be connected (notice that the
network LEDs will start to flicker)
• To know the selected IP Address, do,
$ ifconfig
Note that this IP Address is assigned by the DHCP in your router,
and hence it may change every time you boot
• You can fix the IP address of the R-Pi to a certain value by,
• Log on to the router and configure it to assign a fixed IP address
to the Pi
63. Setup the WiFi Connection
• You will need a WiFi (802.11) module that connects to the Raspberry Pi
through the USB interface
• Keep in mind that not all the WiFi Modules are supported by the Pi
• For a list of adapters that is verified to work with the R-Pi, check
http://elinux.org/RPi_USB_Wi-Fi_Adapters
• Make sure to connect the WiFi module to the R-Pi USB port while it is
unplugged from power
• Now you should see two network devices when using ifconfig
• On the Raspberry Pi desktop, double click on the WiFi Configuration
tool, and connect to the desired WiFi Access Point (like you would do it
on your computer)
69. Remotely Connect via SSH
• The first step to use SSH with the Raspberry Pi is to enable the SSH
Daemon on the Pi
• Using the raspi-config tool, enable SSH
• Then on the host machine, use an SSH Client
• On Windows hosts, this can be done using the PuTTY program
• On Linux hosts, SSH client is part of the openssh-client package
$ sudo apt-get install openssh-client
• From the host machine
$ ssh pi@192.168.0.113
• When prompted for the password, set it as raspberry
• Notes,
• If the host is a Linux machine, and the IP address of the Pi is fixed, we
can assign the PI a name in /etc/hosts and use it in the SSH
command
$ ssh pi@my-pi
70. Finding Out the Pi IP Address
• What if I don’t know the IP address for the Raspberry Pi
• Option 1:
• Hook a monitor and a keyboard /mouse and use the command
$ ifconfig
• But there are problems with this solution:
• Do we need to connect to a monitor/keyboard/mouse every time we boot (assuming
the IP address is not fixed) ?
• If I shutdown, to disconnect the mouse/monitor/keyboard, I may have a different IP
address
• Accordingly, this solution is not practical
• Option 2: Use the nmap Linux Command from the host machine
• Identify the LAN subnet address, Assuming that the host machine resides on the
same LAN, you can find out the LAN address via
$ ifconfig
• Before you power up the Raspberry Pi, scan for all IP addresses on your LAN
$ nmap -sP 192.168.101.*
• Power up your Raspberry Pi and wait for a minute for it to boot, then repeat the
same command, and compare results to find out the new IP address
• If you have multiple new IP addresses, you can explore more about each one via,
$ nmap -n 192.168.101.165
71. Using SSH without Password
(Using SSH Public Keys)
• To avoid entering the password every time you use ssh or scp to the R-Pi, we use
security keys for logging in
• To enable that, we do the following:
• On the host machine generate a key-pair
$ ssh-keygen
• You will need to answer a few questions, default values are ok
• When asked about a pass phrase, any password is good (just remember it)
• This will generate two key files in ~/.ssh directory
• Private Key: ~/.ssh/id_rsa
• Public key: ~/.ssh/id_rsa.pub
• Then copy the public key to the R-Pi
$ scp ~/.ssh/id_rsa.pub pi@my-pi:~/.ssh/any-file-name
• On the R-Pi, add the key to the file ~/.ssh/authorized_keys
$ echo `cat ~/.ssh/any-file-name` >> ~/.ssh/authorized_keys
• Note that, the last two steps can be replaced with, from the host,
$ cat ~/.ssh/id_rsa.pub | ssh pi@my-pi ‘cat >> ~/.ssh/authorized_keys’
• Then we try to ssh from the host into the pi, a prompt will ask for the password,
and an option will appear to store it locally, accept that option
• That’s it, now we can use ssh and scp without the need for a password
• Note, if you want to login as root, then you need to do the same in /root/.ssh
folder in the pi
73. Remotely Connect Via VNC
• First we will need to install the VNC Server on the Raspberry Pi
• Issue the following commands on a terminal on the R-Pi or via an
SSH session
$ sudo apt-get update
$ sudo apt-get install tightvncserver
• After installation, we will need to start the VNC Daemon in the Pi
$ vncserver :1
Note that it will ask you to enter a password
• On the host machine, we need to install a VNC Client, there are a lot
of VNC Clients available for both Windows and Linux host machines
• Run the VNC Client on the host, make sure to state the server IP
address and display number as :
$ vncviewer 192.168.0.113:1
Use the password that you set in the server
74. More on Setting up VNC
• In case resolution is not set correctly, we will need to set the geometry
of the VNC Server, such as,
$ vncserver :1 -geometry 1440x900
Note: select the proper geometry
• In case we need the VNC Daemon to be up every time the R-Pi boots up,
then in the R-Pi,
$ cd ~/.config
$ mkdir autostart
$ cd autostart
$ vi tightvnc.desktop
Then write the following in the file,
[Desktop Entry]
Type=Application
Name=TightVNC
Exec=vncserver :1
StartupNotify=false