Creating backup image and shrinking size

Topics about the Software of Revolution Pi
Post Reply
duelingcats
Posts: 11
Joined: 14 Nov 2024, 07:34

Creating backup image and shrinking size

Post by duelingcats »

I have a revpi connect 4 that I have setup with the necessary software and packages I need and want to duplicate that configuration to several more connect 4 units we have as well as any other additional ones that we acquire.

The simplest way I could think of was using Win32 Disk Imager to create a backup image and then flashing that to all the other connect 4 units.

My question is the following:
Is there a way to shrink the image? The 32gb image takes quite a while to flash to the device and shrinking it would be ideal.
Will running revpi-factory-reset reset the serial/hostname as well as password and mac address?
User avatar
RamiGspo
KUNBUS
Posts: 64
Joined: 02 Jun 2022, 23:20

Re: Creating backup image and shrinking size

Post by RamiGspo »

Hello duelingcats,

To reduce the size of your image, you can take a look to our `shrink_image.sh` script which you'll find in our ImageBakery repository: https://gitlab.com/revolutionpi/imagebakery. This script was designed specifically for this purpose and it reduces the image size by removing unused space and adjusting partitions to the minimum required size.

The script performs the following main operations: mounts the image, removes the machine-id file to trigger the firstboot service, checks filesystem integrity, shrinks the ext4 partition to the minimum necessary size using resize2fs, adjusts the partition size with parted, and finally truncates the image to the new size. This can significantly reduce flashing time.
The automatic filesystem expansion on first boot should be triggered after removing the file machine-id. This script was used in our images up to Bullseye.

Regarding your second question about revpi-factory-reset, what it actually does is initialize the RevPi hardware by loading the necessary device overlays and changing the password. It also resets the hostname based on the device's serial number, but doesn't affect the MAC address as this is stored in the HAT EEPROM. (See here: https://gitlab.com/revolutionpi/revpi-t ... type=heads)

However, I don't like copying images and using them on different devices :!: This approach means all hostnames will be identical initially, and certain certificates that are generated the first time the system boots may cause issues. While this method might have worked well in the past and could still be acceptable for some RevPi deployments, I honestly believe there are better tools available for system provisioning that can create cleaner setups and replicate the same environment across different RevPi devices much more effectively.

Tools like Ansible, for example, allow you to define your system configuration as code and deploy it consistently across multiple devices while ensuring each device maintains its unique identity (hostname, certificates, etc.). This approach is more scalable, maintainable, and avoids the potential issues that come with cloned images. You start with a fresh RevPi image on each device and then use configuration management tools to install and configure exactly what you need.

What particularly bothers me about the image cloning approach is that sometimes, when an issue arises, a new image needs to be generated, and this new image... must be reinstalled on all the systems? If one device is located remotely, this becomes a significant problem requiring physical access or on-site intervention. If you can do an update, there shouldn't be much of a problem... but I still think something like Ansible is better, for example. With just one command, you can update one device, several devices, or just a few... Having these options can save you a lot of headaches in the future.

If you still prefer the image cloning approach, you can use Win32 Disk Imager to create the image of your configured system, apply the shrink_image.sh script to reduce its size, and then flash this reduced image to other devices. I do not like it... but it should work. After the first boot, each device will have its own unique hostname based on its specific serial number, but will maintain all your software configuration.

I recommend testing the reduced image on at least one device before proceeding with mass flashing to ensure everything works correctly.

For reference, our latest image is the RevPi Bookworm 64-Bit from November 2025 (https://revolutionpi.com/en/support/downloads#c1069), and we're already working on Trixie images for future releases. After launching trixie, we will no longer support Bullseye, so I recommend using a recent system.

Good luck!
Mit freundlichen Grüßen | Best regards | Muchas gracias

Ramiro Gsponer.
duelingcats
Posts: 11
Joined: 14 Nov 2024, 07:34

Re: Creating backup image and shrinking size

Post by duelingcats »

Thank you for the information. Based upon your suggestion, I have been going down the path to see if I can download the latest available RevPi image, download the available updates, and then copy and install those updates to subsequent devices after installing the same OS image.

Downloading and installing packages seems to be simple enough with the following scripts to download and then install on other devices.

Code: Select all

#!/bin/bash
set -e

TARGET_DIR="$HOME/package_updates"

echo "Creating package directory: $TARGET_DIR"
mkdir -p "$TARGET_DIR"

echo "Updating package lists..."
sudo apt update

echo "Downloading upgrade packages..."
sudo apt-get upgrade --download-only \
  -o Dir::Cache::archives="$TARGET_DIR" \
  -o Dir::Cache::archives::partial="$TARGET_DIR/partial"

echo "Done."
echo "Packages downloaded to: $TARGET_DIR"

Code: Select all

#!/bin/bash

sudo apt-get upgrade \
  -o Dir::Cache::archives="$HOME/package_updates"
The one part I am having trouble with is figuring out how to download node-red along with the supporting necessary packages pre-installation. I found that node-red is not installed by default, and clicking install runs scripts in the background to initiate the download and installation. On my development RevPi unit I am trying to download node-red and necessary dependencies to a directory so that I can copy and install it on subsequent revpi units later.

These production revpi units are cut off from the internet and that is why I am having to do all this downloading of updates/software offline. Connecting them up to the internet just for these updates/installation is not an option at the moment due to business decisions that I cannot overrule unfortunately. That is why I was thinking of making a image of everything installed and copying it over, but like you said that could be messy. Ideally I can download these items (revpi-nodered, revpi-nodered-proxy-apache, noderedrevpinodes-server, cockpit-revpi-nodered, revpi-nodered-proxy-firewalld) in a directory, copy said directory, then install them on the units I copy it to.

Would there be a clean way to do that?
duelingcats
Posts: 11
Joined: 14 Nov 2024, 07:34

Re: Creating backup image and shrinking size

Post by duelingcats »

I found that revpi-nodered, revpi-nodered-proxy-apache, noderedrevpinodes-server, cockpit-revpi-nodered, revpi-nodered-proxy-firewalld were just packages and installing them via apt worked.
Post Reply