Skip to content
Tom Hodder edited this page Nov 16, 2021 · 9 revisions

⚠️ This code was originally developed for a project back in 2018/2019: I'm no longer actively working with rPi on a day to day basis, so I won't be adding features, and will only fix bugs if I get the time. If someone wants to take over the project with a fork, I'd be happy to point users to it!

⚠️ Please use the ideas here as a reference: but it isn't going to be kept up to date.

Background to making a raspberry pi reset tool.

A common technique for providing for rescue of filesystem or OS level issues is to provide an alternative bootable partition, which can be used to repair a failed (or otherwise messed up) situation. For example my Dell laptop has a rescue partition which can be used to restore the laptop to a factory state. This sort of thing inspired me to come up with a similar technique for resetting a raspberry pi.

The default Pi OS image looks like the following:

$ sfdisk -g -l  ./sources/2021-05-07-raspios-buster-armhf.img
Disk ./sources/2021-05-07-raspios-buster-armhf.img: 3.71 GiB, 3980394496 bytes, 7774208 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf4481065

Device                                         Boot  Start     End Sectors  Size Id Type
./sources/2021-05-07-raspios-buster-armhf.img1        8192  532479  524288  256M  c W95 FAT32 (LBA)
./sources/2021-05-07-raspios-buster-armhf.img2      532480 7774207 7241728  3.5G 83 Linux

This is a disk image with 2 partitions. The first is a vfat partition which gets mounted on /boot and a bigger ext4 filesystem which gets mounted on /

The typical flash and boot process goes like this:

The basic idea for recovery partitions is something like this

the initial attempt at the reset script added a recovery partition after the root partition in the unpartitioned space, this works for the simple case, but if you actually want to use all the empty space, it's not a good solution

So we put the recovery partition in before the root partition

The script now has to calculate how much space is available on what is being used as the recovery partition, and if necessary expand it to make space of the zipped root=/ partition. This is fairly simple for smaller images, you can just pad it would with a generous amount. However it becomes complicated when dealing with "Full" and "Desktop" images

Clone this wiki locally