It was time to replace the venerable Raspberry Pi (Model B Plus Rev 1.2) that has been the main workhorse of our home automation system for over a year. A Raspberry Pi 3 B will be used from now on. The old Model B+ will replace an even older Model A that was also hosting a home automation system. This is the first post recording the details of the installation of a home automation system based built around Domoticz on both of these Raspberry Pi models with Raspbian Buster Lite as the operating system.
The installation is described over three posts. The first one is about installing and updating the operating system. The second is about installing the most important servers that I use in my home automation system. The third is about peripherals added to the Raspberry Pi.
I have done this before, but with older versions of the operating system and the home automation software. Some things have changed and hopefully I have learned a few things since those earlier installations.
This series of posts could be of interest mostly to new fans of small single-board computers, in this case the Raspberry Pi. Assuming that many of these would be new to Linux, I have added sidebars entitled Information for neophytes in which I ramble about what that I think could be of help to beginners.
Table of Contents
- New To Linux
- Already Have Raspbian Running?
- Getting Buster on an SD card
- Start with Monitor and Keyboard
- Headless Start the Easy Way
- Headless Start the Hard Way
- Initial Boot
GNU/Linux or simply Linux is a mature open source Unix-like operating system which can run on numerous hardware platforms including Intel, AMD and ARM 32 and 64-bit processors. Many, including myself, see Linux distributions such as Debian and Manjaro (and their many variants: Ubuntu, Mint and so on) as viable alternatives to the ubiquitous Windows and Mac OS commercial operating systems. Right now, you are probably using one of these systems to read this. In all of these GUI systems, most everything can be done with the usual point and click mouse operations with the occasional data entry into text windows. To be fair, some arcane settings will require "dropping down" into a terminal or console (emulating a physical computer terminal) to issue commands at a prompt as in the "old days".
The CPM/80 ">" prompt, when
pip was not a Python utility!
The Windows 10 cmd ">" prompt.
Mac OS terminal "$" prompt (on a borrowed Mac).
The Ubuntu (Linux) terminal "$" prompt (on my desktop).
Raspbian is a Debian based Linux distribution for the Raspberry Pi. It is probably the most commonly used distribution on this family of single board computers. Raspbian comes in three flavours, two with a GUI desktop similar to what I have on my Ubuntu desktop machine and Raspbian Lite which does not have a graphic user interface. It is suitable for machines that are to be used for servers that are not used for personal tasks like sending emails or looking at YouTube videos. This is the version that I installed on the Raspberry Pi that will host the home automation system. Since there is no GUI, setting up the system has to be done with text commands.
The Raspbian LXTerminal "$" prompt (on Raspbian Desktop).
I cannot go into a lengthy tutorial about Linux commands. This post is already too long, but the real reason there will be no detailed discussion of Linux command is that I am not knowledgeable enough to undertake the task. Instead I will defer to two sites with lists of the most important commands, which will prove to be a good starting point for the newcomer.
- Linux commands by the Raspberry Foundation.
- 57 Raspberry Pi commands that everyone should know by Patrick at RaspberryTips
Do not worry, there is no need to memorize 57 commands before starting. Here is the list of Linux commands found in this post, which is far from using all those commands listed above.
Be careful with some of these commands. I have lost work when I
carelessly typed a command such as
reboot without looking at
the prompt. Instead of shutting down a Raspberry Pi, I entered the command in
a Ubuntu terminal with the obvious consequence that
my desktop computer became very quiet very quickly. You have been warned.
If Raspbian is already running on the Raspberry Pi, then it would be a good idea to back up configuration files, images, scripts and so on for the major programs that will be reinstalled later.
If you have a Linux-based desktop computer, then the SD card can be kept and placed in a reader. It will then be possible to access everything in the old system. Better yet, make a backup and mount the image, leaving the SD card in a safe place.
If you are upgrading to Buster from an older version of Raspbian on the same Rapsberry Pi, you could try in-situ upgrading. If it works then in principle, the configuration for all the installed packages will be in place. While the Raspberry Pi Foundation does give instructions on doing this, it gives the following warning.
We do not recommend upgrading an existing Stretch (or earlier) system to Buster – we can’t know what changes everyone has made to their system, and so have no idea what may break when you move to Buster. However, we have tested the following procedure for upgrading, and it works on a clean version of the last Stretch image we released. That does not guarantee it will work on your system, and we cannot provide support (or be held responsible) for any problems that arise if you try it. You have been warned – make a backup!
Past experience tells me that I cannot take the SD card from the older Raspberry Pi, stick it into the SD slot of the newer Pi and then try to update the operating system. So this is a tabula rasa install of Buster for the most part. Nevertheless, it is quite useful to save some configuration files, scripts, etc. for re-use in the new system or at the minimum for comparison with the new system.
As shown near the end of this post, I created a hidden local directory in which I saved useful Bash scripts. In addition two hidden files that define the user environment were modified. All this is saved for future reference.
||Bash script to create virtual Python 3 environments|
||Bash script to control a webcam (part 3 of this series)|
||Bash script publishing current time to some home automation devices (will be explained in the future)|
||Local configuration file for the |
||Local Bash script executed on login|
It's almost as if I had planned it; the Python scripts that are used
by the home automation system are in a Python virtual environment named
syspy . It is very simple matter to create a list of Python
packages added to the virtual environment to be able to recreate it elsewhere.
I saved the following files to recreate the virtual environment later on.
||Pip installed Python packages in |
||Script that reports Internet facing IP address of the LAN|
||Script that reports the ambient temperature and CPU temperature to Domoticz|
||Simple script to send emails|
Here's another area where fixes and tweaks have been accumulated and which
are easily forgotten. The list of user defined scheduled tasks, called
cron jobs in Linux lingo, can be
redirected into a text file to be saved for later reference.
Jobs created as
root can be saved in a similar manner.
There were no
root cron jobs on my original Raspberry Pi.
Here is the data that I saved. The last two are only useful if switch
icons were added manually. If they were uploaded using the
Custom Icons in the
Setup/More Options menu,
then they were saved in the database. Even then it might be worthwhile
to save the uploaded images. They can be identified by the file owner who is
||The installation parameters (directory, http ports)|
||The actual start up script (the one in /home/pi/domoticz/ is a template only).|
||Database of Domoticz devices|
||While floor plans are saved in the database, it is a good idea to keep a copy of the original files|
||List of all switch icons|
||Those icon images that were added manually|
The Web server is used for only one purpose: serve binary files for
over-the-air updates of home automation wireless devices. There
is one subdirectory per device type in the
directory. I saved everything in the
||Archive of |
||The Web server configuration file.|
nginx configuration file is almost more work than
editing the file when configuring the server as it involved only the addition
of a single line.
I saved the WireGuard configuration file
wg0.conf in the
/etc/wireguard directory. On some other systems there could
be more than one file and all should be saved.
I also saved the content of the
directory. That the script and information about all the peers that connect
to the virtual network server on the system used to create the configuration
Michael Vogt (mvo5) has created a package called apt-clone that saves
a list of all installed packages on Debian based systems including Raspbian.
Later the packages can be easily re installed in one go after installing the
operating system and
apt-clone itself. It is not unlike the use
pip freeze to preserve the Python environment for later use.
More information can be found in a post by Oltjano Terpollari: How to
Clone Packages in Debian Derived Systems and elsewhere on the Web.
This will be a first-time use of this package. First I installed it,
created a hidden directory
~/.clones and had
create the list of installed packages in that directory.
I have no experience with using
apt-clone when moving
to a newer version of Debian but it does work when cloning a current
version of the OS.
The home automation system cannot be offline while I am experimenting with updates. Instead everything is being done on a Raspberry Pi Model 3 B. Once that new system is running, I hope to do the same thing on the old Model B which I have found more than adequate as a home automation server.
As usual, I downloaded the latest
Lite version of
Raspbian Buster Lite Minimal image based on Debian Buster Version: September 2019 Release date: 2019-09-26 Kernel version: 4.19 Size: 435 MB
from https://www.raspberrypi.org/downloads/raspbian/. Of course you can download and install a desktop version of Raspbian and it will be possible to do everything described in these posts.
I followed the instructions to copy the image onto a micro-SD card in Installing operating system images.
Installing the current version of balenaEtcher in a
Linux system is quite simple. Extract the
balenaEtcher-1.5.59-x64.AppImage from the
downloaded archive and copy it to
~/.local/bin (it could just
about anywhere in the home directory). Delete any old application desktop
file. Lately, these are named
appimagekit-balena-etcher-electron.desktop and are stored in the
/home/michel/.local/share/applications/ directory. Start the
application and let it install a desktop file. From then on, balenaEtcher can be started in the usual way. I recommend
checking the application settings (clig on the cog wheel) and disable the
Auto-unmount on success option.
As before, it was a breeze to copy the operating system image onto the SD card with the application. It is not even necessary to decompress the downloaded archive containing the image file.
All these file management chores, copying, deleting, extracting from archives and so on, can all be done with "point and click" ease using Double Commander. It is one of the first utilities I install in all the Linux distributions I use. It even works in Windows, macOS and FreeBSD. Highly recommended. Furthermore, it is written in Free Pascal/Lazarus, my favourite programming language.
By far the easiest way to boot and configure Raspbian on a Raspberry Pi is with a direct connection to the Linux console using a monitor and keyboard. A mouse can also be connected, but it is not needed as Buster Lite does not have a graphical interface. If it is possible to connect the Pi to the local area network with an Ethernet cable, then updating the system and installing packages will be very simple indeed.
Put in the SD card with the Debian image and turn the machine on. Expect lots of things to scroll by the screen and after a while enter the default password when prompted. Do not worry if nothing shows up as you type, that's a safety feature.
Once you have typed in the invisible password, press the Enter key to tell Linux that you have finished your bit. It will read what you have typed in and either complain that the password is wrong or it will welcome you and show the '$' prompt.
If this is the first time that you are setting up a Raspberry Pi, I would
strongly suggest that you follow what preceded and not bother with the
"headless" stuff in the following sections. Later on when you see an
ssh command given from a Linux desktop,
or a Windows machine:
it means that I am connecting to a headless Pi over the local area network. Ignore these commands if you have a direct console connection and skip to the Basic Configuration section.
Of course if an extra keyboard and monitor are not available, then you will have to find another way to reach a headless Raspberry Pi. There is an easy way to open a session with a Raspberry Pi that is not connected to a keyboard and monitor, and there is a hard way. Both are described below.
If you have a USB to Serial adapter that operates on 3.3V and you know how to use a terminal program such as Screen, tmux or C-Kermit, then it is relatively simple to connect to a Rapsberry Pi. Here is the pinout.
|Raspberry Pi||USB Serial AdapterConnection|
|6, 9 or 14||Ground||Ground pin|
If the Raspberry Pi is an older model without built-in Bluetooth, then
there is no further preparation needed. If the Raspberry Pi is a a newer
model, then the
config.txt file found in the boot partition of
the micro SD card containing the Raspbian image has to be modified. Assuming
the SD card is still in the desktop computer reader, its boot partition is
should be seen as a drive connected to the system. If not, remove the card
from the reader, wait awhile and insert it in the reader again. The partition
should be found by the system because its file system is the ubiquitous FAT32
which most operating system can read.
Add the following lines near the end of the file.
List the serial devices on the system before connecting the USB to serial (tty) adapter to the desktop computer
Now connect the serial end of the the USB to Serial adapter to the Raspberry Pi which should not be under power and then connect it to the desktop USB port. List serial devices to find the newly added adapter, start up the terminal program connecting to that port and then apply power to the Raspberry Pi. You should then see the Linux boot messages which end with a login prompt.
If using Screen the terminal should be launched with the following command on the desktop.
If you are here, then ignore the
ssh commands such as
that you may see later on in this post unless you have connected to the Raspberry Pi over the local area network, which is not necessary when there is a direct serial connection with the Pi. Skip ahead to the Basic Configuration section.
The Raspberry Pi is used as a headless server with no monitor and no keyboard. I am rather lazy find a hassle to dig out a monitor and keyboard just for the initial configuration of such a system. And my USB to serial adapters have a way of disappearing. So this is my preferred method to set up a Raspberry Pi, but not the one I recommend.
Since connectivity with the local network will be by Wi-Fi when the home automation system will be in operation, it would be great if that could also be set up before the first boot. Well, it can... maybe. Wi-Fi can be enabled without problems on newer Raspberry Pi's that have a built-in Wi-Fi (Raspberry Pi Model 3 and newer). On older Raspberry Pi it may be possible, but that requires a Wi-Fi USB dongle that is supported by the Linux kernel; see Various Hardware with Raspbian Buster Lite, USB Wi-Fi Dongles for some details.
Furthermore a static IP addresses can be assigned to the Ethernet network interface. It is also possible to do that for the Wi-Fi interface if the desktop (or portable) computer used to create the SD image is running Linux or Mac OS (I have not verified this claim on a Mac).
The setup is in two or three parts. I am assuming that the (micro) SD card
containing the Raspbian image is still connected to
the desktop computer and its
boot partition is visible in the
desktop system. If not, remove the card from the reader, wait awhile and
insert it in the reader again. The partition should show up as its file
system is the ubiquitous FAT32 which most operating system can read. If the
desktop is running Linux or MacOS the second, much bigger partition,
also show up. Windows will not read an Ext4
This approach entails connecting to the Raspberry Pi over the local
network using the SSH protocol. By default the
ssh service is
not enabled in Raspbian Buster. But, this is easily
remedied. If there is a file named
ssh in the
partition when the Raspberry Pi is first booted, then the service will be
enabled and started. The content of the
ssh file does not
matter. Indeed, it can be an empty file.
These commands, shown on a greenish background, are typed out in a virtual console or a terminal which is a wrapper program that runs a shell or command processor on my desktop Ubuntu system. The terminal is easily started with the simultaneous three key press: AltCtrlT.
The desktop computer name is
hp and my user name is
michel, hence the shell starts each command line with
michel@hp:. After the colon, comes the present working directory
(pwd in the jargon). In this case it is initially
~ which is
short for the current user home directory which here is
/home/michel. Finally, the shell writes the prompt which here is
$. It can be different dependant on the shell being used. That's
Linux for you, there is more than one shell.
The first command,
cd (for change directory), changes the
present working directory. The second command,
used to change the time stamp of a file. But here we are exploiting
a side effect of the command; if the named file does not exist, it
is created. The third command,
ls, lists the content of the
present working directory if no parameters follow it. In this instance,
-l parameter asks for a detailed listing. The added
ssh will limit the listing to matching files. We can
then see that the file
ssh has indeed been created and that
its size is 0.
Instead of using
touch, a file with minimal content named
ssh could have been created with a text editor such as
nano (see below). It would not matter what the file
Do not forget to press the Enter key after typing each command. That is how the shell knows that you are done and that it is time for it to do its job. A long time ago, back when most computer programs were punched on cards made of light cardboard, I caused the reboot of a laboratory system when I first used an interactive terminal because I hadn't realized the need for the Enter. I will not go into the details, suffice it to say I am still red-faced about ruining someone's experiment. We all have to learn.
Because Double Commander allows me to launch
a terminal in a specific directory, I did not even have to do the
three-finger salute mentioned, nor issue the change directory command
cd shown above.
What is required is to create the
configuration file with Wi-Fi credentials. I used
nano from the
command line, but any text editor could probably be used. The file,
wpa_supplicant.conf, goes in the
ssh file created in the previous state. You have
to adjust the two-letter country code and the network credentials. The
quotation marks around the SSID and password are necessary.
nano is a small text editor found on most
Linux distributions including Ubuntu
and, as we shall see later, Raspbian. It is a
relatively simple to use; all keystrokes enter text into the file being
edited at the current cursor position. The exceptions are control and meta
sequences such as Ctrlx to
leave the editor. The most important of these sequences are displayed at the
bottom. There is an on-line manual.
It is not necessary to use
nano on the desktop computer, any text editor can be used. Just
make sure to save the file as a text file. Just to be sure list the content
of the file
This not strictly necessary but it is highly recommended to set static addresses for the network interfaces that will be used. First, this Raspberry Pi will be a server which needs to be easily found on the local network. Having a static IP address will accomplish this. Otherwise, the IP address may change when the Pi is rebooted. As the Domoticz installation script says:
Domoticz is a SERVER so it needs a STATIC IP ADDRESS to function properly.
The other reason is that it will make it much simpler to find a headless Raspberry Pi to complete its basic configuration, especially for those that use a Windows desktop or portable computer.
I will make two points before going on to show how to proceed.
- Make absolutely sure that the static address about to be assigned to the Raspberry Pi is not used by another device connected to the local network.
- Make absolutely sure that the static address about to be assigned to the Raspberry Pi is not used by another device connected to the local network.
The static address can always be changed later.
There are two ways of setting a static IP address. The "easy but incorrect way" that will only work with an Ethernet connection to the Raspberry Pi. It is the only way I know that can be used by those that are using a Windows desktop. The "harder and correct way" will work with either an Ethernet connection or a Wi-Fi connection if it has been set up correctly as explained above.
Easy but incorrect
A simple addition to the text file
all that is needed.
Add "ip=192.168.1.100" (or whatever the IP should be) without the quotation marks at the end of the single long line of commands the file contains.
That is all that is needed right now. It will be better to clean things up later when the Raspberry Pi is configured.
Strangely (or not?) if Wi-Fi credentials have been defined, the Wi-Fi
interface will not be enabled unless the wired connection is in place
when powering the Pi for the first time. In that case, the Ethernet interface
will have the static IP address specified in
the Wi-Fi IP address will be set by the LAN
Harder but correct
This requires access to the
rootfs partition which, on my
Ubuntu desktop machine, is mounted in the
/media/michel directory alongside the
partition. Sometimes there is a problem trying to
cd into the
rootfs. This happens when the SD card is changed quickly. Start
disk application, find the SD card in the list of drives in
the left pane and mount both the
partitions by selecting the partition in the listt of Volumes and then
clicking on the left most button with the right pointing triangle. If the
button shows a square, the partition is already mounted.
The mount point will be displayed on the
Contents line at the
bottom. In my case it is
/media/michel/rootfs. The fixed IP
address is added to the
dhcpcd configuration file. I prefer to back up the
original file found in the
rootfs/etc directory before modifying it.
nano can be made to back up the original when
saving a changed version of the file.
The following lines, with appropriate changes, need to be added to the configuration file.
All the IP addresses shown above need to be adjusted to take into account
the parameters of the local area network. The router IP address (often called
gateway elsewhere) and the DNS server IP address are usually the
same and often, but not always, similar to the one shown above. But some
local area networks (LAN) use the so-called 24-bit address block starting at
10.0.0.0 and others use the 20-bit block starting at 172.16.0.0. All the LANs
I have used were in the 16-bit block starting at 192.168.0.0, with the only
exceptions being a virtual private network and the virtual machines in Oracle VM VirtualBox. If you want to learn more about these
private networks look at the Wikipedia article.
I think it is best to assign different IP addresses to the two interfaces, unless it is certain that the Ethernet and wireless interfaces will never be simultaneously connected to the same local network.
It is now time for the initial boot. All that needs to be done is to
safely eject the SD card from the desktop reader, then place it in the SD
slot of the Raspberry Pi. I suggest that the Raspberry Pi be connected to the
local area network (LAN) with an Ethernet cable for the initial boot at
least, especially if a Wi-Fi dongle is being used. Indeed if the
cmdline.txt file was modified to set a fixed IP address, then a
wired connection to the LAN is mandatory. You may have to wait until the LED
activity stops and the red LED is steadily on to open an
Opening a remote session on the Raspberry Pi means that shell commands
cat) can be
executed on the Rapsberry Pi from another computer on the same network
as the Raspberry Pi. It comes down to using the desktop keyboard and monitor
as if they were connected to the Raspberry Pi.
Of course you have to use a program on the desktop to do this. On Linux systems, it would most likely be the command line
ssh, part of the OpenSSH
suite of tools which implements the SSH (Secure Shell) protocol. While the
command line utility
ssh is available in Windows, most users would probably use PuTTY instead to open a remote
session on the Raspberry Pi. From what I can make out, Mac
OS X users can use the built-in
ssh client in a terminal
window as shown above but there are alternatives.
It is necessary to log into an existing user account and provide
the correct password when starting a remote session or a local session with
a keyboard and monitor connected to the Raspberry Pi. Initially there is only
one user account:
pi and the password is
ssh doesn't recognize the secure key returned by the
Raspberry Pi (ECSDA is the cryptography algorithm used to generate the key)
so it asks if it is alright to connect. Once you have answered
in full, it will store the key and will not ask again.
ssh is a secure replacement for
telnet. Anyone else
remember using NCSA telnet over a Crynwr packet driver on PC running MS-DOS? I would open
sessions on the IT department minicomputer, a PDP-11 as I remember. I forget
exactly why? Probably to send e-mails, which was a complicated thing to do in
the mid '80s. I do remember accessing
gopher sites that way in
the early '90s and even building a demonstration
gopher site for
our department trying to get the institution to get on with it. It never did,
HTTP took over.
Since I was able to set up a static IP for Ethernet and Wi-Fi using the
"hard but correct way", I opened a remote session with
the specified address Wi-Fi address without even connecting the Ethernet
In Windows the command would be the same
but the Ethernet IP address has to be used and a wired connection is necessary.
If it had not been possible to set a static IP address, then try to connect
raspberrypi.local as shown here.
This will work in a desktop computer if its operating system has so called
Zeroconf technology in place. That is the case for most major
Linux distributions where the Avahi service is installed. It should also work in Mac OS where Bonjour takes care of
the zeroconf protocols. It will not work in a fresh install of Windows. I tried and got this.
Nevertheless, give it a try because it will work in Windows if Bonjour Print Services from Apple was installed previously to reach a networked printer.
raspberrypihost name was already connected to the network, then the host names will be mangled to avoid conflicts. Its qualified host name address could be something like
raspberrypi-2.local. You could use a
zeroconfservice browser to try to find it.
If attempts at starting an
ssh session give results such as
what follows then there is something obviously wrong.
In the case of
Connection refused then in all likelihood
ssh was not enabled; something went wrong when creating the
ssh file in the
boot partition of the SD card.
No route to host is displayed then it will be necessary
to find the IP address of the Raspberry Pi. There are, at least, two ways to
do this that should work no matter the operating system.
The router route
One way is to log into your router with a web browser to find the IP addresses of the devices connected to it. By scanning these addresses with the Raspberry Pi connected and not connected to the network, it should be fairly easy to identify the Raspberry Pi. This is not a foolproof method, I find that my router does not show all connected devices and does not react quickly when a device is disconnected.
Where's the router?
If you do not know the IP address of the router to access its web server
in the first place, then have a look on the back or bottom of the device
itself. If you are still out of luck, try running the
in a command window on a Windows desktop. You could
ifconfig in a Linux or the
ip address command if
net-tools (which contains
ifconfig is not installed which is the case in Ubuntu). Even simpler, look at the interface settings on the
desktop; the IP address of the default route and DNS server is probably the
IP address of the router. Below are a couple of screenshots taken in
virtual machines, the first running Mint19 (another
variant of Debian) and the second
The IP scan method
Another approach is to use an IP scanner. Angry IP Scanner is available for
Windows, Linux and Mac OS X. I use Zenmap, a graphical
nmap which is available in the Ubuntu software library. If you have a wireless router, you
can try NetX on an Android tablet or phone. I am sure there is
something equivalent on IOS. Just as before,
do two scans for valid IP addresses on the local area network. One
scan is done with the Raspberry Pi powered on and connected to the network
and one scan with the Raspberry Pi powered off. A comparison of the
valid IP addresses should reveal the IP address of the Raspberry Pi.
The ARP scan method
I have just become aware of yet a third way explained by Remi Bergsma in
HOWTO discover the ip address of a Raspberry Pi.
I had to install the
The second command was to get the correct name for the network interface
that is used by the desktop computer to connect to the local network.
It is not really necessary as the
--interface but if more
than one interface is connected, the scan will take longer and there will
be repetitions if interfaces are connected to the same network.
Something like this should work in Windows without the need to install anything.
All this is proof that setting up a static address before booting the Raspberry Pi for the first time is worthwhile.
If this is the first time you log onto a Raspberry Pi with
then things should go smoothly. Just enter the default password,
If the IP address had already been used for an
or if the host name
raspberrypi.local had already been used
then expect some complication.
Something ever more byzantine could be displayed. Assuming that everything is safe, just go along with the suggestions.
At this point you should be logged into the Raspberry Pi. If you installed the desktop of version of Raspbian and connected a monitor, keyboard and mouse to the Pi, you will be in the graphic user interface, so it will be necessary to start a terminal to follow along. This is not too hard, just find and start the LXTerminal application in the usual fashion. You could also try the 3 key combination AltCtlT which may pop up the terminal window as in Ubuntu.
The password and other basic parameters should be changed. This is
best done with the configuration utility. But before, you may want to change
avahi configuration file.
With that, the "workstation" will show up in the
avahi-browse --all command.
cmdline.txt had been modified to set a static IP
address for the Ethernet network interface, then this is time to set the
static IP address the correct way and to remove the modification to the
file. Similarly if a static IP address had not been assigned before
booting, then this would be the opportune time to do it. The static
address or addresses are set in the
You just need to add the static addresses as shown above. This will take effect on the next reboot of the Pi. But do not reboot now, continue on to complete the basic configuration and then reboot as instructed.
cmdline.txt had been modified it should be
returned to its original state now that
dhcpcd.conf has been
ip=192.168.1.100 (or whatever the static IP
was) at the end of the line. The
sudo prefix is needed here
because the copy of
cmdline.txt in the
Now start the configuration utility.
This is the opening screen of the configuration.
If you logged in with Kermit over a serial connection, you will not get the pretty colours:
It does not matter, the program works the same way. Navigate with the Tab
key ⇥ to move from one control to the next and with
the up ↑ and down ↓ cursor
keys to move within a list. Select the highlighted choice by pressing on the
↲ or Enter key. The
selection can also be made by "tabbing" to the
<Select> control at the bottom and then press the Enter key. I suggest that the following changes be
- 5 Interfacing Options / P2 SSH:
choose <Yes> to enable the SSH server if it has not already been done. Even if you installed the Desktop version of Rasbian and have a keyboard and monitor hooked up to the Raspberry Pi, I recommend doing this.
- 4 Localisation Options / I2 Change Timezone:
select your continent or region and then select your city or one nearby in the same time zone. As this is a headless system, there is no real advantage to change the locale or keyboard layout.
- 7 Advanced Options / A3 Memory Split:
if this Pi will be used as a server it makes sense to allocate as little memory as possible to the graphic processing unit. This is 16 M bytes.
- 1 Change User Password:
do not forget it; save it in a password manager (I use KeePassXC).
- 2 Network Options / N2 Wi-fi:
enter the wireless network name and password if Wi-Fi connectivity is desired and if it was not defined already.
- 2 Network Options / N1 Hostname:
change the host name to avoid collisions with other Raspberry Pi that may connect to the network currently or in the future. For illustrative purposes, I set the host name to
Reboot as suggested, and then after a while check that the Raspberry Pi
publishes its host name and then reconnect with
ssh. Even if
a keyboard and monitor are connected to the Raspberry Pi, it is a good idea
to learn how to connect via SSH to a Pi that will be used as a server.
If everything seems in order and if it had been necessary to edit the
config.txt file to enable the uart because the Raspberry Pi
has a bluetooth chip, then I suggest disabling the UART.
This is to regain the slight loss of performance caused by enabling the serial port. See Configuring The GPIO Serial Port On Raspbian Jessie and Stretch Including Pi 3 and 4 by Jon Watkins for details.
For added security, it is not a bad idea to change the default user. In
the past, I would simply add a new user and eventually removed the
pi. But that was a hit-or-miss approach which usually
meant hunting down a missing group membership for the new user when something
new did not work. Luckily, Jim McDonnell at Unix etc.
has a very good explanation of how to proceed systematically to avoid such
problems. I just followed the instructions in How to Rename the Default Raspberry Pi User, executing
the scripts found in that article. There were a couple of error messages.
Because the listed configuration files are not present in the
version of Raspbian there were no real errors, as
mentioned in the article.
Because the default
pi user was renamed
ssh connections need to be with that account from now on.
Before installing any major new piece of software, it is always important
to update the operating system. This is something that is done more or
less automatically in full blown desktop systems such as
Ubuntu. On the
Lite version of
Raspbian, it has to be done manually.
This operation took a surprising amount of time even if the image was rather recent. Now you may be time to get a coffee, tea or other beverage.
Newcomers to Debian Linux might wonder what this odd-looking commands is. The command line contains two commands that are separated by the double ampersand. Instead of combining the commands they could have been given one after the other.
The first command,
apt-get update, scans the default Debian repository and any other repositories that you may
have added (see below for an example) to update the list of currently
available software packages in the repositories. The second,
upgrade will replace currently installed packages with any newer
version if available. It is important to realize that
upgrade uses to local list of available packages to decide if a newer
version is available, it does not scan the repositories itself. That why it
is important to execute
apt-get update first.
-y option is added to the
upgrade command so that it will not be necessary to confirm, with a
y, that the operation is to be completed.
Other Linux distributions have different package
managers: Red Hat and CentOS
yum, Arch Linux uses
pacman and so on.
Even within Debian the story is rather more complex. As far as I know, APT (Advanced Packaging Tool) is actually a "front end" for DPKG the Debian Package Management System. There are other front ends, such as Synaptic, which I occasionally use on my Ubuntu desktop, and Aptitude.
With its inclusion in Ubuntu 16.04 in 2016, a new
front end called simply
apt started to become popular. Basically,
it aggregates the commands spread across the
apt-cache utilities. You will find in my posts that I sometimes
apt update and
apt upgrade instead of
apt-get versions shown above. They are basically
interchangeable. The same is true for
apt show and
apt-get show, but I prefer to use
to get pithier information about available versions of a package as well
as the installed version when a package is already installed.
For more information see Difference Between apt and apt-get Explained.
I also enabled the UDP module of the log server on the Raspberry Pi because a number of home automation devices send their log messages to the Pi (see Syslog Server on Raspbian).
Log files live in the
Listing the content a log file looking for error messages for a particular
problem is a lot like drinking from the proverbial fire hose. Just
syslog to see what happens.
You can use another Linux utility to see only the last desired number of messages in a log.
You can "follow" a log file, which in effect will print to the console each new message as it is written to the log.
If you know what you are looking for then you can pipe the output of
grep to show only log messages that
grep to select messages with "gnugp" or "fips"
and then piping the result to
grep to select messages with "Nov 5"
will display only messages on "Nov 5" containing "gnugp" or "fips".
I added two directories to the
woopi home directory that
will hold bash scripts and python scripts.
Then I added that directory to the search path by appending the
following to the
.profile file in the home directory.
I prefer creating a virtual Python 3 environment to contain what I'll call system Python scripts. That way it will be possible to experiment with newer libraries in the future without breaking the Python scripts the system relies upon. A couple of packages need to be installed to create virtual environments.
I have written a bash script that automates the creation of virtual environments. This will copy it to the bash script directory and make it executable.
Following a suggestion by AndyG, I added a shell function and alias
Log out of the
woopi account and log back in for these
changes to take effect and then create the virtual environment.
At this point I copied the saved pythons scripts into the environment. Some of these will not work because of missing Python modules. However these are easily added if the environment had been saved from a previous installation as explained above.
Of course if you did not have a virtual Python environment in a previous installation of Raspbian, then these last two steps cannot be followed. Later I will show which Python modules were added to the Python environment.