"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:
Please note that Washington University's WiFi network uses additional authentication measures that make a headless setup very difficult. It requires you to boot your Raspberry Pi before connecting it to the network. As such, please consider doing the standard setup with monitor, keyboard, and mouse. If this is not an option for you, please let your instructors know.
The headless setup allows you to configure your Raspberry Pi without a monitor, keyboard, or mouse. You will use your existing laptop or desktop to write an OS image to your Raspberry Pi's MicroSD card, then write additional files to connect it to your wireless network and enable SSH. From there, you will be able to boot your Raspberry Pi, and connect to it from your laptop or desktop. At this time, we are providing instructions for Windows, MacOS, and Ubuntu Linux (Desktop version 20.04).
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:
If you are using Ubuntu, you may download the .deb package
If the .deb package fails to install, you may issue the following command instead:
sudo snap install rpi-imager
You can run the installed package by issuing the command:
If you receive the error:
mkdir: cannot create directory 'run/user/0' then run the following commands:
sudo mkdir 0
sudo chmod 0700 0
If you receive an error like:
Could not connect to any X display
then run the following command:
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
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!
To allow your Raspberry Pi to automatically connect to your WiFi network, check "Configure wireless LAN," enter the network name as the SSID, then the network password.
Be sure to enter the appropriate wireless LAN country code (e.g., US if you are in the United States).
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.
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 the command
ssh pi@hostname, where you replace
hostname with the hostname you set during the imaging process. 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 a last step, you will need to configure your Raspberry Pi so that you can interract with its desktop environment from your laptop or desktop. You will need to enable VNC on the Raspberry Pi, then install a VNC viewer on your computer.
Issue the following command to your Raspberry Pi via the SSH connection:
You will see a menu with several options.
You will use the Raspberry Pi's desktop environment to set several of these options.
For now, select
3 Interface Options, then
Yes to enable the VNC server.
Finish to exit the configuration menu.
Now, you will be able to connect to your Raspberry Pi's desktop environment by using a su viewer. We recommend the RealVNC Viewer, which is free and has versions for several operating systems, including Windows, MacOS, and Linux. Depending on your system, you may need to run the installation package as an administrator or root user. If not, the installer may not progress past 0%.
Once you have downloaded and installed the VNC Viewer, enter the hostname or IP address for the Raspberry Pi into the search bar, then press enter. You will be prompted for a username and password to connect to the Raspberry Pi. This is the same username and password used for SSH, which are
raspberry by default.
Note that if you run into problems later (e.g., when trying the optional enrichment exercise) and are completely shut out of your Raspberry Pi, you can re-image it by shutting it down, removing the MicroSD card, then repeating the prior steps. This will destroy the image that was already there, but gives you a way to recover to this initial starting point.
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.
If you are connected with VNC, you may notice that the screen resolution is extremely small. Click the Display tab, then click Set Resolution. Select a resolution as appropriate for your monitor, then click OK (or simply close the window with the "x" in the top corner of the menu, if the resolution is so low that the OK button is off the screen).
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.
Select an appropriate WiFi network, then enter the password to connect.
Open up a terminal window on your Raspberry Pi, and in it enter the command
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
f for the digits).
We will now set up wireless networking so that you can access the internet from your Raspberry Pi on Washington University's WiFi network.
In a browser on a windows machine in the lab, visit the university's https://selfservices.ip.wustl.edu web page, and underneath the User Registration heading please fill in the fields with your Pi's MAC address, your WUSTL Key id and password, and your first and last name. Then, click on the register button at the bottom of that page and wait until it updates with a message saying that the registration was successful.
Then, on your Raspberry Pi, please click on the wireless networking icon to the upper right on its desktop, and select the wustl-2.0 network from the list that should appear (possily after a brief wait). If prompted to do so, enter your WUSTL Key id and password, and once you are connected to the network, click on the browser icon that's next to the raspberry icon on the top left of your desktop, to open up a browser. Enter the URL of the home page for this course, https://classes.engineering.wustl.edu/cse422/ and confirm the page loads.
Once you have done that, in the terminal window on your Pi enter the command
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
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
/project/scratch01/compile, as only you will be running a kernel on your Pi.) Move
linux_source directory and
run the following commands:
sftp [your wustl key]@shell.cec.wustl.edu
cd /project/scratch01/compile/"your username"
quit (to get back to your Pi)
Back up your directories
/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
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
directories, run the following commands to install the kernel you built:
tar -xzf modules.tgz
tar -xzf boot.tgz
sudo cp -rd * /usr/lib/modules (or
sudo cp -rd * /lib/modules if
/usr/lib does not exist)
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
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")
As the answer to this exercise, give the output that was just produced by
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.