Introduction
This is a guide for installing Ubuntu Server on a Raspberry Pi Zero 2 W via a headless setup using the Raspberry Pi Imager and another computer running Linux.
Many of the steps are outlined in the Raspberry Pi Foundation’s Documentation in the Getting Started Guide.
There are a few additional steps and helpful details that this guide is intended to provide for a smooth setup.
Parts for the Pi
There are several necessary components:
-
5V power supply that provides at least 2.5A
- I prefer a power supply with a switch - at least for setup and testing - since the Pi Zero doesn’t have one.
-
micro SD card with between 16GB and 256GB capacity
- If using an older card it’s also relevant to consider the speed of the card.
-
Another computer for building the OS image and completing headless setup.
-
A case isn’t strictly necessary, but it is helpful to keep the Pi protected.
- I found this clear case useful for this project.
Building the OS image for the Pi
The next step is to install the desired operating system (OS) image on bootable media.
The Raspberry Pi Imager is very helpful for creating a bootable OS image and configuring it for a headless setup.
On Ubuntu, the Raspberry Pi Imager can be installed with:
sudo apt install rpi-imager
Once the Imager is installed, open it and select the following settings (or substitute your own):
Operating System
CHOOSE OS > Other general-purpose OS > Ubuntu > Ubuntu Server 22.04.3 LTS (64-bit)
Note:
- The latest Long Term Support (LTS) release makes the most sense for this project.
- The Raspberry Pi Zero 2 W is a 64-bit system.
Storage
CHOSE STORAGE > {Select the appropriate SD card}
Note: Take care to select the correct storage as whatever drive you select will be completely overwritten and all data erased.
Advanced Options (Gear Icon in the lower right)
Select and fill the following fields:
☑️ Set hostname: {DESIRED_DEVICE_NAME}
☑️ Enable SSH
🔘 Use password authentication
☑️ Set username and password
- Username: {DESIRED_ACCOUNT_NAME}
- Password: {DESIRED_ACCOUNT_PASSWORD}
☑️ Configure wireless LAN
- SSID: {WIFI_SSID}
- Password: {WIFI_PASSWORD}
- Wireless LAN country: {COUNTRY_WHERE_THE_PI_IS_LOCATED}
Note: This must be a 2.4GHz WiFi network for the Pi to connect with it.
☑️ Set locale settings
- Time zone: {TIMEZONE}
- Keyboard layout: {KEYBOARD_LAYOUT}
Click SAVE.
Review the information and build the OS image
Once you have entered and confirmed all the above information, click WRITE.
If you are sure you have selected the correct media and settings, click YES.
Wait for the writing and verification steps to complete.
Read the system message to confirm succesful OS image writing. If there was an error, repeat the imaging steps.
Assembling the Pi
Assembling the Pi is straightforward:
- Insert the micro SD card.
- Place the Pi in the case.
- Plug the power supply into the correct micro USB port.
Powering the Pi
To turn it on, you only need to supply power.
- If you have a power supply with a switch, plug it in and flip the switch to on.
- If you have a power supply without a switch, just plug it in.
Give the Pi a few minutes to boot.
Connect to the Pi over the Local Network
Connecting to the Pi can involve a few steps:
- Identify the IP address of the Pi.
- Connect to the Pi over SSH.
Identify the IP address of the Pi
Identifying the IP address of the Pi can be accomplished in several ways.
For instance, you can log in to your router and search through the WiFi-connected devices.
Another approach is to use another computer to search your WiFi network for the device. We’ll look at that approach here.
First, identify the IP address of the computer you’ll use to conduct the search by running the ip
command:
ip -brief address
Look for addresses identified as ‘UP’ and identify which is the IP address of your search computer.
For this example, let’s say the address is 192.168.0.6.
Next, use the nmap command and the IP address you just found to search the network for other connected devices.
sudo nmap -sn 192.168.0.6/24
From the list that nmap generates, identify the IP address for the Pi.
Connect to the Pi over SSH
Now, we can use SSH to connect to the Pi.
The command uses the form ssh {username}@{ip-address}
, so for a user of pi and an IP address of 192.168.0.12 we’d enter the following:
ssh pi@192.168.0.12
During your first login to a host, you’ll see a warning message:
The authenticity of host ‘192.168.0.12 (192.168.0.12)’ can’t be established.
…
Are you sure you want to continue connecting?
If you believe you have connected to the correct device, type ‘yes’ and press Enter.
When prompted, enter the password you assigned for the account.
You should be greeted with a welcome message:
Welcome to Ubuntu 22.04.3 LTS
Updating the Pi
Once you have connected to the Pi, finalize the setup by updating the system:
sudo apt update && sudo apt upgrade && sudo apt autoremove
Confirm the update completed successfully.
Afterward, you will likely need to reboot to apply all changes:
sudo shutdown --reboot now
Conclusion
With the above steps completed, the Raspberry Pi Zero 2 W is ready for use.