Setup your Raspberry Pi 4 - without an external monitor

Gaurav Gahlot - Dec 20 '21 - - Dev Community

I received my first Raspberry Pi yesterday. I have got a Raspberry Pi 4 Model B with 8GB 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.

Note: 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:



bootcode.bin
loader.bin
start.elf
kernel.img
cmdline.txt


Enter fullscreen mode Exit fullscreen mode

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:



country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant

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


Enter fullscreen mode Exit fullscreen mode

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:

IP Scanner

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



# username - pi
# password - raspberry

➜ ssh pi@192.168.0.232
pi@192.168.0.232'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:~ $


Enter fullscreen mode Exit fullscreen mode

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



# change the password
$ passwd

# get updates
$ sudo apt update

# upgrade the system
$ sudo apt upgrade


Enter fullscreen mode Exit fullscreen mode

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:



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>                              │
│                                                                                                            │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


Enter fullscreen mode Exit fullscreen mode

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:



sudo apt install realvnc-vnc-server


Enter fullscreen mode Exit fullscreen mode

Start the VNC server using the vncserver command:



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)


Enter fullscreen mode Exit fullscreen mode

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.

Note: 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.

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:



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


Enter fullscreen mode Exit fullscreen mode

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:



$ 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


Enter fullscreen mode Exit fullscreen mode

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



sudo usermod -aG docker $USER
sudo reboot


Enter fullscreen mode Exit fullscreen mode

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



$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Enter fullscreen mode Exit fullscreen mode




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 containerise 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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .