Our step-by-step guide to prepare a lean yet versatile SD card image based on Raspberry Pi OS Lite.
Learn how we at reelyActive prepare a SD card image for a headless Pi.
Download the latest version of Raspberry Pi OS Lite and flash it to an SD card with Etcher.
We'll flash the SD card with Etcher, a friendly open source tool that you can download here.
From the computer with which you intend to flash the SD card :
You should now have a file entitled 20xx-xx-xx-raspios-bullseye-armhf-lite.img on your computer . Let's flash!
We recommend using micro SD cards from reputable vendors of at least 4GB size.
From the computer with which you intend to flash the SD card :
Proceed to the next step once the SD card is flashed and verified.
Configure Raspberry Pi OS before the first boot on the Pi, ensuring a painless initial connection.
Following the flashing of the SD card in the previous step, the computer should automatically mount two partitions: boot and rootfs. We'll make minor changes to each partition as follows.
If the partitions aren't automatically mounted, eject the SD card and then re-insert into the computer .
Open a terminal and browse to the root of the bootfs partition (ex: cd /media/user/bootfs/
), then:
sudo touch ./ssh
net.ifnames=0
This will allow us to SSH into the Pi on the first boot, and will use predictable network interface names (ex: eth0, wlan0) which we'll need for Part 3.
As of April 2022, Raspberry Pi OS no longer ships with a default username & password!
From the same terminal in the root of the bootfs partition (ex: /media/user/bootfs/
):
sudo nano userconf
) pi:$6$XW.DLlBAlSF1wtdM$qpqLFBieq0toz9JviJm4.RvBjGN4yaxtrpcXMn8XdDa48.w7Ji6GeP.BWyhfae0NY074GmVMItEy9kNPdPaSz.
This will set the default username to pi with password berryinsecure (encrypted above), which will be required when SSHing into the Pi in Step 3—and you can change it to a less-insecure password in that step too!
Open a terminal and browse to the root of the rootfs partition (ex: cd /media/user/rootfs/
). Edit the /etc/dhcpcd.conf file to include the following (simply append or uncomment and edit):
# It is possible to fall back to a static IP if DHCP fails: # define static profile profile static_eth0 static ip_address=10.0.50.100/24 static routers=10.0.50.1 static domain_name_servers=10.0.50.1 # fallback to static profile on eth0 interface eth0 fallback static_eth0
This will ensure that the Pi boots with the static Ethernet address of 10.0.50.100 in the absence of DHCP, as will be the case, and will prove helpful on any occasion where it is necessary to directly connect to the Pi over Ethernet, as in the following step.
Unmount both partitions and eject the SD card which is now ready to find its way into the Pi.
Boot the Pi for the first time and SSH in via Ethernet to run raspi-config.
The SD card should only be inserted into (or removed from) the Pi when it is disconnected from power.
With the SD card inserted into the Pi, complete the following:
ssh pi@10.0.50.100
and, when prompted, enter the password berryinsecure (before April 2022, the default password was raspberry) Now that you're logged in to the Pi, it is possible to execute commands such as raspi-config.
From the command prompt on the Pi , enter the command sudo raspi-config
which will open a text-based menu.
Update the configuration as per the following table where the settings are indicated in [ ].
# | Option | Action(s) |
---|---|---|
1 | System Options |
S1 Wireless LAN
*adjust as per your region and local WiFi network |
1 | System Options |
S3 Password* [berryinsecure] *this is a good time to choose something less insecure |
3 | Interface Options |
I6 Serial Port
|
5 | Localisation Options |
L2 Change Timezone* [America | Montreal] *adjust as per your region (reelyActive is "Made in Montréal") |
6 | Advanced Options | A1 Expand Filesystem [Select] |
Upon completing the above, select <Finish> and select <Yes> when prompted to reboot. If you entered valid WiFi settings, the Pi should connect to this network automatically, which will be required for the next step.
SSH into the Pi over WiFi and configure its Ethernet DHCP server to facilitate future direct connections.
The Pi should have rebooted from the previous step and connected to both the local WiFi network and again to the computer connected directly via Ethernet .
With the Pi still connected to the computer via Ethernet , and from the same terminal window as before:
ssh pi@10.0.50.100
, using the new password (or berryinsecure if you didn't change it) ifconfig
. It will be the inet value under wlan0 (ex: 192.168.0.123) exit
ssh pi@xxx.xxx.xxx.xxx
, replacing the x values with the Pi's WiFi IP address. The computer is now connected to the Pi over WiFi .
Be sure to disconnect the network cable between the two, else they may ignore their Internet connection over WiFi, instead selecting Ethernet as their default gateway.
From the same terminal connected to the Pi via SSH over WiFi :
sudo apt-get install dnsmasq
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.default
sudo nano /etc/dnsmasq.conf
then paste in the following two lines and save:
interface=eth0 dhcp-range=10.0.50.2,10.0.50.99,255.255.255.0,12h
sudo service dnsmasq restart
The Pi will now behave as follows on Ethernet connection:
External DHCP? | Behaviour of the Raspberry Pi |
---|---|
Yes | The Pi will accept the DHCP-assigned IP address |
No | The Pi will fallback to static IP address 10.0.50.100 and it will assign IP addresses in the range 10.0.50.2-99 to any connected devices |
The core configuration of the Pi is now complete. On to the software!
Install all the prerequisites to run Node.js programs such as our Pareto Anywhere middleware.
To simplify installing and updating Node.js, the NodeSource binary distributions will be used. From the same terminal connected to the Pi via SSH over WiFi :
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install -y nodejs
1 min Confirm that node and npm are successfully installed with the commands node --version
and npm --version
respectively.
*it is recommended to specify the current LTS version as indicated on nodejs.org
Since the latest release of Raspberry Pi OS Lite, there are inevitably newer versions of some of the packages available. From the same terminal connected to the Pi via SSH over WiFi :
sudo apt-get update
1 min sudo apt-get upgrade
5 mins+ sudo apt-get install git
All software packages are now installed and at the latest version. The Pi is prepared for the (optional) installation of Pareto Anywhere, which is the subject of the next tutorial:
Tutorial prepared with ♥ by jeffyactive.
You can reelyActive's open source efforts directly by contributing code & docs, collectively by sharing across your network, and commercially through our packages.Continue exploring our open architecture and all its applications.