How to automatically expand Raspberry Pi root partition on boot like in Ubuntu

I am running OpenWRT on a Raspberry Pi SD Card. After flashing the SD Card, the root partition shows a size of 102M. However, my SD Card is 16GB.

Often, I do a full backup of my SD card by first shrinking the root partition and then using ApplePiBaker to backup the SD card to a .img file.

The problem is that when I reflash a backup image of OpenWRT to an SD card, the root partition is fully shrunk, so there is no capacity left on the SD card.

I tried using the automated expand script, in hopes that I could run it in a crontab, but the script only seems to work for x86.

My question is, how can I make OpenWRT automatically expand the root partition (if it needs expanding) to full capacity upon boot in the same way that Ubuntu does?

Any help is much appreciated!

Giving up, I used fdisk to create a 3rd partition on the remaining SD card space and formatted it with F2FS format. Alternately, I tried a 16GB pendrive in one of the 4 USB slots with the VFAT filesystem driver. The pendrive can be mounted/unmounted through Luci.

This is a PITA but here we go:
Must be using ext4.
You need to know Linux and you need to ro the partition to expand it.
Power down.
Take the sd card out, put it in another linux box or fire up the Pi with Raspberry Os and install gparted. Use an SD card adapter, plug it in.
Use the ro command to change the partition from read only to read write.
Open Gparted.
Expand the file system.
Use ro to return the partition to read only.
Cross your fingers. boot.

Hold on I'll fix it, I misread OP twice.

1 Like