Contents

Setup your Raspberry Pi 4 - without an external monitor

The blog post defines the steps to setup a brand new Raspberry Pi 4 Model B without an external monitor attached to the Pi.

I received my first Raspberry Pi yesterday. I have got a Raspberry Pi 4 Model B with 8 GB RAM. As I was doing the setup, I found it difficult to get all the information in one place, so I decided to write this blog post. This post documents the steps to setup a brand new Raspberry Pi without an external monitor.

Here is what we are going to do:

We have quite a lot to cover, so let’s get started.

Prerequisites

Following are some prerequisites for the setup:

  • Raspberry Pi board (obviously)
  • connector for power supply
  • microSD card (depends on your Pi model though) and a card reader
  • another system to do the work (on the same network)
  • SSID (network name)
  • PSK (network password)

Installing Raspberry Pi OS

The very first thing you need for the setup is the Raspberry Pi Imager. Raspberry Pi Imager is the quick and easy way to install Raspberry Pi OS and other operating systems to a microSD card, ready to use with your Raspberry Pi. The imager provides a wide range of stable operating systems. However, they are all 32-bit (I think). You can very well choose either one and move forward.

Since the Raspberry Pi 4 supports 64-bit OS, I will be installing the 64-bit Raspberry Pi OS. You can download the same from here. Please note that it’s still in beta testing and a list of known issues can be found on the same forum.

Follow the steps below to install the OS:

  • Connect your microSD card to the system where you have downloaded the OS and imager.
  • In the imager select the Choose OS option.
  • Scroll down the pop-up list and select Use custom at the end.
  • Select the downloaded OS (.zip file)
  • Now select Choose Storage and select the connected SD card.
  • Click Write and wait for the process to complete.
Choosing an OS
If you choose an OS from the recommended list, it will first download the OS and then write it to the SD card. This will take a little longer, so be patient.

Setup Wifi

Now that we have installed the OS, it’s time to setup the network.

Open the SD card in a file manager of your choosing. If you are using a Windows based system, the SD card will directly land you in the boot directory. You can double check it by looking for these files:

1
2
3
4
5
bootcode.bin
loader.bin
start.elf
kernel.img
cmdline.txt

Create a file named wpa_supplicant.conf next to the above files, i.e., in the boot directory.

However, if you are on a Linux based system you need to create the file as /etc/wpa_supplicant/wpa_supplicant.conf. Now, add the following content to your file:

1
2
3
4
5
6
7
8
9
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
  scan_ssid=1
  ssid="network_SSID_here"
  psk="network_password_here"
}

Save the file and ensure that the file extension is .conf. Insert the SD in the slot of the Pi board, connect the power and turn it on. As the Pi boots you should see the blinking green and red lights. Once the boot is complete the green light will turn off.

SSH and Run Updates

Now, it’s time to find the IP address of your Raspberry Pi. There are multiple ways to scan a network and get connected devices. In order to make it easy you can use an IP Scanner. This article provides a good list of scanners that you can choose from. Select and install one.

Scan your network and you should see a Raspberry Pi device connected. Here is an example:

/setup-raspberry-pi-without-a-monitor/ip-scanner.png
IP Scanner

Note the IP address. Let’s SSH into the Pi with default credentials.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# username - pi
# password - raspberry

➜ ssh [email protected]
[email protected]'s password:
Linux raspberrypi 5.10.63-v8+ #1488 SMP PREEMPT Thu Nov 18 16:16:16 GMT 2021 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Dec  4 00:43:28 2021 from 192.168.0.233
pi@raspberrypi:~ $

Here are a few things you should do as you login:

1
2
3
4
5
6
7
8
# change the password
$ passwd

# get updates
$ sudo apt update

# upgrade the system
$ sudo apt upgrade

The Raspberry Pi OS also provides a configuration manager that you can start using the sudo raspi-config command. It will prompt you with the following or similar term-UI:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
Raspberry Pi 4 Model B Rev 1.4


┌────────────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├─────────────────────────┐
│                                                                                                            │
│                      1 System Options       Configure system settings                                      │
│                      2 Display Options      Configure display settings                                     │
│                      3 Interface Options    Configure connections to peripherals                           │
│                      4 Performance Options  Configure performance settings                                 │
│                      5 Localisation Options Configure language and regional settings                       │
│                      6 Advanced Options     Configure advanced settings                                    │
│                      8 Update               Update this tool to the latest version                         │
│                      9 About raspi-config   Information about this configuration tool                      │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                               <Select>                               <Finish>                              │
│                                                                                                            │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Setup VNC Viewer

Honestly, you don’t really need a GUI to work with a Raspberry Pi. But it can be useful at times, especially if you are a beginner. Let’s setup VNC viewer just for that.

On your Pi, install the realvnc server:

1
sudo apt install realvnc-vnc-server

Start the VNC server using the vncserver command:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
vncserver

...

Running applications in /etc/vnc/xstartup

VNC Server catchphrase: "Needle baker salute. Price diagram origin."
             signature: e4-20-40-65-48-3d-f7-51

Log file is /home/pi/.vnc/raspberrypi:1.log
New desktop is raspberrypi:1 (192.168.0.232:1)

Notice the last line that provides details about how you can connect to the desktop started by the server.

Now install the VNC Viewer (also know as VNC client) on the system you want to have the display on. Once installed, start the client and use the desktop address you got from the VNC server (192.168.0.232:1 in my case). When prompted, provide the Raspberry Pi user credentials you used to SSH into the Pi.

Set VNC interface to be enabled by default
With this setup, each time you want to access the GUI you will need to SSH and start the server manually. You can enable the VNC interface by default from the configuration manager (raspi-config) -> Interface Options -> VNC -> Enabled setting.

/setup-raspberry-pi-without-a-monitor/vnc-viewer.png
VNC Viewer

Congratulations! You have successfully setup your Raspberry Pi. 🎉 🥳

Install Docker

Installing Docker on Raspberry Pi 4 is super simple. All you need is to run the following command that gets a script and pipes it to the shell:

1
curl -sSL https://get.docker.com/ | sh

By default, Docker daemon runs a privileged service and a non-privileged user can’t connect with it without using sudo. Meaning, if you try executing docker ps command you would get the following error message:

1
2
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

In order fix this we need to add the pi user to the docker group. Once done, reboot the Pi.

1
2
sudo usermod -aG docker $USER
sudo reboot

SSH again and try executing the docker ps command w/o sudo and you should not get any errors.

1
2
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Conclusion

In this blog post, we have setup a Raspberry Pi 4 Model B from scratch without an external monitor connected to the Pi. We have also installed Docker and so, the Pi is all set to get you rocking on a new journey. In the next post, we will setup Rust and write our first application. Later we will containerize the application and run it on the Raspberry Pi. So, stay tuned.

I hope you found the steps useful and I look forward to your valuable feedback. If you run into issue, please do let me know and I will be happy to help.