How many times can upgrade(flash) new firmware before wearout?

I have openwrt installed on linksys wrt1200ac.
I create my own image from 18.06 branch.
how many times can I flash this image before the ROM (or whatever is in there , maybe flash) wear-outs and gets bad sector.
if you think this is not possible let me tell you that I got bad sectors on my last router(tplink 8970 ,if i remember the name correctly)


Flash memory is rated in the tens of thousands of write cycles. If you wore out a flash device in the past it wouldn't be from installing new firmware but possibly from logging data too frequently to flash. This is usually avoided by logging to /tmp

I have flashed my R7800 about ~150 times in the past year. (EDIT: Actually a bit more: 421 different firmware versions since Oct 2016.)

I have flashed my WNDR3700/3800 routers about 150 times per year for several years. (EDIT: recently: 248 firmware versions since 1.1.2017)

But modern NAND flash (like in R7800) can generate bad sectors, but those should usually get hidden by UBI fs.

1 Like

@reza Check the /overlay/upper directory on your router, it shows everything that was dynamically changed. Than check if maybe some files are updated frequently or seem to belong on /tmp.

1 Like

that was on my old router which made it a brick.
I am trying to prevent the same fate happening.
is there a app (linux app) that can monitor this changes to filesystem (writes ) and log them in /var for me to check?

By default, Openwrt writes only a few changes at boot, but after that there are no changes to the disk. Pretty much everyhing gets written into ramdisk /tmp alias /var so that flash gets kept intact.

Timestamps in overlay fs /overlay/upper may offer you easy clues if anything actually writes there at all. The advice from Andy244 is quite valid. /overlay/upper is the actual contents of written to flash (in addition to the original firmware).

Regarding files system monitoring tools, I am not sure if there is anything available easily that really monitors filesystem changes per app AND disk.

I had some faulty device SPI chip. It broke after 2-3 writes. Same hardware, same hardware revision, same SPI chip model, just other device: I could flash it over 80 times and its still alive.
If the flash chip broke, then it was a bad one. I never had any issues with any other device. Does not matter if its the about 20 years old Linksys WRT54G or any of the modern ones. The flash normaly dont break if its fine in first place. If its faulty, also the OEM firmware stops working at some time because that one also writes often to the chip different configurations and things like that.

I need to find a better word for app. I meant that is there a program that monitors what files are written and maybe logs the most written(changed) ones. It doesn't need to find the related process.

then later I can manually monitor that file and find the process responsible.

Simpliest is checking when the last file / dir was written and going down the path

# ls -ltr /overlay/upper/
drwxr-xr-x    3 root     root             0 Aug  2 16:53 mnt
drwxr-xr-x    2 root     root             0 Aug  4 23:33 bin
drwxr-xr-x    6 root     root             0 Aug  5 04:50 usr
drwxr-xr-x    8 root     root             0 Aug  5 04:50 lib
drwxr-xr-x    4 root     root             0 Aug  5 04:52 www
drwxr-xr-x   13 root     root             0 Aug  5 04:52 etc
drwxr-xr-x    2 root     root             0 Aug  5 20:06 root
drwxr-xr-x    2 root     root             0 Aug  8 00:26 sbin

if there is a file edited inside a subfolder inside ,say, 'etc' , so the file etc/subfolder/test then this doesn't show in this command. how do I find this out? (I tested on my laptop with a 1/2/3/test.txt file)

I now use find program to find the files changed in the last ,say, 5 minute.
find -cmin -5
and this find just the .ash_history file, which is the command history. so right now I didn't find anything bad. I will try after a day.

If rolling your own:


this should be [y] then right?
to decrease the writes ?

│ Type : boolean │
│ Prompt: Save history on shell exit, not after every command

It is also possible to direct busybox to save the history to /tmp. (note that you lose history at reboot, but so what)

I do it via patching busybox (see below), but it could also be done via shell variables HISTFILE (full path+name of historyfile) or HOME (just the dir to save history in):

--- /dev/null
+++ b/package/utils/busybox/patches/310-save-history-in-tmp.patch
@@ -0,0 +1,11 @@
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -14209,7 +14209,7 @@ int ash_main(int argc UNUSED_PARAM, char
+ 		if (iflag) {
+ 			const char *hp = lookupvar("HISTFILE");
+ 			if (!hp) {
+-				hp = lookupvar("HOME");
++				hp = "/tmp";
+ 				if (hp) {
+ 					INT_OFF;
+ 					hp = concat_path_file(hp, ".ash_history");

so having history saved at the exit of shell is bad too?
I am getting confused.
at the start the answer was that I can flash the ROM thousands of times.
but now the small history file of ash is really bad for write cycles?

if not then you mean for optimizing so that the small file is not written also?

BTW , I have a usb flash attached that I use to run apps from, can I make a symlink to the usb for ash_history and save it there?

This is turned off by default, so there will be no writes into a history file unless explicitly enabled:

Enable history saving in shells. 
  │ Type  : boolean  
  │ Prompt: History saving 

That was just a helpful hint in case if you really want to avoid any flash writes (but still enable the history feature in busybox).

I use history to not to have to remember my commands. so I need it even between reflashs.
so I have enabled the save-history feature, but didnt see the save-on-exit feature and I have enabled that too.

maybe I should do the symlink way and be done with it.

btw is there 'fish' shell available on openwrt? as a side shell,not main shell.
I have it on my laptop and I love it search that can search from middle of commands.
tried to make zsh that way but it didnt work on my laptop.