Trim ASUS router's NVRAM
Here is a way to clean-up ASUS router’s NVRAM without full factory reset. Yes, it is possible :)
TL;DR: Connect to your router via SSH and trim NVRAM with this script (as always, use at your own risk!):
for line in `nvram show | grep ^[^=]*=$ `; do var=${line%*=}; nvram unset $var; done; nvram commit
The other day my ASUS router, with Asuswrt-Merlin (RT-AC68U), stopped forwarding ports. Quick Internet search revealed that it is either a full JFFS partition1 or its NVRAM2 is full, thus the settings didn’t survive router reboots.
My JFFS partition was fine, but the NVRAM was completely full and the only “solution” was to do a factory reset of the router. That would completely wipe all of my settings and I didn’t want that to happen. In the end I found a one-line script to delete unused properties from the NVRAM. They credit the Internet, but no link is provided, so maybe this forum thread is the origin and this thread has more information and links back to the first one. No guarantees, use at your own risk!
for line in `nvram show | grep ^[^=]*=$ `; do var=${line%*=}; nvram unset $var; done; nvram commit
To run this command you have to connect to your router via SSH first and then run it in the terminal. In my case, it deleted around 10KB of data, from the total of 64KB used. Now my port forwarding can be set and works again.
I am adding this script to my webpage to have it on more than just one place, because domains expire, webpages are re-designed, forums get closed, thus information is lost.
The original forum post suggests to “for stability, immediately reboot to restore ’necessary’ NVRAM variables, even if empty”, but in my case that was not needed and the router is working fine.
What it does?
This script deletes all properties from the NVRAM that have no value assigned, e.g. some_property=
where there is no value after the equals sign. These properties with no values are not used anymore (probably :)). Worked on my router, but no guarantees. Use at your own risk!
No worries, this will NOT delete Base64 encoded values that need padding at the end with =
.
Probably run this every after firmware upgrade, to always clean-up the newly unused properties.
Why does it get full?
Because the router adds new features with firmware ugprades, and sometimes it renames properties and does not delete the original ones. So they will stay there, with no value assigned. Yes, it will delete the value of the old properties, but not their names.
This way, after ~10 years of upgrades, and in between an upgrade to Asuswrt-Merlin, my NVRAM got full. I never did a factory reset/full wipe, because of too many custom settings. Backing-up the settings, doing the factory reset and then restoring them, will end-up with full NVRAM again, as NVRAM holds the settings. Check the size of your settings backup ;)
Also, Asuswrt-Merlin uses more NVRAM, than the stock ASUS firmware, so it is a bigger problem in Merlin. It was explained by the author of Asuswrt-Merlin here.
Missing “Apply” button in the port forwarding (virtual server) settings
Sometimes this button disappears, and it is either the JFFS partition or NVRAM problem. In my case this button has not re-appeared even after the NVRAM clean-up, but it is working without it. If the forwarding rules show-up after changing to another settings screen and going back, then it is working.
It didn’t help?
If this does not free-up enough space from your NVRAM, then you have to do a factory reset and reconfigure your router from scratch. Do not restore your config from a backup, because that will fill it up again.
JFFS partition full?
If your JFFS partition is full, you can follow this Reddit thread how to safely clean it up.
-
The JFFS (Journaling Flash File System) partition is a writable section of the router’s flash memory. It is used mainly for storing scripts, configurations, certificates and Asus puts there log files, which can fill it. ↩︎
-
NVRAM (non-volatile random-access memory) is memory that can hold data after a device is turned off. ↩︎