Mounting an mtdblock (rootfs_data) as rw partition

Hi All,

New to openWRT filesystems and partitions, Any suggestions on the below would be helpful.
For development purposes I would want the root "/" directory to be read write,
thus allowing any file creation.

Since root dir / is mounted as ro, facing a lot of issues while exection of some scripts, errors similar to below one:

mkdir: can't create directory '/cfg/': Read-only file system
cp: can't create directory '/cfg/default/': No such file or directory
cp: can't stat '/cfg/default/ini/global.ini': No such file or directory
sed: can't create temp file '/ini/global.iniXXXXXX': Read-only file system
/sbin/wifi: eval: line 1: can't create /ini/global.ini: Read-only file system

As of now, not able to modify the squashfs /dev/mtdblock18 as a rw partition.
Below is the log from device, displaying mount and partitions.

root@RuckusAP:/# mount
/dev/mtdblock18 on / type squashfs (ro,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,noatime,mode=700)
ubi2:data on /writable type ubifs (rw,sync,relatime,assert=read-only,ubi=2,vol=0)
root@RuckusAP:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 0c000000 00020000 "rcks_wlan.main"
mtd1: 0c000000 00020000 "rcks_wlan.bkup"
mtd2: 08000000 00020000 "datafs"
mtd3: 00800000 00010000 "NOR"
mtd4: 00050000 00010000 "SBL1"
mtd5: 00010000 00010000 "MIBIB"
mtd6: 00020000 00010000 "BOOTCONFIG"
mtd7: 00080000 00010000 "ART"
mtd8: 00040000 00010000 "RPM"
mtd9: 00010000 00010000 "CDT"
mtd10: 00010000 00010000 "APPSBLENV"
mtd11: 000a0000 00010000 "APPSBL"
mtd12: 00020000 00010000 "BOOTCONFIG1"
mtd13: 00180000 00010000 "QSEE"
mtd14: 00010000 00010000 "DEVCFG"
mtd15: 00010000 00010000 "APDP"
mtd16: 00010000 00010000 "Board Data"
mtd17: 003e0000 0001f000 "kernel"
mtd18: 03546000 0001f000 "ubi_rootfs"
mtd19: 00410000 0001f000 "kernel"
mtd20: 02ef6000 0001f000 "ubi_rootfs"
mtd21: 06e13000 0001f000 "data"

Below is the snippet from image Makefile:

define Image/Build
echo "...................Image/Build/127....................." >&2
#$(call Image/Build/$(1),$(1))
dd if=$(KDIR)/root.squashfs of=$(BIN_DIR)/squashfs-root.img bs=2k conv=sync
endef

Other similar errors:
touch: /etc/config/network: Read-only file system

Thanks in adv!
DR

1 Like

kmod-mtd-rw ?

Hey @frollic , its not enabled in the configs, will try it out once. Ty for the quick revert :slight_smile:

squashfs is a read-only filesystem, you can't write to it, regardless of what you do - but OpenWrt spans an overlayfs over it, so it appears to be (virtually) writable (later on in the boot process).

1 Like

It is still the same @frollic , coz of failure to insmod,

root@RuckusAP:/# insmod mtd-rw.ko
insmod mtd-rw.ko
[ 2316.557721] mtd-rw: must specify i_want_a_brick=1 to continue
failed to insert /lib/modules/5.4.164/mtd-rw.ko
root@RuckusAP:/#
root@RuckusAP:/#

 

root@RuckusAP:/#
root@RuckusAP:/#

 

root@RuckusAP:/#
root@RuckusAP:/# mount
mount
/dev/mtdblock18 on / type squashfs (ro,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,noatime,mode=700)
ubi2:data on /writable type ubifs (rw,sync,relatime,assert=read-only,ubi=2,vol=0)
root@RuckusAP:/#
root@RuckusAP:/#

 

root@RuckusAP:/#
root@RuckusAP:/#

 

root@RuckusAP:/#
root@RuckusAP:/# mkdir cfg
mkdir cfg
mkdir: can't create directory 'cfg': Read-only file system

yes @slh , i also came across that yhere needs to be an overlay that sits on top of squashfs to make it writeable. Will need to explore on the same to understand the changes that i need to make.

Thanks,
DR

And you didn't fix the failure but supplying the required safety argument for insmod????

insmod mtd-rw.ko i_want_a_brick=1

Ps. But like others have already said, you likely want the normal r/o ROM + r/w overlay, like most OpenWrt routers do.

i did try this out, but it kept throwing subsequent errors and insmod failed.
And yea, have enabled overlayfs in configs, will need to look at other changes required.

errors like:


[   77.128241] ubi2 error: 0x806aefe8: cannot open device 2, volume 0, error -16
[   77.128267] mtd-rw: mtd21: error -16
[   77.134340] mtd-rw: no partitions to unlock
failed to insert /lib/modules/5.4.164/mtd-rw.ko

Which hardware and which version/release of OpenWrt are you running?

Did you configure the read-write overlay to end up in /writable?! For things to work as intended, the read-write filesystem should end up in /overlay...

Hi Daniel,

OpenWRT version is 21.04 for ipq807x target.
Yes, I get to see a sys_init script under /etc/init.d/ in the development SDK dropped to me. which does the mounting you are pointing to.
mount -t ubifs -o sync ubi2:data /writable

_grep_datafs
if [ ${data_num} -lt 20 ]; then
    ubiattach /dev/ubi_ctrl -m 0 2>/dev/null
    ubiattach /dev/ubi_ctrl -m 1 2>/dev/null
    ubiattach /dev/ubi_ctrl -m 2 2>/dev/null
    mount -t ubifs -o sync ubi2:data /writable
    cat /proc/mounts | grep writable 2>/dev/null
    if [ $? -ne 0 ] ; then
        model=`cat /proc/v54bsp/model`
        ubidetach /dev/ubi_ctrl -m 2
        ubiformat /dev/mtd2
        ubiattach /dev/ubi_ctrl -m 2
        if [ -f /proc/v54bsp/vid ]; then
            if [ $model == "r610" -o $model == "R610" ]
            then
                # 64MB partition
                ubimkvol /dev/ubi2 -N data -s 56MiB
            else
                # 128MB partition, R710, T710
                ubimkvol /dev/ubi2 -N data -s 110MiB
            fi
        else
            # ap148
            ubimkvol /dev/ubi2 -N data -s 58MiB
        fi
        mount -t ubifs -o sync ubi2:data /writable
    fi
        if [ ! -d /writable/etc ]; then
                mkdir /writable/etc
        fi
else
    echo "*** Cannot find datafs partition" >&2
fi

Regards,
DR

I'm sorry, but this is Qualcomm SDK and not OpenWrt, and it's a total mess. I have never touched it, and if you asked me, nobody ever should :wink: