[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
In total, need to ensure
- kmod-mtd-rw is installed
- UBI volume is created
- Device rebooted
- Extroot configured
- Device rebooted
- Boot script attaches the UBI device
- Boot script performs
mount_root