Difference between revisions of "RaspberryPi:Installation"

From UCT EE Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[Category:RaspberryPi]]
 
[[Category:RaspberryPi]]
  
In order to use the Pi you need to install an operating system on it and set up networking. The following will lead you through installing Raspbian as an operating system.  Raspbian is an operating system created for the Raspberry Pi, built on Debian.  You will then configure the networking settings in Raspbian to allow you to access the Pi remotely using SSH.
+
In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH.  
 +
 
 +
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it).
 +
 
  
 
== Prerequisites ==
 
== Prerequisites ==
Line 10: Line 13:
 
* A means of writing to the SD card, such as an SD card reader
 
* A means of writing to the SD card, such as an SD card reader
  
textbf{Hardware Requirements} & \textbf{Software Requirements} \\ \hline
+
Software Requirements
\begin{tabular}[c]{@{}l@{}}\tabitem Raspberry Pi\\ \tabitem Ethernet Cable\\ \tabitem \\ \tabitem Means of writing to the Micro SD Card\end{tabular} & \begin{tabular}[c]{@{}l@{}}\tabitem \href{https://www.raspberrypi.org/downloads/raspbian}{Rasbian (Desktop \& Recommended Software)}\\ \tabitem  \href{https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html}{PuTTY (the full suite, Windows only)}. \footnote{Some versions of Windows have the required SSH and SCP packages, but PuTTY has many other tools that are useful.}\\ \tabitem \href{https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html}{SDFormatter}\\ \tabitem \href{https://www.balena.io/etcher/}{Etcher, an image writing tool}\\\end{tabular} \\ \hline
+
* An operating system image. It's recommended you use [https://www.raspberrypi.org/downloads/raspbian Raspbian]. You can read more about operating systems for the Pi on [http://wiki.ee.uct.ac.za/RaspberryPi:Overview#OperatingSystems this page]
\end{tabular}%
+
* Something to allow you to SSH in to your Pi. On Windows you can use [http://wiki.ee.uct.ac.za/PuTTY PuTTY] or [http://wiki.ee.uct.ac.za/Windows_Subsystem_for_Linux WSL]
 +
* On Windows, you will need an [https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html SD Card Formatter]
 +
* On Windows, you will require software to burn the image. [https://www.balena.io/etcher/ Balena Etcher] is recommended.
 +
 
 +
== Installation Process ==
 +
<ol>
 +
<li> Preparing the SD Card </br>
 +
Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section. </li>
 +
 
 +
<li> Burn the image to the SD card </br>
 +
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. <strong>Ignore the Windows popups about needing to format the SD card.</strong> Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with. </li>
 +
 
 +
<li> Enable SSH <br>
 +
SSH is covered in detail in [[SSH]], but for now just enable SSH by creating a file called “ssh” (no file extension) on the boot partition of the SD card.</li>
  
== Prepare the SD Card ==
+
<li>Configure Networking<br>
 +
Please read through [[RaspberryPi:Networking]]. Configuring networking on the Pi depends on what Pi you are using. For example, if you're using a 3b+, you may want to connect via a static IP over Ethernet. If you are using a Pi Zero, you may want to connect over a USB to Serial or USB to Ethernet connection. In both cases, you will likely want to connect your Pi to Wifi through Eduroam.
 +
</li>
  
The SD Card needs to be formatted before it can be used. To make your life simple, there is a tool called “SD Card Formatter” - a link is available in the Software Requirements box of the prerequisites section.
+
<li>Boot<br>
 +
Insert the SD Card into the Pi, and connect your Pi via the interface you are using</li>
  
== Install and configure Raspbian ==
+
<li>Ensure Connectivity <br>
 +
Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example, <br>
 +
<pre>$ ping 192.168.137.15</pre>
 +
You should see a response similar to
 +
<pre> $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms</pre>
 +
or
 +
<pre> $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52</pre></li>
  
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses<ref>Yes, “mouses” is entirely valid is and used to distinguish a computer device from a rodent: https://en.wikipedia.org/wiki/Computer_mouse#Naming
+
<li> SSH In to your Pi <br>
</ref>.
+
<pre> $ ssh pi@192.168.137.15</pre>
 +
You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply "raspberry".
 +
</li>
  
Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it). This is how all of the practicals will be conducted, as it is how most IoT devices are configured (over a network).
+
<li>Change your password<br>
 +
To change your password, you can simply run <pre>$ passwd </pre></li>
  
 +
<li>Enable Services <br>
 +
It's a good idea to enable useful services on the Pi.
 
<ol>
 
<ol>
<li><p>Insert the SD card into the computer. If you do not have a reader available, speak to a friend or tutor who does.</p></li>
+
<li>On your Pi, run <pre> $ sudo raspi-config</pre></li>
<li><p>Format the Micro SD card<br />
+
<li>Use the arrow keys and scroll down to “Interfacing Options”</li>
If you’re on Windows, this is where you would use SDFormatter. If you’re on Ubuntu, you can use GParted.</p></li>
+
<li>If not enabled, enable SSH, VNC, SPI, I2C and Serial</li>
<li><p>Write image to SD card<br />
+
<li>Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.</li>
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with.</p></li>
+
</ol>
<li><p>Enable SSH<br />
 
SSH is covered in detail in Section [sec:SSH], but for now just enable SSH by creating a file called “ssh” (no file extension) on the boot partition of the SD card.</p></li>
 
<li><p>Configure the Networking<br />
 
This section can get complicated, so we’ve created Section [sec:NetworkingOnThePi] to help explain it. For now, just follow the steps in Section [sec:Connectivity-Ethernet] and Section [sec:Connectivity-ChangeComputerIP].</p></li>
 
<li><p>Boot<br />
 
Insert the SD Card into the Pi. Connect an Ethernet cable between your PC and the Pi. Connect the Pi to a power source.</p></li>
 
<li><p>Ensure connectivity<br />
 
Ensure you can “see” your Pi. Open a command window or terminal, and run</p>
 
<pre>        $ ping 192.168.137.15
 
        </pre>
 
<p>You should see a response similar to</p>
 
<pre>        $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms
 
        </pre>
 
<p>or</p>
 
<pre>        $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52
 
        </pre></li>
 
<li><p>SSH in to the Pi<br />
 
Section [sec:SSH] covers all the details on SSH. For now, open a command prompt or terminal on your machine, and enter in the following:</p>
 
<pre>        $ ssh pi@192.168.137.15
 
        </pre>
 
<p>You will be asked to add the machine to known hosts. Select yes.<br />
 
The password required to log in is simply “raspberry”</p></li>
 
<li><p>Configure<br />
 
For practicals you will need to enable a few services on the Pi.</p>
 
<ul>
 
<li><p>Open a terminal. You can either click the icon or press Ctrl+Alt+T</p></li>
 
<li><p>Run</p>
 
<pre>           $ sudo raspi-config
 
            </pre></li>
 
<li><p>Use the arrow keys and scroll down to “Interfacing Options”</p></li>
 
<li><p>Enable SSH, VNC, SPI, I2C and Serial</p></li>
 
<li><p>Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot. Wait about 30 seconds, and SSH in again.</p></li></ul>
 
 
</li>
 
</li>
<li><p>Expand the Filesystem The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.</p>
+
 
<ul>
+
 
<li><p>SSH into the Pi</p></li>
+
<li>Expand the Filesystem <br>
<li><p>Run</p>
+
The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.
<pre>           $ sudo raspi-config
+
<ol>
            </pre></li>
+
<li>SSH into the Pi</li>
<li><p>Use the arrow keys and scroll down to “Advanced Options”</p></li>
+
<li>Run <pre> $ sudo raspi-config </pre></li>
<li><p>Select “Expand Filesystem”</p></li>
+
<li>Use the arrow keys and scroll down to “Advanced Options</li>
<li><p>You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.</p></li></ul>
+
<li>Select "Expand Filesystem"</li>
 +
<li>You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.</li>
 +
</ol>
 
</li>
 
</li>
<li><p>Creating another user<br />
+
</ol>
It isn’t good practice to run everything as root, so we create another user with sudo privileges. The first command adds the user, the next command adds the user to the group <code>sudo</code>, which gives them sudo execution rights. On the Pi, run the following:</p>
+
 
<pre>        $ sudo adduser &lt;username&gt;
+
== More detailed Information ==
        $ sudo adduser &lt;username&gt; sudo
+
If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the [https://www.raspberrypi.org/documentation/installation/installing-images/README.md Raspberry Pi Website]
        </pre>
 
<p>Now that you have created a new user, you can log into the Pi via SSH using that username as follows:</p>
 
<pre>        $ ssh &lt;username&gt;@192.168.137.15
 
        </pre>
 
<p>To switch users while you are SSH’d in run</p>
 
<pre>        $ sudo su - &lt;username&gt;
 
        </pre>
 
<p>To switch to root (not recommended), run</p>
 
<pre>        $ sudo su
 
        </pre>
 
<p>To change your password, you can simply run</p>
 
<pre>        $ passwd
 
        </pre>
 
<p>To change the password of another user, drop down to root and run</p>
 
<pre>        $ passwd &lt;username&gt;
 
        </pre>
 
<p>To delete a user, switch to another user with root access, and run</p>
 
<pre>        $ sudo deluser -remove-all-files -f &lt;username&gt;
 
        </pre></li></ol>
 

Revision as of 04:43, 6 February 2020


In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH.

This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it).


Prerequisites

Hardware Requirements:

  • Raspberry Pi, and a means of connecting to it, such as an Ethernet Cable for a Pi 3b+ or a standard USB cable for the Pi Zero/ZeroW
  • A micro SD card
  • If you're using the Pi 3b+, a power source (the USB port doesn't provide enough current)
  • A means of writing to the SD card, such as an SD card reader

Software Requirements

  • An operating system image. It's recommended you use Raspbian. You can read more about operating systems for the Pi on this page
  • Something to allow you to SSH in to your Pi. On Windows you can use PuTTY or WSL
  • On Windows, you will need an SD Card Formatter
  • On Windows, you will require software to burn the image. Balena Etcher is recommended.

Installation Process

  1. Preparing the SD Card
    Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section.
  2. Burn the image to the SD card
    Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. Ignore the Windows popups about needing to format the SD card. Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with.
  3. Enable SSH
    SSH is covered in detail in SSH, but for now just enable SSH by creating a file called “ssh” (no file extension) on the boot partition of the SD card.
  4. Configure Networking
    Please read through RaspberryPi:Networking. Configuring networking on the Pi depends on what Pi you are using. For example, if you're using a 3b+, you may want to connect via a static IP over Ethernet. If you are using a Pi Zero, you may want to connect over a USB to Serial or USB to Ethernet connection. In both cases, you will likely want to connect your Pi to Wifi through Eduroam.
  5. Boot
    Insert the SD Card into the Pi, and connect your Pi via the interface you are using
  6. Ensure Connectivity
    Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example,
    $ ping 192.168.137.15

    You should see a response similar to

     $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms

    or

     $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52
  7. SSH In to your Pi
     $ ssh pi@192.168.137.15

    You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply "raspberry".

  8. Change your password
    To change your password, you can simply run
    $ passwd 
  9. Enable Services
    It's a good idea to enable useful services on the Pi.
    1. On your Pi, run
       $ sudo raspi-config
    2. Use the arrow keys and scroll down to “Interfacing Options”
    3. If not enabled, enable SSH, VNC, SPI, I2C and Serial
    4. Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.
  10. Expand the Filesystem
    The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.
    1. SSH into the Pi
    2. Run
       $ sudo raspi-config 
    3. Use the arrow keys and scroll down to “Advanced Options
    4. Select "Expand Filesystem"
    5. You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.

More detailed Information

If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the Raspberry Pi Website