The following was tested on a rooted Nexus 7 Wifi only (2012 version), also known as “grouper”.
First, unroot your device using the option in the Chainfire SuperSU app.
Now, reboot to bootloader mode and flash the stock Nexus recovery (Download).
Unzip the downloaded recovery zip file and flash the recovery image in bootloader mode (Power off, then Vol- and Power key pressed together lands you in bootloader mode).
fastboot flash recovery recovery.img
Now download the latest Kitkat factory image of Nexus 7 from Google
Choose the one labelled “Factory Images “nakasi” for Nexus 7 (Wi-Fi)”. As of now the latest is 4.4.4 (KTU84P).
Download the file, a .tar file, extract it with Winzip/Winrar.
It yields a directory containing a file without an extension. Rename it to give it a .tar extension.
Extract the .tar file. This gives you a list of the following files:
bootloader-grouper-4.23.img flash-all.bat flash-all.sh flash-base.sh image-nakasi-ktu84p.zip
Rename flash-all.bat as modflash.bat, and edit it to comment the additional lines as below:
PATH=%PATH%;"%SYSTEMROOT%\System32" fastboot oem unlock fastboot erase boot fastboot erase cache fastboot erase recovery fastboot erase system :: fastboot erase userdata :: fastboot flash bootloader bootloader-grouper-4.23.img fastboot reboot-bootloader ping -n 10 127.0.0.1 >nul fastboot update image-nakasi-ktu84p.zip
Note that the following lines are modified ones to protect your data from being corrupted:
:: fastboot erase userdata :: fastboot flash bootloader bootloader-grouper-4.23.img fastboot update image-nakasi-ktu84p.zip
Once done, you can flash the latest TWRP back. Download version 22.214.171.124 here
fastboot flash recovery openrecovery-twrp-126.96.36.199-grouper_2.img
Now download the latest SuperUser updater zip from Chainfire’s site:. Push it to sdcard via adb while TWRP recovery is on.
adb push UPDATE-SuperSU-v2.01.zip /sdcard/
Now install the zip from TWRP.
Once you reboot, go to the Market link for Chainfire SuperSU apk and install it. That’s it you’ve successfully updated to the latest Android version without losing root.