What part of the file system is in ROM?

While researching, I have found some script ( script ) to deal with the lights of my router that reads:

while true ; do
	Status=$(ping -q -c 20 -W 1 > /dev/null 2>&1 && echo "ok" || echo "FAIL")
	if [ "$Status" = "ok" ]; then
	echo 255 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:white:wan/brightness
	echo 255 > /sys/class/leds/pca963x:shelby:white:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
	sleep 10

But, as long as Flash ROM is good for reading but not so good for writing (its life cycle could be shortened), I would like to know if the "/sys/class/leds" directory is stored inside Flash ROM.

And, if there is any guide or general rule: what parts (directories) of the file system in a OpenWRT router are stored at Flash ROM?

Sys is not part of rom or overlay. Writing to sys is fine



It's not a real file. Writing to those "files" triggers code in the kernel drivers. In this case it will ultimately set a bit in an I/O register that controls the hardware pin that is connected to the LED.

Turning LEDs on and off this way is not persistent. Nothing will be stored in flash.

/proc and /dev are similar psuedo-filesystems that are kernel APIs.

/tmp (with a link from /var) is a RAM disk which is used for general file storage, but it is not stored in flash so unlimited writing is OK. All files there are erased by a power cut or reboot.


Thanks you, friends.

As long as I still don't know of any rule or list, I must ask here: what about "/etc"? Is it at ROM?

The files at "/etc" that part of the image you installed are in ROM, the modifications that you or the firstboot procedure made, are in the overlay filesystem.

Look at the output of the mount command. An example (lines slightly reordered):

/dev/root on /rom type squashfs (ro,relatime)
/dev/mtdblock4 on /overlay type jffs2 (rw,noatime)

overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

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)
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)

Almost everything is on permanent storage, with the exception of the pseudo filesystems in the final section
(/proc, /sys, ...).

/rom is the initial firmware image (read only). Modified files end up on /overlay. This happens transparently to the user, who will access files under /.


So, if I program a script that edits/changes, say, "/etc/config/system", or adds a file at "/etc/", or deletes a file at, say, "/etc/MyCustomData/", am I modifying (this is: writing on) the Flash ROM?

No, the kernel/ rootfs (/rom/) remains read-only at all times (squashfs is read-only by design), any changes (new files, edits, deletions) end up in a writable overlay (often using jffs2 filesystem) and are only virtually merged into (well, on top of) the read-only squashfs.

1 Like

You are writing to flash in the case of /etc

But it is not to the part labelled ROM but to the part labelled overlay.

In the end it is flash.

Google overlayfs

1 Like

All right, then I would say that the answer to the original question for this thread should be: writing anywhere that survives reboots is writing to flash ROM.

Is it correct?

Yes, if a file survives a reboot, it was in the flash memory.

1 Like

All right.
Thanks you all for your help.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.