"It's a dangerous business, Frodo, going out of your door. You step into the road, and if you don't keep your feet, there is no knowing where you might be swept off to."
—Bilbo, The Fellowship of the Ring by J. R. R. Tolkien, Book 1, Chapter 3
The aim of this studio to to set up your Raspberry Pi. We understand that your situation may be unique this semester, so this studio will be structured a little differently than others. We understand that you may or may not have access to a monitor, keyboard, and mouse, so we will provide optional instructions for headless setup of your Raspberry Pi, so you can access and control it from a laptop or desktop. Throughout this studio, we will be providing variant instructions based on the equipment and networks you have access to. In many places, you will be prompted to click on a header, which will expand the instructions relevant to your situation.
In this studio, you will:
Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete. We encourage you to please work in groups of 2 or 3 people on each studio (and the groups are allowed to change from studio to studio) though if you would prefer to complete any studio by yourself that is allowed.
As you work through these exercises, please record your answers, and when finished upload them along with the relevant source code to the appropriate spot on Canvas. If you work in a group with other people, only one of you should please upload the answers (and any other files requested) for the studio, and if you need to resubmit (e.g., if a studio were to be marked incomplete when we grade it) the same person who submitted the studio originally should please do that.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
As the answer to the first exercise, list the names of the (ideally 2 or 3) people who have worked together on this studio.
We would like to get a sense of which Raspberry Pi model each person is using this semester. As the answer to this exercise, please list, for each person in your group, the Raspberry Pi model (e.g. Model 3B+, Model 4B) that you have obtained for this class. We understand that you may be sharing a single Raspberry Pi among multiple people, and so there may be one or more group members who do not yet have a Raspberry Pi.
To start, you need to assemble your Raspberry Pi.
If you have the recommended starter kit from Canakit, watching the video that you can find in the course's Canvas site on the "Setting up your Raspberry Pi" page of the "Intro to Linux and the Raspberry Pi" module before you start may help you with the assembly. To avoid problems: make sure you put the Raspberry Pi card into the protective case, before you install the heat sinks and MicroSD card that were provided in the kit (this helps with their alignment, and also avoids potential issues with damage to them or shearing them off as you're putting the card into the case).
If you have another starter kit, please refer to the included instructions (if available) for setup.
As the answer to this exercise, please let us know which Raspberry Pi kit you are using, and whether or not you ran into any surprises, concerns, questions, or issues during the assembly, and if you did what those were.
Now you are ready to set up and install the Raspberry Pi OS.
First, please specify how you will connect your Raspberry Pi to a network:
Next, please specify how you will set up your Raspberry Pi:
Then, please select the OS you are using on your laptop or desktop:
To prevent inconsistencies in Linux distributions and software versions that may arise from purchased or borrowed Raspberry Pi devices set up at different times, you should download and use a specific Raspberry Pi image as your starting point. To do so:
Insert the MicroSD card into the USB adapter, and connect it to a USB port on your laptop or desktop computer.
Download, install, and run the latest version of the Raspberry Pi Imager:
Download the Raspberry Pi image we will be using:
Once it has downloaded, extract the .zip file to reveal the .img file containing the Raspberry Pi image.
Warning: This is a 1.2GB zip file and expands to be almost 4GB. The download and extraction may take a while.
Run the Raspberry Pi Imager, then proceed with the following steps:
Select CHOOSE OS, then select "Use custom" (this may be the last option in the list). Select the .img you extracted in the previous step.
Now, select CHOOSE SD CARD, and select the MicroSD card that you inserted. Make sure you select the correct card, as this will delete all existing data on the device!
Next, enter the advanced settings menu (the gear icon, or in the Windows installer you can get it via shortcut ctrl+shift+x).
If you are not using your own router, you may want to change your hostname from the
default raspberrypi
to something unique so that it does not
conflict with others in the course. For example, choose a hostname that contains your username.
Check "Enable SSH" and select "Use password authentication."
Set a username and password. You can use the default username (pi
) if you like,
but to help avoid having your Raspberry Pi recruited into an evil bot swarm (or
other undesirable and unauthorized use), type in (and re-enter to confirm) a suitably
strong new password. Record it somewhere so you don't forget!
Check "Set locale settings," select a timezone as appropriate to your location (e.g. in St. Louis, you will use America/Chicago), and select "us" as the keyboard layout.
Click "Save"
Finally, click WRITE. Once the write has completed, you will see a message box titled "Write Successful."
Now, unmount the volume and insert the MicroSD card into the Raspberry Pi, then turn it on.
Once it powers up completely (which could take a few minutes the first time), you will need to connect to it via SSH. Issue a command of the form ssh <username>@<hostname>
, where you replace <username>
and <hostname>
with the username and hostname you set during the imaging process (e.g., ssh piuser@pihost
). Enter the password you specified during the imaging process.
Depending on your router's DHCP and DNS settings, the hostname may not resolve. In that case, you will have to look at your router settings to see the list of connected devices, then connect to your Raspberry Pi via the IP address assigned by your router.
As the answer to this exercise, please tell us the hostname that you set during the imaging process.
Now, you are ready to configure location and user settings for your Raspberry Pi.
When your Raspberry Pi first logs in, you will see a setup wizard titled "Welcome to the Raspberry Pi." Click Next.
On the Set Country screen, use the following options:
At this point, even though you've already set a password using the Raspberry Pi imager, you may be prompted to enter a new password. At this point, you can close the setup screen. To prevent the screen from reappearing each time you log in, open a terminal window, then issue the following command:
sudo apt purge piwiz
Next, upgrade the software and drivers on your Raspberry Pi. Run the following commands:
sudo apt-get update
sudo apt-get upgrade
This may take several minutes to complete. Once done, reboot your Raspberry Pi.
Once you have successfully installed and booted the Raspberry Pi OS, and can see the desktop, please tell us briefly about your setup as the answer to this exercise. For example, are you using Washington University's WiFi network, or your home WiFi? Do you have a monitor, keyboard, and mouse connected, or did you perform a headless setup? If headless, are you connecting with SSH, RealVNC, or through another method? And, if headless, what operating system are you using on the computer that connects to the Raspberry Pi?
We will now look at network settings on your Raspberry Pi.
Open up a terminal window on your Raspberry Pi, and in it enter the command
ifconfig wlan0
and note the MAC address that appears after the word ether
. The MAC address should consist of six hexadecimal numbers separated by colons, like 00:00:00:00:00:00
(but with values from 0
to 9
and a
through f
for the digits).
Once you have done that, in the terminal window on your Pi enter the command
hostname -I
and note the IP address that appears.
As the answer to this exercise, give both the MAC address and the IP address for your Raspberry Pi.
Finally, we need to transfer our recently compiled kernel and modules that we built in the previous studio to our Raspberry Pi in order to install them.
To make the transfer process faster, you will first need to compress the files that you will be retrieving.
Use ssh to connect to shell.cec.wustl.edu
.
Then, navigate to the directory where you compiled the Linux kernel with:
cd /project/scratch01/compile/"your username"/linux_source
Next, create two archives with the following commands:
tar -C modules/lib -czf modules.tgz modules
tar -C linux/arch/arm -czf boot.tgz boot
Now, open a local terminal on your Pi.
Alternatively, in this and all future assignments, you may use SSH to run terminal commands on your your Raspberry Pi. Optionally, if you generated an SSH key to connect to the school's servers in the previous studio, you may want to use the same key to connect to your Raspberry Pi. The installation steps outlined after generating the key in our SSH key instructions should help you to do so.
Create a directory called linux_source
that will
serve as a place to organize your code. (Note: this does not need to be created
under /project/scratch01/compile
, as only you will be running a kernel on your Pi.) Move
inside your linux_source
directory and
run the following commands:
sftp [your wustl key]@shell.cec.wustl.edu
cd /project/scratch01/compile/"your username"
cd linux_source
get modules.tgz
get boot.tgz
quit
(to get back to your Pi)
Back up your directories /usr/lib/modules
and /boot
, because you will
be modifiying their contents. To do this, we used
sudo cp -r /usr/lib/modules ~/Desktop/modules_backup
and a similar
command for /boot
.
Note that on some versions of Linux,
/lib
may be a directory rather than a symbolic link to
/usr/lib
. In that case, please use
sudo cp -r /lib/modules ~/Desktop/lib_backup
to back up that directory instead.
You should still be in
your linux_source
directory (if not, navigate there).
Once you have backed up the /usr/lib/modules
and /boot
directories, run the following commands to install the kernel you built:
tar -xzf modules.tgz
tar -xzf boot.tgz
cd modules
sudo cp -rd * /usr/lib/modules
(or sudo cp -rd * /lib/modules
if /usr/lib
does not exist)
cd ..
sudo cp boot/dts/*.dtb /boot/
sudo cp boot/dts/overlays/*.dtb* /boot/overlays
sudo cp boot/dts/overlays/README /boot/overlays
Finally, if you are using a Raspberry Pi 3B+, run the command:
sudo cp boot/zImage /boot/kernel7.img
If you are using a Raspberry Pi 4 or 4B, run the command:
sudo cp boot/zImage /boot/kernel7l.img
At this point, your new kernel is installed. When you reboot, you'll be running your very own, custom kernel.
Go ahead and reboot now. If everything went OK,
the new system should look and feel the same as before. You can verify
that your new kernel is running with the command uname -a
.
In particular, the build date should be today, the version string should
include the local version string you specifed during configuration, and
your Linux source code version (as well as the characters "PREEMPT")
should appear.
On some Raspberry Pi hardware, particularly the new 4Bs, the firmware
defaults to booting into a 64bit kernel rather than into the 32 bit kernel
you have built. If you do not see the local version string you
specified when you run uname -a
, add the following line
at the bottom of the /boot/config.txt
file on your Raspberry Pi (e.g., in the [pi4]
section just above the last line that says [all]
):
arm_64bit=0
then reboot your Pi, and run uname -a
which should show
the local version string you specified, indicating the kernel you built
is now running.
As the answer to this exercise, give the output that was just produced by
running uname -a
for the new kernel.
At this point, you should consider how to back up copies of your work on other machines (possibly using svn, git, or another repository service, use multiple Raspberry Pi machines within your group for redundancy, etc. Starting with the next week's exercises, we will be making substantial changes to code that you will need to manage effectively even if your Raspberry Pi should freeze up, lock you out, etc.
For this studio, please turn in the following:
Be careful with some of the commands described on that site, as they can remove accounts, etc. which can leave you without a way to get into your Raspberry Pi (forcing you to start all over by re-imaging your MicroSD card, etc.)
As the answer to this exercise, describe what you did and what you saw when you did that.
Page updated Wednesday, January 25, 2023, by Marion Sudvarg, James Orr, and Chris Gill.