When flashing an SD card with the Raspberry Pi Imager, it will create two partitions : bootfs and rootfs. We will make backups of these partitions on the SD card, so we can restore them when needed (so we will end up with 4 partitions instead of 2).
-
Install an OS on your SD card with the Raspberry Pi Imager. Do not boot the Raspberry with the SD card yet!
-
Mount the
bootfspartition. In thecmdline.txtfile, changeroot=PARTUUID=xxxxxxxx-02toroot=PARTUUID=xxxxxxxx-04. The idea here is that we'll use the partition 4 for the actual system root, and use partitions 2 and 3 as a backup that we'll restore to partitions 1 and 4 when resetting the system. We need to use the last partition as the filesystem root, because during first boot the root partition will be extended to span the whole free space, and it won't work if it isn't the last one.
When done, unmount the partition. -
Mount the
rootfspartition, and in/etc/fstab, changePARTUUID=xxxxxxxx-02 /toPARTUUID=xxxxxxxx-04 /. -
From the root of the
rootfspartition, runsudo sfdisk --disk-id /dev/mmcblk0 | sudo tee etc/rpi-disk-id(change/dev/mmcblk0to the SD card's block device). -
Download the
raspi-resetscript tousr/local/sbin/in therootfspartition, and give it execute permission (chmod +x raspi-reset):cd usr/local/sbin/ sudo wget https://raw.githubusercontent.com/yayuniversal/raspi-reset/refs/heads/main/raspi-reset chmod +x raspi-resetWhen done unmount the
rootfspartition.
From here, both partitions should be unmounted.
- Open the SD card with GParted or any other partition editor. The partition schema should look like this:
-
Copy the
bootfspartition, by right-clicking on it, then paste it in the beginning of the free space on the right -
Do the same for the
rootfspartition, and apply the changes. The resulting partition schema should look like this:
The partitions must be numbered in this order: partitions 1 and 2 should be the original bootfs and rootfs, partition 3 should be the cloned bootfs, and partition 4 the cloned rootfs.
Now, you can use the SD card with your Raspberry Pi. When you want to reset the system, just run sudo raspi-reset! It may be a good idea to run it inside a screen or tmux session, so in case your internet connection goes down during the process, your Raspberry Pi isn't left in an unusable state.

