Lightweight Raspberry Pi image backup

Lightweight Raspberry Pi image backup

We present here a method for making a light backup and restoring a Raspberry Pi. Creating a backup, an image of your Raspberry Pi, is essential in the event of SD card corruption or power failure. On Raspberry Pi and other single-board computers, the SD card often fails. You therefore need to make a backup in the form of an image or iso file, so that you can upload this image to a new SD card and recover your configuration.

The problem is that saving an image includes the entire memory of the SD card. So you can end up with several files of 32, 64 or 128Gb.


  • Raspberry Pi
  • Two SD cards
  • Internet connection

OS backup method

There’s no other method quite like it. The method I suggest consists of several steps, but will allow you to have a light backup of the Raspberry Pi and be able to update your projects easily.

The method consists of the following points

  • Recover OS information
  • Recover hardware info (optional)
  • Recover configuration files
  • Recover installed packages
  • Recover installed Python packages

The list is by no means complete, but with it you can get close to an exact copy of what you had before.

Cleaning your system

sudo apt-get  --purge -y autoremove 

You can also delete any software you’ve never used.

Create a backup folder

It can take any form you like. The important thing is that it is clear so that you can find your way around.

  • RPiBckp
    • version
    • projects
    • config

Recover OS information

Depending on your project, it’s important to know the OS version, as compatibility issues may arise depending on the packages used.

cat /etc/os-release
cat /etc/os-release > /home/pi/RPiBckp/version/os-version.txt

Another important piece of information is the kernel version and hardware configuration.

uname -a > /home/pi/RPiBckp/version/sys-version.txt
ls -l /lib/modules

N.B.: uname -r gives you the specific Kernel version. You can find the installation file in the firmware list

Recover installed packages

For a list of installed packages, enter the command

dpkg --get-selections

If you want the list of packages with the version number

apt list --installed

N.B.: for all these commands you can use grep to filter your search.

It’s important to note that there are a number of packages installed automatically and others that you install according to your needs.

The list of automatically and manually installed packages can be obtained with the respective commands

apt-mark showauto # paquets automatique
apt-mark showmanual # paquets manuel

For my part, I keep a file with all installed packages to keep track of all versions.

apt list --installed > /home/pi/RPiBckp/version/apt-list-installed.txt

a file with manually installed packages

apt list --installed | grep -v automatic > /home/pi/RPiBckp/version/apt-list-manual.txt

and I create the file with just the names to launch the package installation

apt-mark showmanual > /home/pi/RPiBckp/version/packages.txt

I can then install the right versions individually if they don’t suit me.

Recover installed Python packages

python3 -m pip freeze
python3 -m pip freeze > /home/pi/RPiBckp/version/requirements.txt

Recover configuration files

Some configuration files can be interesting to retrieve, in particular the wifi configuration.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /home/pi/RPiBckp/versión/wpa_supplicant.conf

Creating a Git repository

It might be a good idea to create a git repository for each of your projects, either for configuring a Raspberry Pi, or for a set of Python scripts. A git repository is ideal for keeping your projects up to date, particularly in terms of package and OS versions.

Once you’ve recovered all your interest files, it’s time to restore your project.

Installing a Raspbian version

You can use the Raspberry Pi Imager software

or download the desired image from the site http://downloads.raspberrypi.org/raspbian/images/

N.B.: OS versions that are too old may not be compatible with new hardware and may cause security problems.

Installing a Kernel version

You can check the Kernel version installed with the command

ls -l /lib/modules

To install a specific version of Raspberry Pi firmware, you can find the list of firmware versions by version number.

You can then copy the Git hash corresponding to the desired version (e.g. 5.10.63: 64132d67d3e083076661628203a02d27bf13203c).

And install it using the command:

sudo rpi-update <git_hash>

For example:

sudo rpi-update 2ef601a50b68eebeeb4dc3c6c525855961891be6

Warning: be careful which version you install. The Kernel version should only be modified by experienced people who have a compatibility problem that cannot be solved in any other way.

Copy your backup folder

On a fresh installation of Raspbian, you can copy your backup folder and

Install the required packages

It is possible to install a set of APT packages from a text file containing the list of files to be installed

xargs -a packages.txt sudo apt-get install -y

You can do the same to install Python packages.

python3 -m pip install -r requirements.txt

Copy configuration files

For the wifi configuration file or any other file, you can use the copy or move command in superuser mode (sudo).

sudo cp wpa_supplicant.conf /etc/wpa_supplicant/


This method doesn’t produce a perfect copy of your project, but it does allow you to reproduce and maintain your project with very little memory space, which can be a huge advantage. You’ll end up with a set of configuration files that will enable you to quickly restore a corrupted SD card.

If you have any ideas for important files to back up or other methods of restoring an SD card, please feel free to leave a comment.


Raspberry Pi Zero microcontroller overview

Raspberry Pi Zero microcontroller overview

The Raspberry Pi Zero microcomputer is very compact, with an integrated Bluetooth and WiFi module. Very easy to use, it is smaller but less powerful than the Raspberry Pi3.

Microcontroller features

The Raspberry Pi Zero microcontroller uses the ARM11 single-core microprocessor. This processor operates at a clock frequency of 1000 MHz. It has NC kB RAM, NC kB EEPROM and 512,000 kB Flash memory (for programming and data logging).

  • CPU single-core ARM11
  • Voltage : 3.3V
  • Flash : 512000 kB
  • RAM : NC kB
  • EEPROM : NC kB
  • Clock speed : 1000MHz
  • WiFi : Yes
  • Bluetooth : Yes
  • SD : Yes

The microcontroller has a WiFi chip, enabling it to connect to the local network, create a server or create its own network for other devices to connect to. The microcontroller has a Bluetooth chip that enables it to interact with other devices. The Raspberry Pi Zero microcontroller also has an SD card slot for storing files for a website, for example.

Power supply

The Raspberry Pi Zero microcontroller operates on a voltage range of 4.9-5.2V, thanks to its on-board voltage regulator, while the microprocessor operates on a voltage of 3.3V. In normal operation, the microcontroller consumes up to 45mA (if no power is supplied) and can accept a maximum current of 20mA on each of its IO pins.


  • Digital I/O : 29 (GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, GPIO8, GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, GPIO24, GPIO25, GPIO26, GPIO27, GPIO28)
  • Broches PWM : 29 (GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, GPIO8, GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, GPIO24, GPIO25, GPIO26, GPIO27, GPIO28)
  • Communication Serial: 1 ((‘GPIO14’, ‘GPIO15’))
  • I2C communication : 1 ((‘GPIO2’, ‘GPIO3’))
  • SPI communication : 1 ((‘GPIO8’, ‘GPIO11’, ‘GPIO9’, ‘GPIO10’))
  • I2S communication: 1 ((‘GPIO18’, ‘GPIO19’, ‘GPIO21’))

Summary of features

Nom: RaspberryPiZero
Marque: RaspberryPi
CPU: single-core ARM11
Tension d’alimentation : 4.9-5.2V
Tension logic: 3.3V
E/S digitales: -1
Entrées analogiques: 0
Flash: 512000kB
Fréquence d’horloge: 1000 MHz
Wifi: Yes
Bluetooth: Yes
SD card: Yes
Touch: No
UART/SPI/I2C/I2S: Yes/Yes/Yes/Yes

How to get started

Configuring a Raspberry Pi as a Wifi Access Point

Configuring a Raspberry Pi as a Wifi Access Point

The Raspberry Pi can be configured as a Wi-Fi Access Point. This is useful when the Raspberry Pi doesn’t have access to a wifi network and you want to connect to it locally. In this tutorial, we’ll look at how to configure the Raspberry Pi to generate its own WiFi network.


  • Raspberry Pi (3B+, 4)
  • 32GB SD card
  • Power supply 5V 3A
  • HDMI monitor+keyboard+mouse or remote access (SSH, VNC, NoMachine)

Installing packages for access point configuration

Update distribution

sudo apt update && sudo apt upgrade

To configure the access point, the following packages must be installed

sudo apt install hostapd dnsmasq

You can then unmask and activate the hostapd service

sudo systemctl unmask hostapd
sudo systemctl enable hostapd

For the rest of this tutorial, we need to choose a fixed IP address for the Raspberry Pi. Here, we choose

Headless Raspberry Pi configuration

  • Configure wpa_supplicant
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

  • Configure dhcpcd
sudo nano /etc/dhcpcd.conf
# RaspAP default configuration
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private

# RaspAP wlan0 configuration
interface wlan0
    static ip_address=
    nohook wpa_supplicant
  • configure hostapd
sudo nano /etc/hostapd/hostapd.conf
wpa_pairwise=TKIP CCMP
## RaspAP wireless client AP mode

## RaspAP bridge AP mode (disabled by default)

To activate the hostapd service, you need to specify the path to the configuration file

sudo nano /etc/default/hostapd

Uncomment the DAEMON-CONF line and add the path to the configuration file

  • configure dnsmasq

In the dnsmasq.conf file, we’ll specify a set of available IP addresses

sudo nano /etc/dnsmasq.conf

You can then reboot your Raspberry to activate the access point. The icon with the opposite arrows should appear on the Raspberry desktop.

And the access point should be available on devices within network range.

Order summary

sudo apt update && sudo apt upgrade
sudo apt install hostapd dnsmasq
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
sudo nano /etc/dhcpcd.conf
sudo nano /etc/hostapd/hostapd.conf
sudo nano /etc/default/hostapd


Bonus: Choose a local alias for your IP address

Once our Access Point has been created, we can give your IP address an alias. This allows you to type a URL (domain.com) instead of the IP address to access the Raspberry Pi.

To create a local alias, we’ll define the alias in two different files and link it to the IP address

  •  In /etc/dnsmasq.conf
sudo nano /etc/dnsmasq.conf

At the end of the file, add the following line with your IP address and the desired domain name

  • In file /etc/hosts
sudo nano /etc/hosts

At the end of the file, copy the following line with your IP address and the desired domain name mydomain.com

After rebooting the Raspberry Pi, you can check the configuration by connecting via SSH (remembering to connect to the Raspberry Pi access point).

ssh pi@mydomain.com

This procedure comes in very handy when you want to create a local Web Server on your Raspberry Pi. This can allow you to access a web page, hosted on the Raspberry Pi and served by Flask, by typing a URL into your web browser while connected to the same network.


Using CAN HAT with Raspberry Pi

Using CAN HAT with Raspberry Pi

It is possible to work with the CAN protocol used in the automotive industry on Raspberry Pi using a CAN HAT. This allows yorto plug in and decode messages from the on-board computer, retrieving information such as fuel consumption, speed or engine rpm.

Installing libraries

To use CAN Hat with Raspberry Pi, only one python package is needed can-utils

sudo apt-get install can-utils

This package handles the CAN communication protocol commonly used in the automotive industry.

  • read and decode CAN messages
  • save messages in a CANlog file
  • replay the CANlog file on a real or virtual CAN bus to simulate a device

N.B.: you can also install pandas and matplotlib to process and trace the data received.

CAN bus configuration

sudo ip link set can0 up type can bitrate 50000
sudo ip link set can0 down

For a virtual can bus, yorcan enter the following commands

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

To check that the can bus is in place, enter the command

ifconfig can


ip addr | grep can

Sending and receiving CAN messages

Enter the transmission command in a terminal

cansend can0 001#1122334455667788

Then, in another terminal, enter the receive command

candump -tz can0

the -tz flag is optional and allows the time to be displayed

(1668600101.854788) can0 0B2#0000000000000000
(1668600101.855011) can0 116#04045CAE092596FF
(1668600101.855285) can0 11E#6B04000000000000
(1668600101.855949) can0 107#0000FE46411404E7
(1668600101.856174) can0 0A7#CDD35F7FFDF5173F
(1668600101.856408) can0 0A8#C1D35FC98C643C0F
(1668600101.856652) can0 32C#0003000098240810
(1668600101.856904) can0 557#0000000000000000
(1668600101.857743) can0 086#1703C82100000000
(1668600101.858067) can0 23D#0000F8FFFFFF3F00
(1668600101.859665) can0 3D0#000000A380008000
(1668600101.859913) can0 33C#0000012080000000
(1668600101.860199) can0 16A954C2#006B000000000000
(1668600101.863567) can0 464#0000000000000000
(1668600101.863814) can0 3DE#FE00000000000000
(1668600101.864582) can0 0B2#0000000000000000
(1668600101.864826) can0 0FD#E5E53F8000000000
(1668600101.865070) can0 101#B4057E0582030000
(1668600101.865308) can0 106#B985B3040000AF20
(1668600101.865631) can0 120#860200020008FF01
(1668600101.865866) can0 121#4602004039627EFE
(1668600101.866109) can0 15A#760E000001E60000
(1668600101.866339) can0 0A8#71D45FC98C643E0F
(1668600101.866574) can0 0A7#F7D45F7FFDF5173F

Recording and replaying a CANlog file

To save a log file of CAN messages, enter the command:

candump -l can0

this command creates a candump–.log file

The file can be replayed on the same can bus or on a different bus.

canplayer -I candump-2022-11-16_120141.log #play can on same canbus as in the file
canplayer vcan0=can1 -v -I candump-2022-11-16_120141.log #play saved canbus (can1) on vcan0
canplayer -l 2 -I candump-2022-11-16_120141.log #play can data twice
canplayer -l i -I candump-2022-11-16_120141.log #play can data inifinitely

Decode CAN bus messages

To decode messages on a CAN bus, it is necessary to have the definition of the messages on the CAN bus. This definition is described in a .dbc file, which is the CAN bus database. This document contains the message identifier and the names of the signals it contains.


Once you’ve mastered the protocol, you can use the CAN hat board with Raspberry Pi to develop embedded automotive devices.


Raspberry Pi Headless configuration

Raspberry Pi Headless configuration

In this tutorial we configure the Raspberry Pi in headless mode. This mode can be interesting when using the microcomputer without a screen. The main advantage is a lighter installation without the desktop and unnecessary software.

Configuring your Raspberry headless

download and write the Raspberry Pi OS Lite image file to the SD card

Authorize ssh access

to authorise ssh access, create an empty file called ssh in the /boot/ folder on the partition (WITHOUT EXTENSION)

Configuring the WiFi connection

At the root of the partition, create a file wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Recover your Raspberry Pi’s IP address

There are several ways to recover the IP address of your Raspberry Pi.

  1. use your box’s management page to display connections
  2. scan IP addresses using arp -a (Windows

Connecting with ssh

If the Raspberry Pi is connected to the network, it can be accessed via ssh with the ip address, login and password. By default, the logins are:

  • login: pi
  • password: raspberry
ssh pi@ #replace with raspberry pi ip adress

You can now access your Raspberry Pi in Headless mode. To make it easier to use in this mode, here are a few tips.

Browsing on multiple terminals

You can navigate through different terminal tabs using the Alt+F1-F12 keys, allowing you to run up to 12 terminals in parallel. This can be very handy when you want to:

  • run tasks in parallel
  • perform tasks with different users
  • run continuous tasks such as htop in the background

Copy the contents of a USB stick

the usb stick should appear under media

To check that the USB key has been recognized, enter the following command and note the volume name (in this case sda1)

lsblk --fs

To mount the USB key in a folder, we use the mount command.

mkdir /home/pi/mntusb
sudo mount /dev/sda1 /home/pi/mntusb

Once the USB key has been mounted correctly, you can copy the files to your Raspberry with the cp command

cp home/pi/mntusb/myfile.txt home/pi/myfile.txt

N.B.: If exfat is not recognized, enter

sudo apt-get install exfat-fuse exfat-utils

Then reboot the Raspberry Pi

Before removing your storage volume, use the umount command

sudo umount /dev/sda1