Rpi-mage: self/restore a custom image



While playing on my PiLab i was confronted to the restore my custom image of Raspbian whithout any physical manipulation on all RPIs. This was achieve with the RPI-mage scripts.


The structure:

I order to do so I create another custom image with :

  • The boot partition
  • The restore partition (moebius)
  • The working partition (Customized Raspbian)

The game was to find an light OS and the size of the restore partition to allow the backup to be hosted. The idea of self restore was pretty simple. 

The logic (of restore):

On the working partition  launch a script that will :

  • mount the /boot partition to switch to the restore partition on the next boot
  • unmount cleanly the /boot
  • mount the restore partition to let a flag on it (rc.local)
  • unmout the restore partition
  • reboot

When arriving on the restore partition at the next boot:

  • The restore partition mount the working partition and also the backup partition
  • Restore the customized image on it
  • Unmount the fresh working partition
  • Remove the flag of restoration
  • Mount the boot partition to switch to the brand new working partition on the next boot
  • unmount the boot
  • reboot

After that, the RPI reboot on a the customized image like the first day.

The advantage of this method is that you don't need to touch the devices.

The issues:

I expected some performance issue doing the backup/restore on the same microSD but not that much.
The first tests was around 100-150 ko/s to create or write the backup. So i inspire me with the rpi-clone project by adding an extra device (other microSD or HDD) on one of the Usb port.

Again some poor performances but this time for another reason. The light linux distribution is used (Moebius), use the busybox to emulate some usual tools like (dd, fsdik and so on). All these tools where also in light mod with some missing options i need. I change all the binaries that i need:
* dd
* fdisk
* sfdisk
* netcat

With these new tools i reach the 30 mo/s to backup and to restore the backup.



With these functionnalities, you will be able to backup a set of RPIs to keep your working lab in a secure place.