How to Make Your Openwrt Raspberry Pi 5’s SD Card Actually Useful: Expanding OpenWRT Partition Size

Make sure to choose EXT4, not squashfs, before reading this guide!!!

Finally, OpenWRT 24.10 was released, and it’s the first stable version to support the Raspberry Pi 5. I downloaded the factory file, burned it to my SD card, and plugged it in to test out OpenWRT.

0x1 Unallocated SD Card Space

If you’re not living in the stone age, you probably have an SD card that’s larger than 32GB. However, the default OpenWRT build only gives you about 104MB for the overlay rootfs, leaving about 30GB of unallocated memory just sitting there, wasting away.

Here’s how the partition table looks:

Device        Boot  Start    End Sectors  Size Id Type
/dev/loop21p1 *      8192 139263  131072   64M  c W95 FAT32 (LBA)
/dev/loop21p2      147456 360447  212992  104M 83 Linux

I’m sure you’re not happy with this. “Why the hell did I buy a 32GB card if only 104MB is usable?” It’s totally unacceptable.

0x2 Frustration

I searched through Google, Reddit, ChatGPT, Deepseek, and OpenWRT docs, and nothing worked.

The official OpenWRT script? Didn’t work and rendered my Raspberry Pi 5 unbootable.

Manually adjusting the partition with GParted? Nope, that caused it to fail to boot too.

Using fdisk and resize2fs? Also a no-go. Once you adjust the partition, Raspberry Pi 5 just won’t boot.

After wasting countless hours, I stumbled upon a Chinese blog that suggested expanding the rootfs before burning the image to the SD card.

0x3 Expanding the Partition Directly in the IMG File

After decompressing the .gz file you downloaded from the OpenWRT website, you’ll get an .img file. To expand this image file by about 29GB (or more, depending on your needs), run the following command:

dd if=/dev/zero bs=29M count=1024 >> openwrt-24.10.0-a06b1da47981-bcm27xx-bcm2712-rpi-5-ext4-factory.img

Boom! Now you have a significantly larger image file. No worries, everything’s fine.

Next, let’s set up a loop device:

losetup -f ./openwrt-24.10.0-a06b1da47981-bcm27xx-bcm2712-rpi-5-ext4-factory.img

Your output should look something like this (don’t panic, you’re doing it right):

root@pwn:/tmp# losetup
NAME        SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                                                                DIO LOG-SEC
/dev/loop21         0      0         0  0 /tmp/openwrt-24.10.0-a06b1da47981-bcm27xx-bcm2712-rpi-5-ext4-factory.img   0     512

In my case, the device is /dev/loop21.

Now load the partition and check it:

partx -a /dev/loop21
lsblk

At this point, you’ll see your partitions. But guess what? The partition is still not expanded. It’s like giving a kid a bigger toy, but telling them they can’t actually play with it. Let’s fix that.

Now for the Fun Part: Expanding the Partition

Run fdisk:

fdisk /dev/loop21

In fdisk, type p to print the current partition layout:

Command (m for help): p
Disk /dev/loop21: 29.17 GiB, 31323062272 bytes, 61177856 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: 0x661a1cf7

Device        Boot  Start    End Sectors  Size Id Type
/dev/loop21p1 *      8192 139263  131072   64M  c W95 FAT32 (LBA)
/dev/loop21p2      147456 360447  212992  104M 83 Linux

Then, delete the second partition and recreate it with the same starting sector. Don’t worry, we’re not deleting data – we’re just reshaping things:

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-61177855, default 2048): 147456
Last sector, +/-sectors or +/-size{K,M,G,T,P} (147456-61177855, default 61177855): 

NOTE: the first sector of newly created partition MUST match the old one!

Make sure not to remove the ext4 signature when asked. Trust me, you don’t want to mess this up.

Once you’re done, write the changes:

Command (m for help): w

Now, update the partition with partx and verify it:

partx -u /dev/loop21
lsblk

You should now see that /dev/loop21p2 has the expanded size.

Time to Resize the Filesystem!

Next, run e2fsck to check the file system for errors:

e2fsck -f /dev/loop21p2

You’ll get a few warnings. Just accept them, it’s all part of the fun!

Finally, resize the filesystem using resize2fs:

resize2fs /dev/loop21p2

Now your partition is resized! You can detach the loop device with:

partx -d /dev/loop21
losetup -d /dev/loop21

Your .img file is now much larger, but let’s shrink it down with gzip to save space:

gzip ./openwrt-24.10.0-a06b1da47981-bcm27xx-bcm2712-rpi-5-ext4-factory.img

The compressed file will be much smaller. For me, it came out to 42MB. Burn it to your SD card using Rufus, and you’re good to go!

0x4 Final Thoughts

I still don’t understand why so many guides and scripts on the internet fail or make the Raspberry Pi 5 unbootable. It’s a mystery of the universe.

By following this guide, you’ll have a custom OpenWRT image that takes full advantage of your SD card’s space. Reinstalling your system? No sweat. Hopefully, future updates won’t break this, but for now, I’m just glad to finally use the full capacity of my SD card.