2015/11/29

[FAQ] NVRAM and Factory Default Reset

http://www.snbforums.com/threads/faq-nvram-and-factory-default-reset.22822/
A lot of questions related to nvram keep popping up on the forums, usually always the same coming back again and again. This post is an attempt to at least clear up a lot of recurring questions.

What is nvram?
NVRAM stands for Non-Volatile Random Access Memory. It's a small portion of the router's flash memory that's usually between 32 KB and 128 KB in size (depending on the router model), and which contains all the router settings. This includes both some low-level settings that are automatically managed by the router (such as power gain per antenna, GPIO addresses of hardware features, etc...), temporary storage, and user-configured settings.


Default settings - where do they come from?
The first time a router boots, it will start by copying various default settings from the bootloader (or CFE in the case of Broadcom's routers). Once it starts booting the firmware itself, another set of default settings are taken from the firmware, and written back to nvram. This is why in certain cases it's very important that you do a factory default reset (more on this below).


What happens if I run out of nvram space?
Best case scenario: your router simply stops storing any settings change you make. Worst case scenario: the nvram content gets corrupted, router crashes, and you are forced to do a factory default reset, and start all over from scratch to be able to once again boot the router.


Why do I sometime need to do a factory default reset?
In addition to those user-entered settings, there's all those system level settings I previously mentioned. Sometimes, the manufacturer will need to change some of those low-level settings, either to resolve an issue, or to adapt to a newer wireless driver that they started using.

If you fail to do a factory default reset, then your router will still have the old values, and it will keep using them. That can lead to performance issues (especially in changes related to the wireless driver), or flat out odd behaviour (if one of the settings no longer works the same way as before).


Can I just restore my saved settings after I do a factory default reset?
No. The idea behind a factory default reset is to have your router start using the NEW default values. If you restore your saved settings, you will overwrite those new values with the old ones, and you are back to square one.

This is similar to having a PC with a corrupted Windows installation. If you reformat, and immediately after you restore a Ghost/TrueImage/Clonezilla backup on top of the reformatted Windows, you are back to where you were before you did all that work.


Factory default reset: before, or after flashing?
Since the goal is to use the NEW default values that are included in the NEW firmware, the factory default reset must be done while the NEW firmware is already flashed. Doing so before flashing will leave you running the OLD default values.


How do I do a factory default reset?
Multiple ways to do so, which will depend on your particular situation.

If your router fails to boot due to corrupted/invalid nvram settings, then you will have to turn off the router, press the WPS button (on Asus routers), then turn on the router. Wait about 10 seconds, then release the WPS button.

If the router is booting correctly, then you can use any of the following:


  • While router is running, press the reset button for about 5 secs, then release it. Router will then reboot.
  • From the webui, on the same page where you can save/restore saved settings, there is a button to restore factory default values
  • Over SSH, you can run the "nvram erase" command.
  • Over SSH you can manually erase the nvram partition (do not use this method unless you know what you are doing! Erasing the wrong partition can permanently brick your router!) Run "mtd-erase nvram", followed by PHYSICALLY turning off then on the router. Do not use the reboot command.



Any way to ease the pain of reconfiguring after a factory default reset?
A few methods:

  • Note down the important settings, using screenshots, and then reconfigure the router using these screenshots as a reference.
  • Keep a text-based backup of all your settings, and manually restore the important settings over SSH/telnet.
  • Use a specialized tool such as John9527's tool, which is specifically designed to handle various scenarios.


How to I use get a text-based backup?
Connect to your router over SSH/telnet, and run the following:

Code:
nvram show | sort
If you have a USB disk plugged as /mnt/sda1/, then you can save the output to a text file:

Code:
nvram show | sort > /mnt/sda1/settings.txt

How do I restore a specific setting?
If you noted down a particular setting (or have a complete text dump of them), the syntax would look like this example:

Code:
nvram set dhcp_staticlist="what is saved in your text file output"
... do all others nvram set here ...
nvram commit

When do I need to do a factory default reset?
The first rule is to check the changelog of the firmware you are about to flash. If for a particular reason this specific firmware release requires one, it will be mentionned.

Also, if jumping more than one revision, check the changelog of past release. If going from 376.40 to 376.45, and 376.43 required a factory default reset, then you must also do so with the 376.45 flash.

As a general rule, if you are jumping more than 2-3 revisions, it's often safer to do a factory default reset. If you want to try out without doing a factory default reset, go ahead and try it. But at the first sign of problem, be prepared to do one.


What are those saved config files for if I can't reuse them?
Those are backups. They are still very useful for the following scenarios:

  • When trying to resolve an issue by making a lot of random changes, and you want to be able to revert back to your original setup
  • If a bug, corruption issue or a power surge caused your router to lose all of its configuration, you can restore it
  • Having 2 or more alternative configurations that you want to easily switch between (personally, almost all my routers have a _Development and _Production copy of my settings, based on whether the router is fronting my Internet connection, or sitting behind another router).
---------------------------------------------------------------------------------------------
我們常說的BIOS是存儲在FLASH芯片中的,象我們現在賣的BUFFALO APFLASH芯片一般爲4M
整個FLASH芯片中大致分爲3部分:
第一部分就是FLASH的開頭部分叫做CFE,存儲啓動必須的一些信息,例如初始地址、MAC地址、內存地址等等;
第二部分就是我們可以下載升級部分,你從産品網站上下載的BIOS升級程序就是這部分;
第三部分就是樓上說的NVRAM,基本可以理解爲用來保存AP的設置參數。
 
OpenWrt:什麽是NVRAM?
NVRAM 全名是 Non-Volatile Ram ,在 OpenWrt 裏是用了 Flash Rom 最後的 64K 區塊,用來儲存一些環境參數,OpenWrt通過這些參數來配置網絡,DHCPDNS和記載硬件版本等。


常用的 nvram 指令有以下 4 種:
1. nvram show
列出 NVRAM 內所有參數,我們亦可以用 grep 命令來抽取部份資訊,例如
nvram show | grep lan_
這命令列出了所以用 lan_開頭的參數,結果如下:
lan_gateway=192.168.1.254
dr_lan_rx=0
lan_netmask=255.255.255.0
lan_lease=86400
lan_stp=1
lan_hwaddr=00:12:17:E1:56:F5
lan_dns=211.152.179.7 202.96.128.86
lan_ifnames=vlan0 eth1
size: 12567 bytes (20201 left)
lan_ipaddr=192.168.1.1
lan_proto=static
lan_ifname=br0
lan_wins=
lan_hwnames=


2. nvram set 參數=數值
用來添加或修改一些參數,例如我想把 LAN  IP  192.168.1.1 改爲 192.168.1.2,可執行:
nvram set lan_ipaddr=192.168.1.2
nvram commit
reboot
 1 行是修改 IP 地址,第 2 行是保存,第 3 行是重新啓動 OpenWrt ,因爲更改 IP 地址後要重啓才能生效。


3. nvram unset 參數
用來刪除一些參數,不過這個功能很少用到,因爲 NVRAM  64K 容量足夠保存大量參數,大部份人都賴得去刪。
例如我想刪除dr_lan_rx=0這個參數,請執行:
nvram unset dr_lan_rx


4. nvram commit
當你對 NVRAM 做了一大堆修改後,你需要把這些修改保存起來,否則你的路由器 RESET 後,這些修改便沒有了,和上面一樣,這時你要執行:
nvram commit
mtd -erase nvram
nvram commit
reboot
如果不行,就刷上openwrt,然後執行以上命令
好了之後再用bootwait刷回dd-wrt就可以了
回到dd-wrt啓動時候,按住reset button啓動,去web guireset button支持關掉,保存,重啓
===============================================
『dd-wrt nvram 命令 參數 詳解』
WVRDDnvram,刷tomato
1、進入管理界面點開升級界面。
2、進入TELNET管理後輸入“mtd -e nvram erase nvram”再執行“nvram commit”這是保存,
3、到你剛點開的升級界面,選擇TOMATO的固件,
4升級吧,現在你就可以進入西紅柿了(用戶名和密碼和DD的一樣)。
以上操作不用REBOOT
 
對第2WVR進行了升級,必須得恢複到默認設置(好像只有4116 http://www.dd-wrt.com/phpBB2/viewtopic.php?t=5033&start=45 也就是10.10日的版本可以恢複出廠默認)後再進行上面14的操作。
我的WAN口接了設備,這時也不行,要撥下來,才可以進入到西紅柿。
其實tomato能清除nvram的原因不是它能同時寫入到dual nvram,而是它把main part給清除了再把自己的默認數據寫了進去,reboot以後pmon檢測主備均正常,然後把主拷貝到備裏面~~~
dd呢,把main擦除了,希望交給pmon來寫入默認值,但pmon發現雖然main無效了,但是sub 還是好的,so就把sub給拷貝到main~~

沒有留言:

張貼留言

交流溝通或良好建議 ,通通歡迎。

▋熱門文章