The correct way to expand the MicroSD card root partition for OpenWrt

The correct way to expand the MicroSD card root partition for OpenWrt

I recently purchased a FriendlyARM NanoPi R4S I plan to use as a router in a project I’ll blog about later on, so I downloaded the firmware image and flashed it onto the 64 GB MicroSD card using balenaEtcher. Although very simple and convenient, the main disadvantage with these prepared images is the static and way-too-small root partition size. It took a bit of searching to find the instructions that actually work, so here they are.

Log into your OpenWrt instance via SSH and install these prerequisites:

opkg update
opkg install parted losetup resize2fs

Now you can download and execute a helper script which will add the expansion to 100% free space on next boot:

wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"
. ./expand-root.sh

Reboot the device whenever convenient and afterwards you should see tons of new space using df -h:

Filesystem                Size      Used Available Use% Mounted on
/dev/root                58.7G    219.7M     58.4G   0% /
tmpfs                     1.9G      1.0M      1.9G   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/root                58.7G    219.7M     58.4G   0% /opt/docker

EDIT: these instructions in the related repository did not work for me.