WRT1900 and MTD and UBI and Mounting NonVolatile Flash

wiki.TerraBase.info
Revision as of 19:59, 29 January 2026 by Root (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

All of the below notes are based on a WRT1900ACS device, with OpenWRT 24.10.5, in early 2026. Adjust to your own environment.

First things first! Remember this command: ubidetach -m 7 OR ubidetach -d 2 (adjust per information below)

Why? If you leave it attached, it could affect successful booting. So if you do the below, do the above!


...start here, to get some information: ubinfo (Note: The below is after an additional ubi2 device was attached with command(s) that follow);

ubinfo
UBI version:                    1
Count of UBI devices:           3
UBI control device major/minor: 10:256
Present UBI devices:            ubi0, ubi1, ubi2

And maybe some more info about a specific device: ubinfo -d 2

ubi2
Volumes count:                           2
Logical eraseblock size:                 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks:     272 (34537472 bytes, 32.9 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       0
Count of reserved physical eraseblocks:  20
Current maximum erase counter value:     3
Minimum input/output unit size:          2048 bytes
Character device major/minor:            244:0
Present volumes:                         0, 1

Oh, better yet, some more information: ubinfo -d 2 -n 0

Volume ID:   0 (on ubi2)
Type:        dynamic
Alignment:   1
Size:        58 LEBs (7364608 bytes, 7.0 MiB)
State:       OK
Name:        rootfs
Character device major/minor: 244:1

Wait! What allowed for that above "-d 2" to be attached? This is the command: ubiattach -m 7 -d 2 Check it with ls -la /dev

crw-rw----    1 root     dialout     4,  73 Dec 31  1969 ttyS9
crw-------    1 root     root      246,   0 Dec 31  1969 ubi0
crw-------    1 root     root      246,   1 Dec 31  1969 ubi0_0
crw-------    1 root     root      246,   2 Dec 31  1969 ubi0_1
crw-------    1 root     root      245,   0 Dec 31  1969 ubi1
crw-------    1 root     root      245,   1 Dec 31  1969 ubi1_0
crw-------    1 root     root      244,   0 Jan 29 10:30 ubi2
crw-------    1 root     root      244,   1 Jan 29 10:30 ubi2_0
crw-------    1 root     root      244,   2 Jan 29 10:30 ubi2_1
crw-------    1 root     root       10, 256 Dec 31  1969 ubi_ctrl
brw-------    1 root     root      254,   0 Dec 31  1969 ubiblock0_0
brw-------    1 root     root      254,   1 Jan 29 10:30 ubiblock2_0
crw-rw-rw-    1 root     root        1,   9 Dec 31  1969 urandom
crw-------    1 root     root       10, 130 Dec 31  1969 watchdog
crw-------    1 root     root      251,   0 Dec 31  1969 watchd

An equivalent to the above command some people recommend, but doesn't work: ubiblock --create /dev/ubi2_0

Why "-m 7"? For a WRT1900ACS, just look up the documentation: https://openwrt.org/toh/linksys/wrt1900acs

Layer 0 raw flash

128 MiB

Layer 1 mtd0

u-boot 1 MiB

mtd1

u_env 256 KiB

mtd2

s_env 256 KiB

mtd3

devinfo 1 MiB

firmware

80 MiB

mtd8

syscfg 38 MiB

mtd9

unused_area 6656 KiB

Layer 2 mtd4

kernel1 40 MiB

mtd6

kernel2 40 MiB

Layer 3 primary

kernel image 6 MiB

mtd5

rootfs1 (ubi) 34 MiB

alternate

kernel image 6 MiB

mtd7

rootfs2 (ubi) 34 MiB

Don't try this: mount -t ubifs ubi2:rootfs /tmp/ubi2

Why? Well, it's a SquashFS File System, so try this instead: mount -t squashfs /dev/ubiblock2_0 /tmp/ubi2

* And don't forget to do this first: mkdir /tmp/ubi2

But that's read only. What if I want to write stuff to it?: mount -t ubifs -o rw ubi2:rootfs_data /tmp/ubi2-rw (but first: mkdir /tmp/ubi2-rw)

And it won't be the entire mtd7 'partition' You'll also now notice that the OpenWRT Table for mtd isn't complete. Look back to the /dev Directory and notice that there's ubi2, ubi2_0, and ubi2_1. The 2_0 is "more ROM" and the 2_1 is "/overlay" (which is Read/Write). Try this: mount -t ubifs -o rw /dev/ubi2_1 /tmp/ubi2_1 (but first: mkdir /tmp/ubi2_1). And you'll see that it is the same as the "...ubi2:rootfs_data" command above.