Skip to content

Background

Tom Hodder edited this page Sep 15, 2021 · 3 revisions

intro

A typical raspbian Pi OS image contains 2 partitions, one with the boot partition and the other with the root partition containing the OS.

It looks like this:

[raspberry-pi-factory-reset] $ fdisk -l ./2021-05-07-raspios-buster-armhf.img
Disk ./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
./2021-05-07-raspios-buster-armhf.img1        8192  532479  524288  256M     c      W95   FAT32 (LBA)
./2021-05-07-raspios-buster-armhf.img2      532480 7774207 7241728  3.5G     83     Linux

In order to factory reset the rpi, we would need to replace the contents of the second partition with a fresh copy. Unfortunately a zipped copy of p2 is much larger than the available space on the p1 (boot) partition, so it would have to go somewhere else. (putting it on the network, such as an NFS/smb share is a possibility. but in the case I wanted a stand alone solution)

The simplest thing would be to add another partition at the end containing the zipped root img. However the problem with this, is that on first boot, the p2 is resized to completely fill the remaining disk, (and this wouldn't be possible if the recovery partition was in the way)

These days, sdcards are pretty cheap and 32GB and 64GB cards are available cheaply, so it would be possible to add another partition in between p1 (boot) and p2 (root) and put a fresh zipped copy of the p2 partition in there. This would solve the problem of blocking the resizer, but its much more complicated as it requires various brain surgery on the img.

Clone this wiki locally