Question of partition of linksys e4200

I have a Linksys E4200v2 router. There are several questions on it.

1. Sizes of mtdblocks
I found the following messages on the system log:

[    0.712276] nand: Could not find valid ONFI parameter page; aborting                        
[    0.718667] nand: device found, Manufacturer ID: 0xad, Chip ID: 0xf1                        
[    0.725076] nand: Hynix NAND 128MiB 3,3V 8-bit                        
[    0.729538] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64                        
[    0.737171] Scanning device for bad blocks                        
[    0.747994] Bad eraseblock 104 at 0x000000d00000                        
[    0.811625] mtd: bad character after partition (f)                        
[    0.816470] 9 fixed-partitions partitions found on MTD device orion_nand                        
[    0.823214] Creating 9 MTD partitions on "orion_nand":                        
[    0.828383] 0x000000000000-0x000000080000 : "u-boot"                        
[    0.833919] 0x000000080000-0x0000000a0000 : "u_env"                        
[    0.839288] 0x0000000a0000-0x0000000c0000 : "s_env"                        
[    0.844692] 0x000000200000-0x0000004a0000 : "kernel1"                        
[    0.850247] 0x0000004a0000-0x000001c00000 : "rootfs1"                        
[    0.855909] 0x000001c00000-0x000001ea0000 : "kernel2"                        
[    0.861494] 0x000001ea0000-0x000003600000 : "ubi"                        
[    0.866777] 0x000003600000-0x000008000000 : "syscfg"                        
[    0.872554] 0x0000000c0000-0x000000200000 : "unused" 

And no messages about mtdblock1,2,3,5,7 was found. But errors of mtdblock0,4,6 occured:

Mon Mar  4 10:00:10 2019 kern.err kernel: [    6.719003] print_req_error: I/O error, dev mtdblock0, sector 24
Mon Mar  4 10:00:10 2019 kern.err kernel: [    6.725189] __nand_correct_data: uncorrectable ECC error
Mon Mar  4 10:00:10 2019 kern.err kernel: [    6.730527] __nand_correct_data: uncorrectable ECC error
Mon Mar  4 10:00:10 2019 kern.err kernel: [    6.735877] print_req_error: I/O error, dev mtdblock0, sector 0
...
Mon Mar  4 10:00:17 2019 daemon.err block: mounting /dev/mtdblock4 (ubi) as /mnt/mtdblock4 failed (2) - No such file or directory
...
Mon Mar  4 10:00:17 2019 daemon.err block: mounting /dev/mtdblock6 (ubi) as /mnt/mtdblock6 failed (2) - No such file or directory

This was the outputs of cat /proc/mtd:

root@OpenWrt:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00080000 00020000 "u-boot"
mtd1: 00020000 00020000 "u_env"
mtd2: 00020000 00020000 "s_env"
mtd3: 002a0000 00020000 "kernel1"
mtd4: 01760000 00020000 "rootfs1"
mtd5: 002a0000 00020000 "kernel2"
mtd6: 01760000 00020000 "ubi"
mtd7: 04a00000 00020000 "syscfg"
mtd8: 00140000 00020000 "unused"

I calculted the sizes(unit: MiB) of mtds:
mtd0(u-boot)=0.5
mtd1(u-env)=0.125
mtd2(s-env)=0.125
mtd3(kernel1 )=2.625
mtd4(rootfs1)=23.375
mtd5(kernel2)=2.625
mtd6(rootfs2)=23.375
mtd7(ubi)=74
mtd8(unused)=1.25

According the official flash layout(https://openwrt.org/toh/linksys/ea4500), I got the following sizes:
mtd0(u-boot)=0.5
mtd1(u-env)=0.125
mtd2(s-env)=0.125
mtd3(kernel1 )=26
mtd4(rootfs1)=23.375
mtd5(kernel2)=26
mtd6(rootfs2)=23.375
mtd7(ubi)=74
mtd8(unused)=1.25

So Question 1:

There was huge difference between the two results (mtd3,mtd5). The system log told me that bad blocks were found. Was that the reason?

2. Which device?

root@OpenWrt:~# df -h                                                
Filesystem                Size      Used Available Use% Mounted on                                                
/dev/root                 2.3M      2.3M         0 100% /rom                                                
tmpfs                    60.2M      7.4M     52.8M  12% /tmp                                                
/dev/ubi0_1              14.9M     12.6M      1.6M  89% /overlay                                                
overlayfs:/overlay       14.9M     12.6M      1.6M  89% /                                                
tmpfs                   512.0K         0    512.0K   0% /dev    

It seemed that /dev/root and /dev/ubi0_1 was mounted on /rom and/overlay separately. By running ls /dev -l, I found that /dev/ubi0_1 was a block file, but /dev/root was not found. So:

Question 2:
/dev/root=mtd? /dev/ubi0_1=mtd?

3. How to enlarge storage?

root@OpenWrt:~# mount
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/ubi0_1 on /overlay type ubifs (rw,noatime,ubi=0,vol=1)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
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)

root@OpenWrt:~# fdisk -l
Disk /dev/mtdblock1: 128 KiB, 131072 bytes, 256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock2: 128 KiB, 131072 bytes, 256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock3: 2.6 MiB, 2752512 bytes, 5376 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock4: 23.4 MiB, 24510464 bytes, 47872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock5: 2.6 MiB, 2752512 bytes, 5376 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock6: 23.4 MiB, 24510464 bytes, 47872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock7: 74 MiB, 77594624 bytes, 151552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mtdblock8: 1.3 MiB, 1310720 bytes, 2560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

It seemed that:

mtd0(u-boot)=0.5 <--> /dev/mtdblock?
mtd1(u-env)=0.125 <--> /dev/mtdblock1
mtd2(s-env)=0.125 <--> /dev/mtdblock2
mtd3(kernel1 )=2.625 <--> /dev/mtdblock3
mtd4(rootfs1)=23.375 <--> /dev/mtdblock4
mtd5(kernel2)=2.625 <--> /dev/mtdblock5
mtd6(rootfs2)=23.375 <--> /dev/mtdblock6
mtd7(ubi)=74 <--> /dev/mtdblock7
mtd8(unused)=1.25 <--> /dev/mtdblock8

Question 3:
I want to enlarge the storage, which one is safe to use? /dev/mtdblock5? /dev/mtdblock6?/dev/mtdblock7?

Thanks!

(Please format output and code with the </> button. Your post is nearly unreadable)

On devices like your Linksys, the "kernel" (and similarly for "alt_kernel") partition contains both the kernel itself and the file systems. The kernel binary is padded out to exactly the right length (26 - 23.375 from your notes) so that the file systems' "byte 0" is at the start of the "rootfs" partition. There isn't an "extra" 23.375 MiB floating around, it's counted twice.

NAND has bad blocks. Yes, NAND does this and is the reason that a layer like UBIFS is used on top of the raw chip. Have you been writing a lot (log files, swap files, torrents, ... ) to your device's internal storage?

Edit: after trying to read the posted logs on a large screen:

This is not a good sign. I would backup your device immediately, consider running nandtest, and consider re-flashing.

"/dev/sda" -- You've got a device with USB 2 or 3, I believe. use it.

You've only got a few MB of space on NAND that could conceivably be used (looks like 74 MB potentially), but using it to extend your root file system would require a custom build of your own, with all that goes with it such as building your own packages to match your kernel. When you fry a USB stick from too many writes, you can throw it out and buy a new one for 10 EUR/USD/GBP. If you fry the NAND chip on your router, what are you then throwing out?

1 Like

Thanks very much.

I understand that mtd4 is a part of mtd3 now.

No. But this router is a second-handed one. I did not check the NAND when I got it. The bad blocks is always there, maybe.

Yes, I've got serveral usb flash drives . But they sometimes get lost, So I have to reinsert them to the router and remount the device manually. Perhaps there is something wrong with the interface on the router. Maybe the interface is too loose, I guess.

Is there a method of no rebuilding the ROM to enlarge the storage? For example, after
doing:

mkfs.ext4 /dev/mtdblockn
mount /dev/mtdblockn /opt

Then I think I could install software to /opt.
The key question is that, which /dev/mtdblock is safe to use? /dev/mtdblock5? /dev/mtdblock6?/dev/mtdblock7?

And I am still puzzled by the sizes of /dev/root and /dev/ubi0_1, since the output of mounts tells me that /rom = 2.3M, /overlay=14.9M, and no mtdblock has size of 2.3M or 14.9M.