OpenWrt/LEDE Project

  • Status Closed
  • Percent Complete
  • Task Type Bug Report
  • Category Base system
  • Assigned To No-one
  • Operating System All
  • Severity Medium
  • Priority Very Low
  • Reported Version Trunk
  • Due in Version Undecided
  • Due Date Undecided
  • Private
Attached to Project: OpenWrt/LEDE Project
Opened by John - 08.12.2020
Last edited by Ted Hess - 19.11.2021

FS#3492 - sysupgrade from CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=y loses settings where image has BLOCKSIZE:=64k

Test device: ath79 mikrotik wap-g on snapshot r15165-66d12ce667


  1. sysupgrade
  2. change settings
  3. sysupgrade: settings lost


  • settings are found and restored on sysupgrade (after the initial 4K_SECTORS=y to 4K_SECTORS=n upgrade)
  • lose write access for routerboot soft_config (which explicitly requires CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=y, as Openwrt partial erase target/linux/generic/pending-5.4/411-mtd-partial_eraseblock_write.patch had a merge error which was rendering devices unbootable at the time.)
  • faster sysupgrade erase/write time: 45s → 26s

target/linux/generic/pending-5.4/470-mtd-spi-nor-support-limiting-4K-sectors-support-base.patch stopped functioning with linux 4.19
Now all partitions have a 4K erase block if CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=y
This causes mount_root to fail to find upgrade settings where the image is expecting 64K blocksize.

grep --binary-files=text -E 'overlay|upgrade|reboot|mount' ath79_mikrotik_wap-g_sysupgrade_loses_settings 
[    8.892059] mount_root: switching to jffs2 overlay
[    8.899647] overlayfs: upper fs does not support tmpfile.
Mon Dec  7 13:25:31 UTC 2020 upgrade: Sending TERM to remaining processes ... logd hostapd wpa_supplicant netifd odhcpd ntpd dnsmasq ubusd askfirst urngd
Mon Dec  7 13:25:34 UTC 2020 upgrade: Sending KILL to remaining processes ...
Mon Dec  7 13:25:35 UTC 2020 upgrade: Switching to ramdisk...
Mon Dec  7 13:25:38 UTC 2020 upgrade: Performing system upgrade...
Appending jffs2 data from /tmp/sysupgrade.tgz to firmware..
Mon Dec  7 13:26:21 UTC 2020 upgrade: Upgrade completed
Mon Dec  7 13:26:22 UTC 2020 upgrade: Rebooting system...
umount: can't unmount /dev: Resource busy
umount: can't unmount /tmp: Resource busy
[  175.677595] reboot: Restarting system
[    8.611437] mount_root: no usable overlay filesystem found, using tmpfs overlay
[  117.356605] overlayfs: upper fs does not support tmpfile.

./package/base-files/files/lib/preinit/80_mount_root:do_mount_root() {

do_mount_root() {
        boot_run_hook preinit_mount_root
        [ -f /sysupgrade.tgz ] && {
                echo "- config restore -"
                cp /etc/passwd /etc/group /etc/shadow /tmp
                cd /
                tar xzf /sysupgrade.tgz
                missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
                missing_lines /tmp/group /etc/group >> /etc/group
                missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
                rm /tmp/passwd /tmp/group /tmp/shadow
                # Prevent configuration corruption on a power loss

  61         case FS_NONE:
  62                 ULOG_WARN("no usable overlay filesystem found, using tmpfs overlay\n");
  63                 return ramoverlay();
Closed by  Ted Hess
19.11.2021 15:41
Reason for closing:  Fixed
John commented on 04.05.2021 00:51

Note that this is still unchanged, so Mikrotik ath79 devices do not restore config in master or 21.02rc1

Roger commented on 16.07.2021 12:56


Maybe one of these workarounds could be applied for while/if there is no fix for the 4K blocksize problem:

  1. Make soft_config read-only on all the devices, and unset CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  2. Tweak mount_root so that it can find the sysupgrade settings

Each ones comes at a price. With the first one, soft_config will not be modifiable from the userspace. With the second one, writing to SPI will remain very slow although, most likely, this should only be noticeable when sysupgrading, I guess not for single-file editions.

Any ideas on how to implement the second idea, if even possible?

Roger commented on 16.07.2021 16:23
2. Tweak mount_root so that it can find the sysupgrade settings
Any ideas on how to implement the second idea, if even possible?

I can answer myself: using "BLOCKSIZE = 4k" instead of the default 64k when generating the image. Either on each device entry, or for all the mikrotik_nor-type devices. In

define Device/mikrotik_nor
  IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 -e | \
	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
	check-size | append-metadata

Flashing process is still slow, yes, but settings are now kept over upgrades. I tested it on the wAP AC.

@John: What do you think? Would you like to give it a try? Maybe submit a patch?

Roger commented on 03.11.2021 10:13

@johnth, this should be fixed in snapshots and 21.02.1. Does it work for you? If so, we can close the task.


Available keyboard shortcuts


Task Details

Task Editing