I’ll explain here the basic configuration I use on my Debian raspberrys when I use them with Jeedom automation system. We just need a raspberry pi zero, an SD Card (I use 16Gb ones, you can use a smaller one), a 1.5A USB power supply, and a Windows computer in order to download & burn the Raspbian image file on our SD Card. Installing Jeedom is out of scope of this article, but we already discussed it in a previous article (not on a Raspberry though but on a VM).
Get the raspbian image
We need to download & install Win32diskimager and then download the raspbian lite image (lighter, no graphical environment). Unzip the image somewhere you will easily find it.
Next, open Win32diskimager, tell it to use your raspbian unpacked image file with the button” Image file” and in “Device” select your SD card. Please take care to choose the right device, as it will overwrite everything ! Then click on “Write” and have a coffee.
When the operation will be done, a Windows popup asking you to format a drive will appear, this is normal, one of the two filesystems wrote on the SDCard is not recognized by Windows, as it is a Linux EXT partition. You should also see a new drive in your Explorer, called “boot”, this is also normal.
Configure the Wifi before we boot on the SD Card
We could configure the Wifi on the raspberry after booting on it, but it would require you to plug it on an external display to configure it. Fortunately, we can set it up before, just by puting a file on the “boot” partition, and this file will be used by wpa_supplicant, the software used for Wifi connectivity.
Create a text file containing the code below, and save it as ‘wpa_supplicant.conf’ at the root of your “boot” drive, on the SD Card. You may need to adjust your country code on the first line.
country=FR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="My SSID"
psk=My un-encrypted passphrase
scan_ssid=1
With the latest Buster Raspbian release, you must ensure that the file contains the three first lines at the top.
Also, if you are using a hidden network, the extra option scan_ssid, may help connection.
About the passphrase: the password can be configured either as the ASCII representation, by using quotes as per the example above, or as a pre-encrypted 32 byte hexadecimal number. You can use the wpa_passphrase utility (with another Linux box) to generate an encrypted PSK. It takes the SSID and the passphrase as as inputs, and generates the encrypted (hashed actually) PSK. With the example from above, you can generate the encrypted PSK with the following command:
wpa_passphrase your_SSID your_un-encrypted_SSID_passphrase
network={
ssid="your_SSID"
#psk="your_un-encrypted_SSID_passphrase"
psk=28d0eca5ddde6c3f53331833547dfa68eb732030f5a48b8b499ab2600015d4be
Configure the SSH server before we boot on the SD Card
Same technic will be applied here: simply create an empty file called ‘ssh’ at the root of yout “boot” drive, on the SD Card. No extension needed.
You can now remove the SD Card from your Windows computer and insert it in your Raspberry.
Boot the Raspberry and connect to it
Now, insert the SD Card in your Raspberry, and plug the USB power. The green light should light a few times until it stabilizes to full color. If your Wifi file is OK (network name & passphrase) you should see it connecting on your network. To check his IP, you have to connect on your Wifi router and refresh a few times the list of connected devices to visually detect the new device.
On your Wifi router, or whatever the component on your network acting as a DHCP server, I strongly recommand to assign a static IP to your raspberry so that it will be much more easier to administrate it later, and configure it in Jeedom.
Then use your favorite SSH client to connect to the raspberry’s IP. The default login and password after a fresh installation is ‘pi’ / ‘raspberry’.
First step is to change the default passwd:
passwd –> enter ‘raspberry’ (default passwd after a fresh installation –> enter your new password
Tweak the configuration
Change to the root user by using:
sudo su -
First, but this is a personal taste, i’ll install the joe text editor.
apt-get install joe
I like to make sure it will be the default editor:
update-alternatives --config editor
Then I install the locate package, to easily find files on the filesystem (by using first ‘updatedb’ to index the FS).
apt-get install locate
updatedb
Then I suggest to change the Timezone and extend the root partition to the available size on the SD Card:
raspi-config
Choose “4 Localisation Options”
Choose “I2 Change Timezone”
And select your country/town.
Then choose “7 Advanced Options”
Choose “A1 Expand FileSystem”
Choose YES when it will ask to reboot.
Then we will tweak a little bit the wifi interface. Reconnect by SSH, and edit the file /etc/network/interfaces and make sure it contains those lines (if you want to use DHCP; otherwise change the 8th line from ‘dhcp’ to ‘static’ if you want to fix the IP and ensure you got DNS servers properly configured in /etc/resolv.conf):
sudo su -
joe /etc/network/interfaces
source-directory /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
Now we will make sure the default Python version used is the “old good” 2.7, while the v3 is installed ans useable, system-wide:
update-alternatives install /usr/bin/python python /usr/bin/python3.7 1
update-alternatives install /usr/bin/python python /usr/bin/python2.7 2
As the highest number at the end of each line is the priority to be used, Python 2.7 will be used by default. Now we update a few things.
apt-get install python-pip python3-pip libglib2.0-dev
python2 -m pip install upgrade force pip
python3 -m pip install upgrade force pip
pip install bluepy
pip3 install bluepy
setcap cap_net_raw+e /usr/local/lib/python3.7/dist-packages/bluepy/bluepy-helper\nsetcap cap_net_admin+eip /usr/local/lib/python3.7/dist-packages/bluepy/bluepy-helper
Note that the line 5 above should return that it is already deployed:
Requirement already satisfied: bluepy in /usr/local/lib/python3.7/dist-packages (1.3.0)
I suggest you reboot with /sbin/reboot to check it’s reconnecting well – In my case it is !
Update the RPI & Raspian
sudo su -
apt-get update
apt-get full-upgrade
Then we will free some space on our root directory …
apt-get autoclean
apt-get autoremove
apt-get clean
Now I get a fully functional raspberry pi zero runing a specific debian, connected to my wifi network, and able to be used through SSH. This will be one of my bases for later articles.
2 thoughts on “Quick tutorial: installing Debian raspbian on a Raspberry Pi (Zero)”