Skip to content

Instantly share code, notes, and snippets.

@maxwellb
Last active April 8, 2025 08:47
Show Gist options
  • Save maxwellb/bcd2e25b45ff83cdff7f1468e718e40d to your computer and use it in GitHub Desktop.
Save maxwellb/bcd2e25b45ff83cdff7f1468e718e40d to your computer and use it in GitHub Desktop.
Netgear R6220 (mt7621)

My OpenWrt configuration notes

[OpenWrt Wiki] NETGEAR R6220

[OpenWrt Wiki] Extroot configuration

Activating more storage

apk update
apk add block-mount
apk add kmod-mtd-rw
insmod mtd-rw i_want_a_brick=1
ubiattach -p /dev/mtd5
ubimkvol /dev/ubi1 -N extroot -m
ubiblock -c /dev/ubi1_0

cat <<EOF > /etc/init.d/attachubi
#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2013-2020 OpenWrt.org

START=10
STOP=98

boot() {
  insmod mtd-rw i_want_a_brick=1
  ubiattach -p /dev/mtd5
}

start() {
  return 0
}

restart() {
  return 0
}

stop() {
  ubidetach -p /dev/mtd5
  rmmod mtd-rw
}

EOF
chmod +x /etc/init.d/attachubi
/etc/init.d/attachubi enable

reboot

Configuring extroot

DEVICE=/dev/ubi1_0
#skip: eval $(block info ${DEVICE} | grep -o -e 'UUID="\S*"')
eval $(block info | grep -o -e 'MOUNT="\S*/overlay"')
uci -q delete fstab.extroot
uci set fstab.extroot="mount"
#skip: uci set fstab.extroot.uuid="${UUID}"
uci set fstab.extroot.device="${DEVICE}"
uci set fstab.extroot.target="${MOUNT}"
uci commit fstab

uci -q delete fstab.rwm
uci set fstab.rwm="mount"
uci set fstab.rwm.device="/dev/ubi0_1"
uci set fstab.rwm.target="/rwm"
uci commit fstab

mount -t ubifs /dev/ubi1_0 /mnt
tar -C ${MOUNT} -cvf - . | tar -C /mnt -xf -

reboot

Troubleshooting

## Analyze the preinit stage of the boot log:
block info; uci show fstab; logread | sed -n -e "/- preinit -/,/- init -/p"

#> Tue Apr  8 07:22:52 2025 user.info kernel: [   12.775191] mount_root: loading kmods from internal overlay
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   12.808784] kmodloader: loading kernel modules from /tmp/overlay/upper/etc/modules-boot.d/*
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   12.827738] kmodloader: done loading kernel modules from /tmp/overlay/upper/etc/modules-boot.d/*
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   12.941469] block: attempting to load /tmp/overlay/upper/etc/config/fstab
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   12.960306] block: extroot: device not present, retrying in 5 seconds
#> Tue Apr  8 07:22:52 2025 user.err  kernel: [   17.994089] block: extroot: cannot find device ubi1_0
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   18.009997] block: attempting to load /tmp/ubifs_cfg/upper/etc/config/fstab
#> Tue Apr  8 07:22:52 2025 user.info kernel: [   18.024730] block: extroot: device not present, retrying in 5 seconds
#> Tue Apr  8 07:22:52 2025 user.err  kernel: [   23.057139] block: extroot: cannot find device ubi1_0

Present status: ubi is not mounted early enough. Try disabling init script (was named ubimount), renaming higher than S10boot (e.g. "attachubi"), and re-enabling... no dice.

Next up, from the Troubleshooting section of Extroot configuration: run mount_root with PREINIT=1 in the environment.

Update /etc/init.d/attachubi

cat <<EOF > /etc/init.d/attachubi
#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2013-2020 OpenWrt.org

START=10
STOP=98

boot() {
  insmod mtd-rw i_want_a_brick=1
  ubiattach -p /dev/mtd5
  env - PREINIT=1 /sbin/mount_root
}

start() {
  return 0
}

restart() {
  return 0
}

stop() {
  ubidetach -p /dev/mtd5
  rmmod mtd-rw
}

EOF

Success!

In total, need to ensure

  1. kmod-mtd-rw is installed
  2. UBI volume is created
  3. Device rebooted
  4. Extroot configured
  5. Device rebooted
  6. Boot script attaches the UBI device
  7. Boot script performs mount_root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment