Saturday, 27 September 2014

Cloning Nexus 7



I have fifteen Nexus 7 tablets to prepare, so I needed to find out how to clone one.

Here is what I have discovered:

Note: I am using a computer running Linux and working on the command line as root. The notes below document the steps I took to get a Nexus 7 cloned, but are not really a tutorial.

WARNING! At one point I was stuck with a non-booting device and had to do a factory reset. This was on the device I was hoping to clone. Luckily I was just learning and it wasn't a real master tablet. You should get your tablet rooted and a recovery installed before setting it up, if at all possible. If you have already got your master tablet ready, make a backup using Titanium or similar, and get it off the tablet. 


Overview

0. Instructions on the Internet are very unclear, especially for Linux

1. You can't use an Android tablet without a Google account. I tried hard for a few days, but gave up and made a fake gmail address for it. My reading suggests that you need a different gmail address for every 10 devices, or you won't be able to use the play store. So I will need another ID for the last five tablets, maybe.

2. Cloning is done with images called nandroid backups. These seem to be like regular computer images you would make with Clonezilla, for example. At least I hope they are.

3. To make a nandroid image you need root on the device and a "custom recovery". I chose CFauto and TWRP. Or they chose me, perhaps. To get them installed you need to unlock the bootloader. For all of this you need the package android-tools on the computer. On Debian Wheezy I had to use backports to install it.

4. Transfer the nandroid image to the computer, and restore it to another tablet (which is also unlocked and rooted, with the same recovery installed)

Details

On the tablet

Open developer tools by clicking many times on the build number in "About tablet" in Settings.
Set USB debugging and plug the tablet into a USB port on the computer

On the computer

Download TWRP and CFauto for your tablet. In my case its:

openrecovery-twrp-2.8.0.1-flo.img

and

CF-Auto-Root-flo-razor-nexus7.zip

Rename the former into something short like twrp.img
Unzip the latter (careful, it doesn't create its own folder. I unzipped into a folder called CFauto)

In a terminal as root (in the directory where you downloaded those two files):
aptitude install -t wheezy-backports android-tools
adb devices
This should pop-up a warning on the tablet, which you accept.

Now reboot the tablet to the bootloader and unlock it. You do both of these things from the computer.
adb reboot bootloader
The bootloader is a screen with a big green android and some details about the device. I suppose it is something like Grub.
fastboot oem unlock
You should see that the tablet now asks you to unlock it. After which do:
cd CFauto/image
fastboot boot CF-Auto-Root-flo-razor-nexus7.img
After this completes, the device will show a red pirate android before rebooting. Upon reboot, you will be welcomed to the device again. This all gets us to the point of having root on the device. Now we need the recovery, to be able to make backup images. Go through initial setup on the device again (skip the Google account), and set USB debugging once again.

Back on the computer

If you get connection problems, do:
killall adb
adb devices
Otherwise go straight to:
adb reboot bootloader
cd ../../. #get back to the directory where the twrp image is
fastboot flash recovery twrp.img
Use the volume keys to select "recovery" and press the power button. The device will reboot into TWRP. This is where you make and restore backup images.

The procedure above has to be done on all 15 tablets. They all need to be rooted, with the bootloader unlocked, and a custom recovery installed. The actual cloning takes place in the custom recovery, where you backup and restore nandroid images.

I use adb push and pull to transfer the images to and from the device.
With the donor device connected:
adb pull /sdcard/TWRP/BACKUPS/0a0a0a0a  localfolder  
The folder 0a0a0a0a is different on each device. Edit: Its the device ID!

With the receiver device attached:
adb push localfolder/0a0a0a0a  /sdcard/TWRP/BACKUPS/1f1f1f1f/.  
1f1f1f1f is the folder on the new tablet. I have found it to be non-existent at first, so you have to make a backup in recovery to create it. You can't trick it into accepting the folder of the donor device, unfortunately. So just backup boot, and it will take a few seconds. Then push your old image over and restore.

Notice the strange path behaviour of adb push. My backup is a dated folder within 0a0a0a0a, yet I push 0a0a0a0a and not the folder within.

If you didn't realise it, you can used Advanced / File Manager on the TWRP recovery screen to find out the name of the device backup folder. Its in /sdcard/TWRP/BACKUPS

Next is setting up one tablet with all the apps and users you need before making the master backup image to restore to the other tablets.

At some point that I can't yet define, after struggling my way through so many poorly-written tutorials, I had to do a factory reset on the new device. It was stuck at a worrying screen that shows a prostrate android with his chest open and a red warming sign hovering over him. You can make a menu appear at this point by fiddling with the up volume and the power button until you hit on the right combination. Its something like hold power and then press up, and release them together. From the menu that appears, choose to wipe the cache and do a factory reset. When you reboot you will be welcomed to the device (again!), kind of like sliding down a ladder or going back three spaces.

No comments:

Post a Comment