Raspberry Pi: Software View
Raspberry Pi: Software View
Software View
ELECTGON
www.electgon.com
[email protected]
28.04.2018
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Installing Raspbian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 First Settings with Raspbian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.1 Expand Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 Assign Static IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.4 Wireless Connection Setup . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4.1 Credentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.5 Enable SSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.6 Other Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Remote Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 BackUp Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Abstract
Previous tutorial was introduced to give overview of Raspberry Pi board as a Hardware view.
Software settings for Raspberry Pi are needed to be declared including its Operating System.
Only basic settings are needed to be understood. Afterwards, Raspberry Pi can act as simple
computer machine that allow user to install his applications as long it is compatible with
the running operating system. This document provides needed steps to have Raspbian as a
running operating system and some other con igurations that may be needed.
RPi Software 1. Introduction
1 Introduction
Once you have your Raspberry Pi board is ready and connected with needed peripherals,
you can start working with it as long you have an operating system is installed in its attached
micro SD card. Available operating system images for Raspberry Pi can be found in its website
https://www.raspberrypi.org/downloads/
On this page you can ind ready images like Ubuntu mate, Ubuntu Snappy, Windows 10
and Raspbian. This Raspbian is built to be optimized for Raspberry Pi. This operating system
(or root ile system to be more speci ic) is built based on Linux kernel which enables user
con igurations to be applied (like realtime patch for instance). The following discussion will
use Raspbian to show how to work with software settings for Raspberry Pi.
2 Installing Raspbian
When you choose which operating system to download. You have to prepare SD card to install
this operating system (Raspbian in our case) into this SD card. Also we have to ind a tool
which we can use to install Raspbian on the SD card. Raspbian will be downloaded as an
operating system image ( ile with extension .img). This means we need to write this .img ile
to the SD card. If your host machine (machine that you will use to write the .img ile into SD
card) is windows, you can use one software called Etcher to write the image. As shown in
igure 2, you can use this tool easily.
1
RPi Software 2. Installing Raspbian
In case you have Linux as the host machine, dd package can be used to write the image.
The following steps explains how to write the image using dd.
• Connect your SD card to your machine.
• Usually SD card is seen at sdb or sdd, so whatever the driver you have, unmount it. Also
note that the SD card may appear in 2 drivers. If happens, unmount both drivers
$umount /dev/sdb1
$umount /dev/sdb2
• Now navigate to your downloaded Raspbian and start to install it on the SD card using
dd command
$sudo dd bs=4M if=2015-11-21-raspbian-jessie.img of=/dev/sdb
This may take sometime but after inished, you are done with a ready SD card to work
with Raspbian.
Important to note here that the SD card will be partitioned into two partitions boot & root.
It is highly recommended to open the boot partition and add an empty ile named as
’ssh’ without any extension. This ile then will enable you to access the Raspberry Pi
remotely using ssh protocol.
2
RPi Software 3. First Settings with Raspbian
In order to make use of all of your SD card space, make sure that Raspbian has been successfully
expanded on the disk space. You can check irst how the sd card is partitioned by typing
$df -h
then type:
$sudo raspi-config
the following window shall be opened
Enter through ’Advanced Options’ then Choose First option “Expand Filesystem”
3
RPi Software 3. First Settings with Raspbian
3.2 Keyboard
According to your language, you can choose which keyboard layout you use
$sudo raspi-config
4
RPi Software 3. First Settings with Raspbian
Enter through ’Localisation Options’ then follow the following options as shown in shots.
Important Note: in new releases of Raspbians, the following steps are not needed anymore.
Keyboard layout is con igured automatically.
5
RPi Software 3. First Settings with Raspbian
6
RPi Software 3. First Settings with Raspbian
7
RPi Software 3. First Settings with Raspbian
Most of work done in Raspberry Pi, can be executed with remote connection (using SSH). It is
good idea then to have ixed IP address in order to access Raspberry Pi remotely. Default
setting in Raspberry Pi makes IP address is assigned by dhcp server, which means most
probably you will have different IP address each time you reboot your Raspberry Pi. That
is why it is important to have ixed IP address.
In order to give your Raspberry Pi static IP address, use the following to open network
interfaces ile
$sudo nano /etc/network/interfaces
Add the following before de inition of eth0 (if it is not already exist)
allow-hotplug eth0
if you found de inition of eth0 using dhcp, modify it to be as follows
iface eth0 inet static
and add the following
address 192.168.1.100
netmask 255.255.255.0
where address is the static IP address that you wish to be assigned always to your Raspberry
Pi, so change it according to your preference.
The interfaces ile should look like the following
8
RPi Software 3. First Settings with Raspbian
Starting from Raspberry Pi 3, the board comes with a wireless interface that is powerful and
make the Raspberry Pi accessable through many interfaces. Enabling the Wireless interface
is pretty similar to ethernet interface. So open the network interface ile
$sudo nano /etc/network/interfaces
then add the following lines at the end
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 192.168.178.25
netmask 255.255.255.0
gateway 192.168.178.1
Also here the address and netmask and gateway depend on the address of your available
wireless network. The ile should look like igure 8
9
RPi Software 3. First Settings with Raspbian
3.4.1 Credentials
The or difference or important setting in wireless interface de inition is the credentials to join
the network. As shown in igure 8, the wpa_supplicant.conf is used to provide the network
credentials. To add credentials of your network, open wpa_supplicant.conf
$sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
At end of the ile, add the following section
network={
ssid="Wifi_Name"
psk="WifiPassword"
}
Where “Wi i_Name” is the name of the wireless network, “Wi iPassword” is the password,
So they have to be changed according to your network settings.
Sometimes it is desired to have the password encrypted, this can be done using the command
’wpa_passphrase’. To generate encrypted psk use the following
$wpa_passphrase "Wifi_Name"
You will be asked for the password. After providing it, you will have an encrypted psk.
Just copy the new encrypted psk instead of the un‐encrypted one
network={
ssid="Wifi_Name"
psk=250648005ff2fac9182665c004de85300f9c2bb7b9f1de0bf840cdfe
}
Ctrl+O then Ctrl+X to save your modi ications in wpa_supplicant.conf and exit.
If you didn’t enable ssh at beginnig, now it is time to enable the SSH service in order to access
the Raspberry Pi remotely.
$sudo raspi-config
choose “Interfaceing Options”, the following panel should appear. Choose to enable SSH.
10
RPi Software 3. First Settings with Raspbian
11
RPi Software 4. Remote Connection
Some other installations are advised to be performed in order to prepare Raspbian for further
application to be set. The following packages can be installed once you have an active internet
connection to Raspbian.
$sudo apt-get install build-essential
$sudo apt-get install htop
$sudo apt-get install git
$sudo apt-get install sysbench
4 Remote Connection
All previous instructions assumed that user is interacting with the Raspbian directly by connecting
a Monitor to Raspberry Pi to command the Raspbian directly. This is not necessary as you can
work with Raspberry Pi remotely by means of SSH. The point here is SSH has to be enabled in
Raspbian, this has been discussed in section 2. So when you install Raspbian in the SD card,
you have to add empty ile called ’ssh’ in the created ’boot’ partition.
So all what you need to do is to install Raspbian to the SD card, connect the Raspberry
Pi then into your network. Raspberry Pi will be assigned with IP address. This IP address is
what we will use to connect using SSH. The following steps assume that you need to connect
to Raspbian from another Linux machine.
In order to know this IP address, you can you use nmap package in your local machine
that will connect to Raspberry Pi remotely. Install this package if it is not installed by
$sudo apt-get install nmap
Then to igure out what it is the assigned IP for the Raspberry Pi, execute this command
12
RPi Software 5. BackUp Operations
$nmap -sn -A 192.168.1.*
where 192.168.147 is the irst section of your network IPs. This command will list all
connected devices in the network along with its assigned IP. Have a look then on these devices
names until you ind Raspberry Pi device, capture its IP then.
You can connect to Raspberry Pi then by
$ssh [email protected]
Replace xxx with the number you have found from nmap operation. For irst time connection,
your local machine will ask for authentication of connection and adding ECDSA key. Respond
with yes to proceed with the connection. You can now work with Raspberry Pi remotely and
perform any possible operation.
In some cases, If you have more than Raspberry Pi board, you may want to connect your
prepared SD card to other Raspberry Pi board. If you want to connect remotely then, your
local machine will notice that the connected device has been changed and the saved ECDSA
key is not matching with the detected device. You can’t connect remotely then if you got this
warning message.
To solve this point, you can delete the old ECDSA key and establish new one. You can do
that simply by
$ssh-keygen -R 192.168.1.xxx
then connect with ssh again to establish new ECDSA key.
In case of Windows operating system, nmap can be installed with a gui, it is free and
downloadable from the internet.
5 BackUp Operations
To make backup of your current installed Raspbian
df -h
this is to know what is the driver of your SD Card. Assume it is in /dev/sdb1 & /dev/sdb2
$sudo dd if=/dev/sdb of=/path/to/backup/location bs=4M
To reinstall this back up again the same dd command shall be used.
If it happened that your image bigger than available SD Card, then you can use the following
script to resize the image to it into the card. This script is taken from
http://sirlagz.net/2013/03/10/script‐automatic‐rpi‐image‐downsizer/
#!/bin/bash
# Automatic Image file resizer
# Written by SirLagz
strImgFile=$1
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
13
RPi Software 5. BackUp Operations
echo "**********************************"
echo "*** This should be run as root ***"
echo "**********************************"
echo ""
exit
fi
if [[ -z $1 ]]; then
echo "Usage: ./autosizer.sh "
exit
fi
14
Bibliography
[1] https://www.raspberrypi.org/
[2] http://sirlagz.net/2013/03/10/script‐automatic‐rpi‐image‐downsizer/
15