Joined: 04 Aug 2018 Posts: 1447 Location: Appalachian mountains, USA
Posted: Wed May 19, 2021 19:06 Post subject: unsetting empty nvram vars to reclaim nvram memory
An old wiki page on scripting suggests gaining back scarce nvram space -- I'm pretty much maxed out -- by using nvram unset on all variables that nvram show lists as having empty values. One might, for example, run
Code:
nvram show 2>/dev/null | sed -nE 's/^([^ =]+_[^ =]+)=$/nvram unset \1/p' >unsetCommands
and then source file unsetCommands and issue an nvram commit after having a look over to spot any obvious craziness.
Is this safe? Can any variable foo_bar that shows in the output of nvram show as just "foo_bar=" (without quotes and with no invisible space at the end) be safely eliminated with unset foo_bar? _________________ 2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
Joined: 04 Aug 2018 Posts: 1447 Location: Appalachian mountains, USA
Posted: Thu May 20, 2021 18:31 Post subject:
Actually that old version is a little iffy these days. On my router it picks up a whole bunch of vpn config lines from various keys that end in =. My draft version above is too severe, however, by insisting the var names contain at least one underscore. Some don't, like wanup.
But the how-to was not the point. I just wanted to make sure that a variables without values are safe to unset, that there won't be any adverse consequences for making them disappear! Reading between your lines, it seems that it's not a problem.
On my router and I assume others in the series, there is one shared" 64K nvram space. The partitioning is only for the firmware itself. But I have pretty much filled up 64K. I have 4600 bytes in Startup, 1700 in Firewall, and 4200 just for the variables/values that configure four wireguard tunnels, with one of them having several peers. Another 2K or so goes to "Additional" stuff for dnsmasq and the OpenVPN client. That's only 20% or so of 64K though, so what uses the rest? Is it all for massive numbers of built-in nvram variables? I'm on 46069 and did the config from scratch, after a reset. _________________ 2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
I have tried this it does not work. You can indeed run the script and it will reduce nvram. You can then write the smaller nvram. But when you reboot, possibly the CFE who knows, adds the missing variables back in and the router then starts throwing out configuration directives you have written into nvram.
Joined: 18 Mar 2014 Posts: 12889 Location: Netherlands
Posted: Fri May 21, 2021 9:16 Post subject:
From the EA6900 thread:
Quote:
You can set the first line: “for line in `nvram show | grep =$ `; do var=${line%*=}; nvram unset $var; done” without the quotes in your startup script at the Administration/Commands tab so that after a reboot your NVRAM size stays low.
Joined: 04 Aug 2018 Posts: 1447 Location: Appalachian mountains, USA
Posted: Fri May 21, 2021 11:47 Post subject:
I saw the idea of doing it in Startup, but my problem the last time I ran out was that my Startup code was silently truncated when I uploaded it. Screwed up the boot. I could indeed "fix" that by doing the space reclamation in Startup itself, so that editing it (on my laptop) and re-uploading it would work. But then nvram would be so full that built-in adding of new nvram vars during a subsequent boot would cause it to max out again, and some nvram actions during boot would then fail, with consequences hard to guess. Might be OK. But maybe not. Maybe adding the unneeded vars is done first, not last. Maybe subsequent changes to important nvram things would then fail. Too risky to even contemplate. _________________ 2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.