unsetting empty nvram vars to reclaim nvram memory

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Wed May 19, 2021 19:06    Post subject: unsetting empty nvram vars to reclaim nvram memory Reply with quote
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.
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Thu May 20, 2021 14:58    Post subject: Reply with quote
Linksys people with split partitions and only 32KB NVRAM have dealt with this far longer and use the following:

Code:
for line in `nvram show | grep =$ `; do var=${line%*=}; nvram unset $var; done
nvram commit


https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=291230#291230

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Thu May 20, 2021 18:31    Post subject: Reply with quote
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.
tedm
DD-WRT Guru


Joined: 13 Mar 2009
Posts: 555

PostPosted: Fri May 21, 2021 7:13    Post subject: Reply with quote
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.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Fri May 21, 2021 9:16    Post subject: Reply with quote
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.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Fri May 21, 2021 11:47    Post subject: Reply with quote
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.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Fri May 21, 2021 12:13    Post subject: Reply with quote
Some linksys routers have an escape by using a different CFE (although there are some drawbacks) but still they will "only" get 64KB

I am lucky my Netgear R6400 and NetGear R7800 have 128 KB nvram Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum