Image - how immutable are the included packages and files once image is flashed?

I seem to have read somewhere something to this effect:

The portion of flash memory to which an image is flashed becomes "fixed" so that no package can be removed from it to free up space. If you opkg remove a package in such "fixed" portion, it is simply treated "as gone."

Is that true? (Sorry I don't have the technical vocabulary for "fixed" etc.) That was question 1.

Question 2. If that is true, what happens if you remove a package in the "fixed" portion, say nano, and install it again? Is nano in the "fixed" portion now treated "as back"? Or does it remain "as gone" while the "free" portion of flash memory gets a new copy of nano (so you end up with two copies of nano taking up space)?

Question 3. Does a config file included in the image also become part of the "fixed" portion of flash? This would mean that editing such a config file, say /etc/config/wireless, would result in the original version (in the "fixed" portion) being treated "as gone" while the "free" portion gets the amended version of /etc/config/wireless.

Question 4. Assuming yes to 3, what happens if, subsequent to editing /etc/config/wireless, you edit it again so that it reverts to the original contents? Do you end up with one copy in the "fixed" portion and another identical copy in the "free" portion of flash (identical as to contents I suppose as timestamp may be different)?

Question 5. If all packages and files included in an image are "immutable once flashed" as above (never gone even if treated as gone), is there a way to reset the router to the condition of the image (i.e. to the condition just after flashing)? At least LuCI's 'Backup / Flash Firmware' menu item does not seem to have a sub-item for such reset.


For questions 1 through 4, while I appreciate replies providing the right vocabulary and explaining how the process works, I would also appreciate replies to take an individual question (above) and expressly telling me that I was right or wrong in what I expected to happen. Thanks.

To question 5, I believe this User Guide is relevant:

The Factory Reset section of the Guide states, "A factory reset returns your router to the configuration it had just after flashing." Such flashing should include flashing with a custom made image including config files (which would then survive the reset)?

1 Like

First of all, read up on

You can't 'flash' packages or files, you can only flash a dedicated firmware image for your device. These generally are made up of kernel and rootfs (often using the read-only, but highly compressed, filesystem squashfs), both of which are read-only - the unused space is then used for the (overlayfs backed-) overlay, which makes the rootfs part virtually writeable. As mentioned before, the rootfs itself is read-only (outside of the context of flashing a new firmware image), so any changes (file modifications, additions and deletions) care recorded on this overlay, including installation or removal of packages. Deletions are realized via whiteouts, writing markers to the overlay which tell the system that files a, b and c are (virtually) deleted --> hidden from view (but still present immutably underneath). Changes to the overlay itself can be modified in place, so installing a new package (not present in the original firmware, the read-only rootfs) and then either upgrading it later to a newer version or deleting it happens solely within the overlay and can accordingly change- or free-up the space of the previously installed package, while 'removing' preinstalled files/ packages that are shipped in the firmware image will require additional space to write out the whiteouts necessary to 'hide' the files from view.


Thank you. It'll take me some time to go through and try to absorb the highly advanced materials you provided.

But just on "flashing packages and files," what I meant was including packages and files in the image building process, as with:

make image PROFILE=[my_router_model] PACKAGES="nano" FILES=files/

so that, when you flash the router with the image, the included packages and files get flashed along with everything else in the image.

Those additions end up in the read-only rootfs. imagebuilder creates a new squashfs from scratch (in doesn't can't modify an existing one in place either), based on the packages you tell it to include (relative to the default packages for your device) - before assembling new/ complete firmware images.


Thanks again. I believe your kind comments so far represent "yes" and "yes" to questions 1 and 3. Care to express a view on questions 2 and 4? That is, what happens when you remove and then reinstate what was once in the original flash image? Is the whiteout peeled off (as it were), exposing the original package or file again? Or does the original thing remain whited-out while a new copy is installed in the overlay? (I believe overlay is the term for the "free" portion?)

Afaik if you delete and then install the package, you are using space in the read-write overlay partition.
The filesystem is not smart enough to check if the new file is the same as an older deleted file.

If you do a factory reset (= delete and create a new read-write overlay), you have access again to all files from the read-only partition, even the ones you "deleted" before.


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