Lab 3: Working with your Pi
You'll work on this lab individually (but it's ok to ask other students for help). In this lab, you'll set up Linux on your Pi and get some experience with command-line tools. Goals:
- Set up Raspbian on your Raspberry Pi 2 B
- Log into your Pi from your laptop
- Install Subversion to check out and commit your lab work.
- Explore a variety of command-line tools
The Equipment you need for this lab:
- Your Laptop (with Windows... if you use Linux or Mac, the instructions will be a little different)
- A Raspberry Pi 2 model B project board.
- A micro SD card (at least 8GB)
- An adapter that will let you plug the micro SD card into your laptop.
- A micro USB power adapter (or another way to get power into the pi).
- An Ethernet cable
Gather this stuff, make sure you have it all before you start.
Part 1: Setting up the Pi
Prep the Disk
- Download the latest Raspbian Disk Image onto your local machine. It's really big, so you may want to put it in ~/StaysOnPC.
- Unzip the file you downloaded.
- Stick the SD card into your laptop. Push hard enough so that you hear it click.
-> - Write the image onto your SD card. For this, follow the instructions on the raspberry pi site: here
- Remove the SD card from your laptop. To do this from windows, first you must "eject" it via "Safely remove hardware". Once Windows has finished with it, push the card to eject it.
Prepare the Network
Next, you need to set up a small local network so your computer can talk to the Pi! Be sure to do all this before you turn on your Pi.
- Open "Network and Sharing Center" via the wifi system tray icon.
- Select "Wireless Network Connection" to configure.
- Select "Properties", and authenticate as an Administrator.
- Select the "Sharing" tab, and check the box to allow other network users to connect through your Internet connection.
- Be sure "Local Area Connection" is selected from the "Home networking connection" drop-down box.
- Click "OK" buttons until all the network configuration windows are gone.
Mac OS X: Go to System preferences > Sharing > Internet sharing. Share your wireless connection to your ethernet.
Ubuntu: Go to System Settings > Network > Wireless > little arrow by your connected network > Settings > IPv4 Settings > Method: Shared to other computers
Hook up the Pi!
- Pull the microSD card out of the adapter, and insert it into the Pi.
-> - Connect your Ethernet cable to your laptop and the Pi.
- Plug the AC adapter into a power outlet and into the Pi.
-> - Admire the lights on the circuit board. There should be lights in two places: on the top by the SD card and on the network port. Oooh. Pretty.
- After about 30 seconds, open up "Git Bash" or a Command prompt on your computer.
- Check if the Pi is alive using the command
ping raspberrypi.local
. If you don't see something like the following, it's not connected. - Once you've verified the pi is alive, close your command prompt.
Take Control
Now that you know it's connected and alive, it's time to log in! Use SSH to log into the pi. You'll use the same program (SecureCRT, Putty or your favorite SSH client) that you used in Lab 1. To log in,
Choose user "pi" and the default password "raspberry". Here's what it looks like in Git Bash:
Expand the Filesystem
The image you installed was intentionally small. If you have a small SD card, it will fit. It also fits big ones! In order to maximize the space on your card, you need to use a command called raspi-config
.
pi@rasperrypi ~ $ sudo raspi-config
After typing the command, you'll get a screen with a menu. This is a tool that can do tons of things with your Pi. You may want to explore its options later, but for now we'll focus on the first one.
Choose the "Expand Filesystem" option. Follow the instructions, then exit raspi-config. Allow the Pi to reboot. After it reboots, log back in using SSH.
Change your Password
Once you're logged in, change your password! Pick a new password for the user "pi" that you will remember. Pick a good one, and launch sudo raspi-config
again. This time, choose the second option: "Change User Password". The system will hide the password as you type it in! This is for security; don't worry, when you press 'enter' it will have the password you typed in.
Change your Hostname
In raspi-config
, go into the "9 Advanced Options" section, then choose "A2 Hostname". You're going to change the name you call the Pi to <rhit username>-pi
. For example, if your Rose-Hulman username is stammsl, change the hostname to stammsl-pi
.
After you've done this, exit raspi-config and allow the pi to reboot.
Log back in. Since you changed the hostname, instead of using raspberrypi.local
to log into your pi, you will use <username>-pi.local
from now on.
SHOW YOUR INSTRUCTOR
Now is a great time to print out the instructor verification sheet and show your instructor.
Part 2: Practice with the Pi
Now it's time to play around with the pi through a terminal. When the pi is waiting for you to give it instructions, it'll show you a prompt. The prompt looks like this:
pi@raspberrypi ~ $
This means you are logged in as pi
on a computer called raspberrypi
and you are in the ~
directory (your home directory). The dollar sign ($
) is a visual indication for you to type something.
For the rest of this lab, you're going to use a number of linux commands. Here's a quick reference for some of them:
cd <dir>
: change directory. For example,cd foo
is like opening the folder "foo" and going inside.cd ..
goes back up a directory.ls
: show a list of the files in the current directorycat <file>
: display the contents of a file.
Stage 1: Update your Pi
In order to run things as an administrator (for example, to install programs), you need to use a command called
sudo
. This temporarily turns you into an admin called root. Try it!pi@raspberrypi ~ $ whoami pi pi@raspberrypi ~ $ sudo whoami root
To update the pi, first we want to install support for the CSSE update mirrors. This way you won't use your quota to install software. This is two commands: one to download the script, another to run it.
pi@raspberrypi ~ $ wget tiny.cc/cssepi ... pi@raspberrypi ~ $ bash cssepi ...
Once all the info is downloaded, you can install updates via
apt-get upgrade
. This will trigger download of software updates from the software mirror at Rose.pi@raspberrypi ~ $ sudo apt-get upgrade
Follow the instructions (if it gives you any).
Stage 2: Install a command-line web browser
Since your sole access to the pi is via command line, lets install a browser that works in a text-only environment! To do this, use apt-get.
pi@raspberrypi ~ $ sudo apt-get install links
It will ask you if it's ok to install stuff. Type "y" and hit enter.
Once it's installed, launch it and see if you can view the course website! (Hint: hit the "ESC" key to show menus and "q" to quit).
pi@raspberrypi ~ $ links http://www.rose-hulman.edu/class/csse/csse132/
Stage 3: Install subversion
Next, you need the subversion client so you can get your lab materials. Use apt-get to install it!
pi@raspberrypi ~ $ sudo apt-get install subversion
Stage 4: Check out your SVN repository!
The command below checks out your repo. Be sure to replace <username>
with your RHIT username.
pi@raspberrypi ~ $ svn --username <username> co http://svn.csse.rose-hulman.edu/repos/1516c-csse132-<username>
Once it's checked out, use the cd
command to go into the directory, and the ls
command to show your repository's contents.
pi@raspberrypi ~ $ cd 1516c-csse132-<username>/ pi@raspberrypi ~ $ ls lab01 lab02 lab03 pi@raspberrypi ~ $
SHOW YOUR INSTRUCTOR
Your instructor will want to check that you've gotten this far, so now is a great time to show your instructor.
Stage 5: Solve the mystery
Use cd
to navigate into your lab03
directory.
Once you're in there, use the ls
command to list that directory's contents.
You'll notice a file that you should read!
Read it using the cat
command and follow its instructions.
When you've solved the mystery, show it to your instructor and get checked off!
Finishing the Lab
Submit the electronic files you create to svn (from your Pi, using
svn add <file>
for each file.). In all of your files, be sure to include your name and your partner's name (for future labs).Submit the instructor verification sheet in hard copy.
Before you power down the Pi, be sure to tell it to shut down. To shut it down, type:
sudo shutdown now
...and hit enter.