How to debug problem with unmountable /overlay/upper (and non-persistent root) in BPI-R4?

My current OpenWRT 24.10. BPI-R4 installed into the eMMC storage does not persist settings.

OpenWRT configuration

I have built a custom image for BPI-R4 from sources, using the latest openwrt-24.10 branch.

Among other things, it includes docker and dockerd. My image is much larger to fit into the ramdisk, so I disabled this option to embed the root filesystem into the kernel (TARGET_ROOTFS_INITRAMFS=n).

System installation

  1. I have flashed the SD card, and confirmed my system boots.
  2. Using UART and a uboot option, I installed the system on NVRAM.
  3. I changed the DIP switches to boot from NVRAM, and confirmed my system works.
  4. Using cfdisk I resized the /dev/mmcblk0p5 partition to fit all the available 8GB of eMMC space - although the problem appears also without resizing it.
  5. Using UART, I installed the system on eMMC.
  6. System works, but the settings are non-permanent. Here's the serial dump of system startup:

Logs

Serial dump, incl. dmesg:
https://pastebin.ubuntu.com/p/Gwhkkr4dXf/

I followed the problem to non-working upper fs.

root@OpenWrt:~# lsblk --all -o "NAME,SIZE,MODE,PARTLABEL,PARTUUID,SUBSYSTEMS"
NAME           SIZE MODE       PARTLABEL  PARTUUID                             SUBSYSTEMS
loop0            0B brw-------                                                 block
loop1            0B brw-------                                                 block
loop2            0B brw-------                                                 block
loop3            0B brw-------                                                 block
loop4            0B brw-------                                                 block
loop5            0B brw-------                                                 block
loop6            0B brw-------                                                 block
loop7            0B brw-------                                                 block
mtdblock0        2M brw-------                                                 block:mtd:spi:spi_master:platform
mtdblock1      126M brw-------                                                 block:mtd:spi:spi_master:platform
mmcblk0        7.3G brw-------                                                 block:mmc:mmc_host:platform
├─mmcblk0p1    512K brw------- ubootenv   5452574f-2211-4433-5566-778899aabb01 block:mmc:mmc_host:platform
├─mmcblk0p2      2M brw------- factory    5452574f-2211-4433-5566-778899aabb02 block:mmc:mmc_host:platform
├─mmcblk0p3      4M brw------- fip        5452574f-2211-4433-5566-778899aabb03 block:mmc:mmc_host:platform
├─mmcblk0p4     32M brw------- recovery   5452574f-2211-4433-5566-778899aabb04 block:mmc:mmc_host:platform
├─mmcblk0p5    7.2G brw------- production 5452574f-2211-4433-5566-778899aabb05 block:mmc:mmc_host:platform
└─mmcblk0p128    4M brw-------            5452574f-2211-4433-5566-778899aabb80 block:mmc:mmc_host:platform
mmcblk0boot0     4M brw-------                                                 block:mmc:mmc_host:platform
mmcblk0boot1     4M brw-------                                                 block:mmc:mmc_host:platform
ubiblock0_3   97.7M brw-------                                                 block:ubi:mtd:spi:spi_master:platform
fit0            92M brw-------                                                 block:platform
fitrw          7.1G brw-------                                                 block:platform
root@OpenWrt:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00200000 00020000 "bl2"
mtd1: 07e00000 00020000 "ubi"

The 0x00200000 corresponds to 22^20 (2MB), and 0x07e00000 is 1262^20 (126MB). 128MB is the size of NAND memory, and sure enough - reading dmesg confirms that these entries show that MTD uses only NAND. This is NOT where I want the data to be stored.

root@OpenWrt:~# mount
/dev/root on /rom type squashfs (ro,relatime,errors=continue)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /tmp/root type tmpfs (rw,noatime,mode=755)
overlayfs:/tmp/root on / type overlay (rw,noatime,lowerdir=/,upperdir=/tmp/root/upper,workdir=/tmp/root/work,uuid=on,xino=off)
tmpfs on /dev type tmpfs (rw,nosuid,noexec,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,noatime)
bpffs on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,noatime,mode=700)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,noatime)
mountd(pid2882) on /tmp/run/blockd type autofs (rw,relatime,fd=7,pgrp=2882,timeout=30,minproto=5,maxproto=5,indirect)
overlayfs:/tmp/root on /opt/docker type overlay (rw,noatime,lowerdir=/,upperdir=/tmp/root/upper,workdir=/tmp/root/work,uuid=on,xino=off)
root@OpenWrt:~# mkdir mnt
root@OpenWrt:~# mount /dev/fitrw mnt
mount: mounting /dev/fitrw on mnt failed: Invalid argument
root@OpenWrt:~# mount /dev/mmcblk0p5 mnt
mount: mounting /dev/mmcblk0p5 on mnt failed: Resource busy
root@OpenWrt:~# block info
/dev/ubi0_5: UUID="948a19eb-c241-4b53-82d3-12bc844225fe" VERSION="w5r0" TYPE="ubifs"
/dev/fit0: UUID="9591bd08-e95a8e93-7ab0c60f-324a0020" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"

Formatting the file system into UBIFS fails mysteriously:

libmtd: error!: "/dev/mmcblk0p5" is not a character device
ubiformat: error!: cannot get information about "/dev/mmcblk0p5"
           error 22 (Invalid argument)
root@OpenWrt:~# ubiformat /dev/fitrw
libmtd: error!: "/dev/fitrw" is not a character device
ubiformat: error!: cannot get information about "/dev/fitrw"
           error 22 (Invalid argument)

Remarks

Interesting thing is that I can't see the UUID of partitions seen by the block in the lsblk output. I suspect I miss some fundamental background information to understand, what is going on with my system.

Your image is missing mkf2fs (although it's a device default package)

[   12.159811] mount_root: overlay filesystem in /dev/fitrw has not been formatted yet                                                                               
sh: mkfs.f2fs: not f[   12.171492] mount_root: no usable overlay filesystem found, using tmpfs overlay                                                               
ound