Flashing a stock Android image without wiping user data
Until today my Nexus 10 was running Android 4.4.2 (stock firmware from Google). I couldn’t install the OTA update to 4.4.4 because I had installed a custom recovery (TWRP) in order to root the device. So today I decided to reinstall the stock recovery and install the update… But the installation failed. The tablet was able to reboot, but it showed that is was still running Android 4.4.2, but cound not find any update anymore. Weird…
(IMHO the problem that happened is that when I reinstalled the stock recovery, I installed the version from the 4.4.4 firmware, but the OTA update expected to have the version from the 4.4.2 firmware. Can this cause the install to fail like this? Not sure, but I have no other explanation.)
So in order to update to 4.4.4 without wiping my device I had to do it by hand:
-
download the latest factory image; in my case the file is named
mantaray-ktu84p-factory-74e52998.tgz
-
extract the archive:
tar xvf mantaray-ktu84p-factory-74e52998.tgz
-
extract the image zip inside the extracted folder:
$ cd mantaray-ktu84p $ mkdir image $ cd image $ unzip ../image-mantaray-ktu84p.zip`
-
flash the boot, recovery and system images, but not the userdata one (as it would wipe my data) [source]:
$ adb reboot bootloader $ # Wait until the device reboots to the bootloader... $ sudo fastboot flash boot boot.img sending 'boot' (4784 KB)... OKAY [ 0.739s] writing 'boot'... OKAY [ 0.132s] finished. total time: 0.871s $ sudo fastboot flash recovery recovery.img sending 'recovery' (5334 KB)... OKAY [ 0.783s] writing 'recovery'... OKAY [ 0.152s] finished. total time: 0.935s $ sudo fastboot erase system ******** Did you mean to fastboot format this partition? erasing 'system'... OKAY [ 0.048s] finished. total time: 0.048s $ sudo fastboot flash system system.img erasing 'system'... OKAY [ 0.028s] sending 'system' (652994 KB)... OKAY [ 95.901s] writing 'system'... OKAY [ 19.227s] finished. total time: 115.156s
-
start the system from the bootloader.
And voilĂ ! The device booted to Android 4.4.4 and I didn’t lose my data. However root access was lost, but that is extremely easy to restore:
- download TWRP and SuperSU
- reboot the device to bootloader:
adb reboot bootloader
- flash the custom recovery:
sudo fastboot flash recovery openrecovery-twrp-2.7.1.0-manta.img
- boot to recovery and enable sideloading (in Advanced –> ADB Sideload)
- sideload the SuperSU zip:
adb sideload UPDATE-SuperSU-v2.02.zip
- reboot and start the SuperSU app.
I’m sure all of this is common knowledge for a lot of people. But it’s not obvious to me, so I’m just putting it here for the next time I need it 😃
EDIT: Just tried it and I can confirm that it works well to upgrade from Android 4.4.4. to Android 5.0 “Lollipop”!
Comments
Join the conversation by sending an email. Your comment will be added here and to the public inbox after moderation.
OTA is meant to be used on 4.4.3, not 4.4.2.
Nice article. It worked flawlessly for me. Thanks
Great article, short and precise. Worked perfectly updating from 5.1 to 5.1.1 on a rooted nexus 7 2012 mobile. Thanks
Thanks man used it for 2 times, works flawlessly.
This is actually really useful. Thank you very much.The same weird problem is happening to me everytime. For example I had Android 5.1 with TWRP installed on Nexus 5 and I tried to flash the official update “to 5.1.1 from 5.1” and the error said “you have release keys of 5.0.2” and expect me to flash the update for 5.0.2 which also doesn’t work.It is really really weird and it happens all the time when I root my phone. This is the best way to update the rom. I wish we had a better way.
@Said I had the same issue when upgrading from Kitkat to Lollipop on my OPO. If I remember correctly, you have to upgrade TWRP to the latest version available. It’s required to install recent ROMs.
Thank you very much !!!!! now i can update via OTA
Would this work with a custom kernel?
@Bogdan, depends on the kernel, but I’ve used it in the past with my Galaxy Nexus and custom kernels. You can flash the kernel with “fastboot flash boot.img” in bootloader mode, or a kernel .zip from recovery.
I am using nexus 6p, in my image factory file, I don’t have boot.img, system.img, recovery.img ..
Worked for me as well…
After bricking my software, I stuck on load screen, so I tried so many ways to flash original Rom for my Huawei G6-L11, but always had some errors . And this method worked like a charm. All I did was flashing system.img and my phone was back to life.