BPi-R64-V1.1 OpenWRT Image expansion

Hello everyone,

I’ve succesfully flashed OpenWrt to my R64’s eMMC as described in the OpenWrt-Wiki. Now I’m not sure how to proceed to make all 8GB eMMC-Flash of my R64 available to OpenWrt.

Here’s what I’ve done so far:

  • Boot from SD
  • Resize partition /dev/mmcblk0p66 (/overlay) with parted:

parted resizepart /dev/mmcblk0p66 8GB

  • Resize f2fs-filesystem:

resize.f2fs -s /dev/mmcblk0p66

This is the resize.f2fs-output:

root@OpenWrt:/# resize.f2fs -s /dev/mmcblk0p66 Info: Segments per section = 1 Info: Sections per zone = 1 Info: sector size = 512 Info: total sectors = 15167775 (7406 MB) Info: MKFS version "Linux version 5.10.92 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r18633-145d896e0e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Sun Jan 23 20:20:53 2022" Info: FSCK version from "Linux version 5.10.92 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r18633-145d896e0e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Sun Jan 23 20:20:53 2022" to "Linux version 5.10.92 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r18633-145d896e0e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Sun Jan 23 20:20:53 2022" Info: superblock features = 0 : Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000 Info: total FS sectors = 192832 (94 MB) Info: CKPT version = 8f5dc91 [f2fs_do_mount:3526] Mount unclean image to replay log first

When I boot from eMMC again the partition size of mmcblk0p66 is 7.2G, but the overlay-filesystem still sits at 92.2M. Not sure what I’m doing wrong, I’d appreciate any help and apologize in advance for any terrible formatting in my first post here!

mmcblk0p65 and mmcblk0p66 are virtual partitions defined by the uImage.FIT structure. You can’t edit them. If you want to increase the size of the overlay, you need to resize the production partition which is mmcblk0p4 (on eMMC) or mmcblk0p5 (on SD Card), they should also show up in parted.

As most filesystems will refuse resizing while mounted, the way to go is to hold the button during boot or use serial console to boot into recovery/initramfs image which resides entirely in RAM with no disk volumes mounted during runtime and hence allows for this kind of operations.

Using all the eMMC as overlay filesystem is probably not the best solution. The content of the overlay filesystem is lost on sysupgrade (apart from configuration and small things you can add to /etc/sysupgrade.conf) and many applications require using a filesystem directly instead of overlayfs (e.g. Docker, because you can’t have one overlayfs as the lowerdir of another overlayfs).

I’d hence recommend you to install autopart and uvol which allows you to easily create additional dynamic storage volumes and have services depend on them being mounted, as that’s the preferred way to handle data storage on OpenWrt. See the init scripts of PostgreSQL, Transmission and nfs-kernel-server in OpenWrt for examples making use of that feature.

1 Like

Thank you for your reply. After undoing the “damage” I did, I have now installed autopart and uvol, which created an additional 7.1G-partition, mmcblk0p5. I ran mkfs.f2fs on this partition and was able to mount it afterwards. This means I can utilize the whole eMMC. I realize I have a lot of reading up to do on how OpenWrt utilizes storage for packages etc but you put me in the right direction. Thanks a bunch.

autopart creates that partition and initializes it as LVM2-managed physical volume. You can then create volumes (which are automatically formatted and auto-mounted) using

uvol create foobar 5000000000 rw

which will be auto-mounted to /var/run/uvol/foobar.

Using a filesystem directly on the additional partition of course also works, just not as flexible as with LVM2.

This is also for anyone else who comes later, since I suspect you are happily ensconced in your storage paradigm now. But just to be clear, you didn’t do any damage. Using all of eMMC for the overlay is a perfectly acceptable and viable way to use your space. Especially considering the use of extroot in an eMMC environment is still broken in OpenWRT.

You can expand your partitions on the fly and use all the space, no muss no fuss:

  1. Repartition. You used parted, I use fdisk. Either is fine. I like fdisk because it gives fine control. The built in /dev/mmcblk0 partition table looks like this:
Device         Boot Start    End Sectors  Size Id Type
/dev/mmcblk0p1        640   1663    1024  512K 41 PPC PReP Boot
/dev/mmcblk0p2       2048  67583   65536   32M  c W95 FAT32 (LBA)
/dev/mmcblk0p3      69632 282623  212992  104M 83 Linux

Make it look like this:

/dev/mmcblk0p1           512     1535     1024  512K 41 PPC PReP Boot
/dev/mmcblk0p2          2048    67583    65536   32M  c W95 FAT32 (LBA)
/dev/mmcblk0p3         69632 11075583 11005952  5.2G 83 Linux
/dev/mmcblk0p4      11075584 15269887  4194304    2G 82 Linux swap / Solaris

Full fdisk output for that process is at the end of this post.

  1. Once you write the partition table, you can on-the-fly resize:
opkg update
opkg install losetup f2fs-tools f2fsck mkf2fs
OLOOP="$(losetup -n -O NAME | sort | sed -n -e "1p")"
ROOT="$(losetup -n -O BACK-FILE ${OLOOP} | sed -e "s|^|/dev|")"
OFFS="$(losetup -n -O OFFSET ${OLOOP})"
LOOP="$(losetup -f)"
losetup -o ${OFFS} ${LOOP} ${ROOT}
fsck.f2fs -f ${LOOP}
mount ${LOOP} /mnt
umount ${LOOP}
resize.f2fs ${LOOP}

After this IMMEDIATELY do: $ reboot && exit

You’ll have 5.2gb of overlay space and 2gb of swap. Here is the full fdisk output from step 1. The main takeaway from below is don’t remove the existing f2fs signature when it asks:

root@OpenWrt:~# opkg install fdisk
root@OpenWrt:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/mmcblk0: 7.28 GiB, 7818182656 bytes, 15269888 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: 0x5452574f

Device         Boot Start    End Sectors  Size Id Type
/dev/mmcblk0p1        640   1663    1024  512K 41 PPC PReP Boot
/dev/mmcblk0p2       2048  67583   65536   32M  c W95 FAT32 (LBA)
/dev/mmcblk0p3      69632 282623  212992  104M 83 Linux

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

Partition 3 has been deleted.

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

Created a new partition 3 of type 'Linux' and of size 5.2 GiB.
Partition #3 contains a squashfs signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): n
Partition type
   p   primary (3 primary, 0 extended, 1 free)
   e   extended (container for logical partitions)
Select (default e): p

Selected partition 4
First sector (67584-15269887, default 67584): 11075584
Last sector, +/-sectors or +/-size{K,M,G,T,P} (11075584-15269887, default 15269887): 

Created a new partition 4 of type 'Linux' and of size 2 GiB.

Command (m for help): t
Partition number (1-4, default 4): 4
Hex code or alias (type L to list all): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/mmcblk0: 7.28 GiB, 7818182656 bytes, 15269888 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: 0x5452574f

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1           640     1663     1024  512K 41 PPC PReP Boot
/dev/mmcblk0p2          2048    67583    65536   32M  c W95 FAT32 (LBA)
/dev/mmcblk0p3         69632 11075583 11005952  5.2G 83 Linux
/dev/mmcblk0p4      11075584 15269887  4194304    2G 82 Linux swap / Solaris

Command (m for help): w
The partition table has been altered.
Syncing disks.
1 Like