Simple question (I hope). Way to mount/view MTD partitions?

Not looking for the ability to write/manipulate any of the partitions, just view the content, sort of like popping a CDRom into the drive and viewing it with Windows Explorer.

Linksys EA8100 v2 is the router in question.

In related questions, how do I determine which partition (primary/secondary) I'm booting on? When I do a sysupgrade in OpenWRT, does it write to the same partition or to the alternate partition (emulating the Linksys firmware design/function)?

cat /dev/mtdX > file.mtdX 
vi mtdX

?

if you do a fw_printenv, you will probably be able to figure out where it boots from.

according to the wiki openwrt boots from mtd8.
and since it also says if you overwrite both, you'll have no way of going back to stock,
one can assume it's always overwriting itself.

Using cat /proc/mtd is how I was able to see a list of the different partitions. I'm talking about mounting a partition to see the actual contents of it. As in, I already saw the "directory" of files, now I want to "view" one of the files.

As for reverting back to Linksys firmware, couldn't I just the latest Linksys firmware file to achieve that? Not that I have any plans of going back to the Linksys firmware, I don't know if I ever have other than one time when I needed to return a router that was slightly defective.

something like this then Cannot mount squashfs ?

I don't know your particular device. I would normally say look at the OpenWrt device page, which often has the flash layout, but the page for yours is essentially just a placeholder right now. So I'll give general advice for looking at them:

First, remember not all mtd nodes have filesystems on them. The majority don't, actually. They often contain the bootloader, FIP (second stage bootloader), DTS (device tree), etc. There may be UBI on one, which is essentially a partitioned device with its own sub-partitions that, again, may or may not have filesystems on them. The label on them in cat /proc/mtd can often give a hint.

In addition, many times there is a duplication where, for example, mtd0-3 and mtd4-7 are duplicated with the intention that when you flash a new firmware it goes on the opposite set to which you are running on.

Some tips (these assume you have some external storage or an extroot or something set up that has ample space):

  • Take a copy of the mtd and use tools like 'file' to investigate it:
    pv /dev/mtd0 > mtd0.img
    file mtd0.img
    If that shows it is a filesytem, you can then then use losetup to mount the file in loopback.
  • If it's UBI (the above investigation and/or the labels on cat /proc/mtd should tell you), then you can use UBI tools to attach, if it's not already attached, and then do the above to take images of them:
    ubinfo to see if you have any UBI devices attached
    ls -l /dev/ubi*
    pv /dev/ubi0_0 > ubi0_0.img
    file ubi0_0.img

When doing your investigations, don't mount any of them directly to start. Don't do anything that could write to them. Take copies of them and investigate the copies.

Oh trust me, I have less than zero intention of trying to write to them. Just curious to see what it looks like "under the hood" so to speak. But no touchy.

I'll give the copying a try and get back to you. Thanks.

ubi0_0.img: Squashfs filesystem, little endian, version 4.0, xz compressed, 8083594 bytes, 2246 inodes, blocksize: 262144 bytes, created: Tue Jan  3 00:24:21 2023

Had to install pv and file. Useful tools.