Quick tutorial: installing Debian raspbian on a Raspberry Pi (Zero)

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.

This image has an empty alt attribute; its file name is image-22.png

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.

Plain Text
wpa_supplicant.conf

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:

Shell

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:

Shell

First, but this is a personal taste, i’ll install the joe text editor.

Shell

I like to make sure it will be the default editor:

Shell

Then I install the locate package, to easily find files on the filesystem (by using first ‘updatedb’ to index the FS).

Shell

Then I suggest to change the Timezone and extend the root partition to the available size on the SD Card:

Shell

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

Shell
Plain Text
/etc/network/interfaces

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:

Shell

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.

Shell

Note that the line 5 above should return that it is already deployed:

Plain Text

I suggest you reboot with /sbin/reboot to check it’s reconnecting well – In my case it is !

Update the RPI & Raspian

Shell

Then we will free some space on our root directory …

Shell

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.

Leave a Reply