Moto G - Root, Remove Ads & Extend Battery Life under Ubuntu



android-motogIf you want to root your Motorola Moto G, a lot of stuff is available on the net from different sites and forums.

But most of the stuff you get on the net is oriented toward using Windows tools.

Obviously you can handle all the needed steps from an Ubuntu workstation, but all different steps are not trivial to setup and follow.

This article is a step-by-step guide that explains all the steps needed to unlock your phone bootloader, install a custom recovery, root it, get rid of annoying ads and extend your battery life.

The complete procedure has been tested on a Moto G 8Gb running Kitkat 4.4.2 from a Ubuntu Saucy 13.10 workstation.

As a pre-requisite, you must have latest Android SDK or latest ADB package installed on your computer. An installation guide is available for Debian and Ubuntu computers.

You have to understand that rooting your phone is always a little bit risky, even if on Google phones everything is smooth.
So, if you go further, do it at your own risk !

1. Create Udev rule for Moto G

By default, Motorola Moto G is not fully writable as it should be under Ubuntu.

We need to declare some very simple udev rules to handle full access to your Moto G.

They will be declared in /etc/udev/rules.d/99-android.rules. If file already exists, just append the content at the end of it.

# sudo gedit /etc/udev/rules.d/99-android.rules


# Motorola Moto G
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2e80", MODE="0666", OWNER="your-login" # Fastboot mode
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2e76", MODE="0666", OWNER="your-login" # MTP mode, USB debug On
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2e82", MODE="0666", OWNER="your-login" # MTP mode, USB debug Off
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2e83", MODE="0666", OWNER="your-login" # PTP mode, USB debug Off
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2e84", MODE="0666", OWNER="your-login" # PTP mode, USB debug On

your-login should be your normal Ubuntu session login.

Once done, udev service has to be restarted.

# sudo service udev restart

2. OEM Unlock Moto G

Next step suppose that you have installed latest android-tools package.
If you are using Android SDK, you should be in ./android-sdk-linux/platform-tools directory.
You also have to issue commands from local directory ( fastboot becomes ./fastboot ).

First main step it to unlock your boot loader.

You have to understand that unlocking your bootloader will void your waranty. So you have to do it knowingly.

Unlocking is a standard process on Moto G phone, but as a safety feature, it will ask for an unlock code and it will wipe all your data.

To do so, you need to start your phone in fastboot mode. To do so :

  1. switch off your phone
  2. unplug USB cable
  3. press Vol Down + Power at the same time
  4. release Power

Your phone should enter in fastboot mode.

You can now connect the USB cable and type the following command to get the unlocking code that will be asked by Motorola :

# fastboot oem get_unlock_data 2>&1 | grep bootloader | sed 's/^.* \(.*\)$/\1/g' | tr -d '\012' && echo ""

This command directly gives you the unlocking code asked by Motorola.

You now need to register to Motorola Device Unlock site.

Once registered, you can start the unlock process. You just need to Paste the unlock code you've got with previous command and press Can my device be unlocked ?.

After validating the agreement, you'll receive an email with subject Unlocking your device. This email will bring your unlock code.

If you go ahead and unlock your phone, it will be fully erased.
All your data will be lost. Your phone will be factory reset.

You can now unlock your phone with the provided code :

# fastboot oem unlock 62ONBCQXG3T6U3ZKP3CU
(bootloader) Unlock code = 62ONBCQXG3T6U3ZKP3CU

(bootloader) Unlock completed! Wait to reboot

Your screen should now become black with Unlocked! written.


After few seconds your phone will reboot.

From now on, everytime you will start your phone you will get this warning.


3. TWRP recovery

TWRP is a new generation of recovery.


Its main advantage over ClockworkMod Recovery is to be usable straight from the touch screen.
You don't need anymore to use Volume or Power keys. You can do all the job from the comfort of your touch screen !

Latest version is available from TWRP site. Just download it before going further.

3.1. Install TWRP recovery

If not already in fastboot, start your phone in fastboot mode by switching if off, unpluging USB cable, pressing Vol Down + Power and releasing Power.

Once ready, from your Ubuntu computer, flash a new recovery with this command :

# fastboot flash recovery openrecovery-twrp-
target reported max download size of 536870912 bytes
sending 'recovery' (8084 KB)...
OKAY [ 0.277s]
writing 'recovery'...
OKAY [ 0.471s]
finished. total time: 0.749s

Your phone may display a message "Mismatched partition size (recovery)". Just ignore it, it's not a problem.

Now that TWRP is flashed, first thing to do is to reboot the bootloader.

# fastboot reboot-bootloader
rebooting into bootloader...
OKAY [ 0.001s]
finished. total time: 0.001s

Then, to enter into TWRP recovery, you need to :

  1. select recovery entry
  2. press Vol+ and Vol- at the same time

You should enter Team Win Recovery.

Be careful, TWRP touch screen may be a little bit over sensitive. This should be corrected from V2.6.3.3 onward.
When you navigate thru TWRP screens, make sure you've not selected something unwanted because of touch screen over sensitivity.

3.2. Protect TWRP Recovery

By default, stock ROM rewrites OEM recovery at every shutdown. That means that at next boot your newly flashed TWRP recovey will be gone !

This removal is done by a specific file named /system/recovery-from-boot.p.

The good news is that you just need to rename that file to block the recovery removal mecanism. We will do it straight from TWRP Recovery.

From TWRP Recovery, select menu Mount and tick the option System. The /system filesystem is now mounted.

Go back to main menu and select menu Advanced / File Manager.

Go in /system, select recovery-from-boot.p and rename it to recovery-from-boot.p.bak

The recovery removal process is broken. We can reboot.

From TWRP Recovery, select menu Reboot / System.

When you will update your stock ROM, your custom recovery will surely be erased.
You will then only need to redo the install and protect recovery steps to get back a fully working custom recovery.

4. Root the Phone

android-icon-supersuThe last step is to root your Moto G.

When you will exit TWRP for the first time, it will detect that your phone is not rooted and will propose you to root it.

Just accept.

After a system reboot, you will get a SuperSU installer notification and application icon.

Make sure you are connected to internet and launch it.

On the first screen, select the button TWRP.

Some files will be downloaded and your phone will reboot under TWRP to flash the downloaded .zip file.

When flashing is over your phone will reboot again.

You're done, your Moto G is rooted.

5. Enable Developer Options

To enable USB debugging, you need to follow these steps on the phone :

  1. go to Settings
  2. select About phone
  3. at the bottom tap 7 times on Build number

This will enable the Developer Settings where you can enable USB debugging.

Next time you'll connect your Moto G to your Ubuntu workstation, it will display on the phone a message asking you to allow connexion to your computer as a trusted computer.

Validate the message while selecting the permanent checkbox.

6. Motorola PDS partition

On Motorola devices the PDS partition contains information specific to your phone : IMEI, MAC address, serial number, etc.

This partition can be lost by accidental format or over time due to filesystem corruption.

So, a PDS partition backup may help you to restore a lost IMEI. It is a situation when the phone reports that the IMEI is unknown.

If you have made a backup, there is a good chance you can bring your handset back to life. Otherwise, it's too late !

6.1. Backup PDS partition

Using ADB you can make a copy of the partition and then move it to a safe place :

# adb shell
root@falcon_umts:/ # su
root@falcon_umts:/ # dd if=/dev/block/platform/msm_sdcc.1/by-name/pds of=/sdcard/pds.img

The partition is now on your sdcard as pds.img. Back it up in a safe place.

6.2. In case of trouble, Restore it

If by any mischange your PDS partition is erased or corrupted, you'll need to restore it.

You can restore it by placing back pds.img in the internal SDcard and running the following command :

# adb shell
root@falcon_umts:/ # su
root@falcon_umts:/ # dd if=/sdcard/pds.img of=/dev/block/platform/msm_sdcc.1/by-name/pds

Be very careful.
You can brick your phone and/or loose your IMEI in case of mistake !

7. After rooting tweaks

Now that your Moto G is fully rooted, you can follow these additional procedures :


You now have a fully rooted Moto G that will be able to give it's maximum during maximum time.

All sorts of tweaks are opened to you !

Hope it helps !

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus