Setting up a Raspberry Pi
Note
These instructions are obsolete: recent versions of Raspberry Pi OS are best installed with the burner tool that permits a login name and SSH access to be set up before first boot.Steps to set up a Raspberry Pi for ssh access on the local network, without ever needing to connect a keyboard or monitor to the Pi. These instructions were prepared using a Pi 1 model B and checked on a Pi 3, but other Pi's should be almost the same.
(These instructions require a Linux machine, so the first part is of no use to those with only a Windows machine; and if you have a Linux machine, you can use QEMU anyway and don't need a Pi. With a Windows machine, there are tools that will write the image to an SD card; then the VFAT boot partition will be visible to Windows, and you can enable ssh by creating a file on the boot partition, and initially at least work with a wired connection. Recent versions of Raspbian also allow you to configure the Wifi by creating a file on the boot partition that is copied to the root partition when the OS boots.)
- Download the Raspbian Stretch Lite image from https://downloads.raspberrypi.org/raspbian_lite_latest.
- Unzip the image on a Linux machine.
$ unzip 2017-03-02-raspbian-stretch-lite.zip $ rm 2017-03-02-raspbian-stretch-lite.zip
- Insert an SD card, then unmount it and copy the image across (substitute the device name of your card for
/dev/sdX
).
$ sudo umount /dev/sdX1 $ sudo dd if=2017-03-02-raspbian-stretch-lite.img of=/dev/sdX bs=4M
- Mount the two partitions of the SD card
$ mkdir boot root $ sudo mount /dev/sdX1 boot $ sudo mount /dev/sdX2 root
- Create an empty file
boot/ssh
$ sudo touch boot/ssh
- Edit: this is wrong, because Stretch encourages you to edit the config file for wpa_supplicant instead.
Edit a file withsudo nano root/etc/networks/interfaces
and change it to contain the following text (substitute your own WiFi details where shown).
# interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto lo iface lo inet loopback iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet manual wpa-ssid "........" wpa-psk "........"
- Better: use this for /boot/wpa_supplicant.conf
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="........" psk="........" }
- Unmount the two partitions, remove the SD card and put it in the Pi, and power up the Pi.
- I have a BT Home Hub that automatically resolves the names of nodes connected on the local network with DHCP, so that makes finding the Pi and logging in a bit easier. You might have to visit the router config page and look at the list of attached devices, then maybe use a numeric IP address.
$ ssh raspberrypi -l pi pi@raspberrypi's password: raspberry pi@raspberrypi:~ $
- Immediately change the password.
pi@raspberrypi:~ $ passwd Changing password for pi. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
- Update Linux
pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get upgrade
- Set the time zone
pi@raspberrypi:~ $ sudo dpkg-reconfigure tzdata
- Make an account in your own name
pi@raspberrypi:~ $ sudo adduser mike ... Enter new UNIX password: <password> Retype new UNIX password: <password> ...
- Allow yourself to use sudo
pi@raspberrypi:~ $ sudo addgroup mike sudo
- Change the hostname
pi@raspberrypi:~ $ sudo sed -i s/raspberrypi/omicron/ /etc/hosts /etc/hostname
- Reboot
pi@raspberrypi:~ $ sudo reboot
Now log in with ssh
as yourself.
$ ssh omicron
- Install needed software.
mike@omicron:~ $ sudo apt-get install mercurial tcl ocaml-nox
- Clone the Mercurial repository.
mike@omicron:~ $ hg clone http://spivey.oriel.ox.ac.uk/hg/compilers
- Build Keiko (not really needed for Lab 4) and the library modules.
mike@omicron:~ $ (cd compilers/keiko; make) mike@omicron:~ $ (cd compilers/lib; make)
- Build Lab 4.
mike@omicron:~/compilers/keiko $ cd compilers/lab4 mike@omicron:~/compilers/lab4 $ make mike@omicron:~/compilers/lab4 $ make pas0.o
- Run the tests.
mike@omicron:~/compilers/lab4 $ make test1
An alternative
- Get a Pi Zero (or Zero W) and follow the instructions here: https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a
- Further config info is here: https://gist.github.com/lurch/ad939bbce48064cffdb215268eac9f62
- Another helpful page: http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget