Close

January 17, 2014

Installing Ubuntu Touch onto Nexus 7 2012 from Fedora 20 (in depth)

Ubuntu Touch on Nexus 7 (2012)

When I started looking at installing Ubuntu onto my rarely used Nexus 7 2012 edition tablet, I hadn’t considered how much of a right pain in the arse it would be if you weren’t running Ubuntu.

Turns out, if you’re running Ubuntu, it should be a walk in the park, if you’re running anything else, in my case, Fedora 20, it’s more complicated.

So, this is a guide to installing Ubuntu Touch onto a Nexus 7 2012 (mine is 8GB WiFi only, your mileage may vary).

What I will guide you through is the following.

I will show you how to install the AndroidSDK Tools
I will show you the steps to take a backup (if you so wish)
I will show you how to unlock your device
I will show you how to install the developer release of Ubuntu Touch

This is a collection of various guides and my own experiences, I had about 10 installs of it manually with it booting to a black screen before I turned to IRC and received some guidance, it was still not straight forward though. Most people in that channel had Ubuntu, so tough crowd. They were all nice though, not one told me to RTFM, maybe because there isn’t one?

{Before continuing, please read the disclaimer here: https://wiki.ubuntu.com/Touch/Install }

Some foolish assumptions:

1) You are happy to lose all the data on your Nexus 7 as it is now.
2) YOU ARE HAPPY TO LOSE ALL THE DATA ON YOUR NEXUS 7!
3) You are willing to risk bricking your device for a developer release of Ubuntu Touch
4) You have a working installation of Fedora (I’m only claiming this will work on 20 but should be fine on many previous releases)
5) YOU ARE HAPPY TO LOSE ALL YOUR DATA! Don’t come crying to me if you brick it too. I’ve installed this many times and it’s not bricked mine, if you manage to brick yours, sorry, you were warned.
6) You know your way around the Linux system a bit (this guide was getting huge, it starts off detailed, but tails off after I added this assumption.
7) $ means running as user, # means running as root

OK, with that out of the way, lets proceed, allons-y!

Step 1) Getting yourself the android gubbins, adb, fastboot, etc, in detail:

Download the SDK from here, http://developer.android.com/sdk/index.html

At the time of writing, it was around 475MB and there are two versions:

1) adt-bundle-linux-x86_64-20131030.zip for 64bit systems
2) adt-bundle-linux-x86-20131030.zip for 32bit systems

Unpack it in your home directory, then rename it to ~/AndroidSDK

Add into path variable ~/AndroidSDK in .bash_profile file in your home directory. So use your favourite editor to open up that hidden file to edit.
For example add to the end of your PATH list the following, you split the options up with colons ‘:’

$HOME/AndroidSDK:$HOME/AndroidSDK/tools:$HOME/AndroidSDK/platform-tools

So, it should look something like this:

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/AndroidSDK/sdk:$HOME/AndroidSDK/sdk/tools:$HOME/AndroidSDK/sdk/platform-tools

Keep the rest of the file unchanged, save it.

Now, you’ve done that for your user, however, we’re going to be using some other tools, such as sudo and the root users profile. So, make yourself root, either using sudo or su and edit their ~/.bash_profile too and add that AndroidSDK line, HOWEVER, you will need to make $HOME the full path to your home directory, otherwise it will use /root, which is wrong, unless you’ve installed it as root, which is also wrong (well, bad practice).

I mentioned sudo, if you’ve not already got it, install sudo:

# yum install sudo

Once that is installed, add your user account to the sudoers file in /etc/sudoers, again, bad practise to do this as it opens up the option to run any command as root under your account, but for purposes of this, put this into /etc/sudoers

lee ALL=(ALL) ALL

this would be near something looking like this in the commands section:

root ALL=(ALL) ALL

Once you’ve added that, near the top of the file, you also want to add the path to AndroidSDK like we did before, but this is so sudo works, it doesn’t use PATH it uses a SECURE_PATH variable which is defined in this file. So, add the path variables to that secure_path, for example, mine is:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/home/lee/AndroidSDK/sdk:/home/lee/AndroidSDK/sdk/tools:/home/lee/AndroidSDK/sdk/platform-tools

Save the file.

Now, as root, run this command to invoke the paths in your bash_profile:

source ~/.bash_source

as yourself, run the same command. This avoids having to log out and back in again.

Now, running the following commands should output something familiar:

$ echo $PATH
# echo $PATH
$ sudo echo $PATH

Happy, good.

Now, what we have should be the Android bits in our paths as root, ourselves and running as sudo, so to check that, you can type into a terminal, this:

$adb version

my output is: Android Debug Bridge version 1.0.31

#adb version

$sudo adb version

they should all be successful and return information.

For thoroughness, also check this returns something, as it is also used:

$fastboot help

#fastboot help

$sudo fastboot help

This is the safest way to check fastboot, none of the above should return “command not found” if it does, then you’ve set one of the paths wrong in the above, go over it again, verify where your SDK tools etc are and amend as needed.

Editing your udev rules for device detection:

For ease, I’ve provided my udev rules here: http://pastebin.com/yvsCsXcH

Please append or copy this to the directory /etc/udev/rules.d/ you will need to be root to do this, or at least running the command as sudo

Enable debugging mode in your Nexus 7:

If not enabled, enable developer mode, by tapping Settings -> About phone -> Build number (x 7 times)
If not enabled, enable USB debugging in Settings -> Developer options -> USB debugging
Power on your Nexus 7, and plug it into your computer.

Run this command to check that you can see your device after a minute:

#adb devices

You should see something like this:

List of devices attached
012a2509bb200c12 device

2) Backup your Nexus 7 (if you want to, if you don’t care about returning to this state, skip this step)

To do this, navigate to a directory you want to save your backup to and run this command:

$adb backup -apk -shared -all

You will need to accept the prompts on your Nexus 7 screen and allow the backup to happen.

This will then backup to your directory for later if you want to restore your Nexus 7.

3) OEM Unlock your device to allow the custom bootloader and recovery to be installed:

If the device is already unlocked, skip this step. These steps will wipe all personal data from the device. If you want to keep this, then backup yourself, AND do step 2. If step 2 doesn’t work, or you can’t restore from it, this isn’t my fault.

With the device powered off, power on the device by holding the Power button + volume up + volume down.
The device will boot into the bootloader. Android lying on it’s back.
Plug the device into the computer via the USB cable.
On your computer, start a terminal. Type sudo fastboot oem unlock, followed by Enter

On the device screen, accept the terms of unlocking.
Boot the device by pressing the power button (pointed by an arrow with Start on the screen).

Device factory reset

If you get stuck in a bootloop rebooting the tablet after unlocking the bootloader… Here’s what you do:

During the bootloop.. hold the power button + volume up + volume down button simultaneously to get yourself back into fastboot mode as you were previously.
In fastboot mode.. use the volume keys to scroll to Recovery and the power button to select it.
In Recovery (Android robot on his back with a red triangle)… tap the volume up button and the power button simultaneously which will bring you into stock recovery. Again.. Don’t hold the buttons, just tap them simultaneously. Also make sure you’re holding the correct volume button. Up will be the volume key on the right.
Once you’re in Recovery.. perform a factory reset/data wipe and then reboot your tablet… you should now be back to the Welcome Screen.

4) Enable Debug mode and start adb:

Follow these initial steps on your device:

If not booted, boot the device into Android
Enable USB debugging on the device

on Ice Cream Sandwich (version 4.0) go to Settings and turn on USB Debugging (Settings > System > Developer options > USB debugging).
on Jelly Bean (versions 4.1 and 4.2) you need to enter Settings, About [Phone|Tablet] and tap the Build number 7 times to see the Developer Options.

on 4.2.2, (settings > about > tap on build number 7 times to activate the developer options menu item).
On either Android version you must then enable USB debugging via Settings > Developer options > USB debugging. You will also need to accept a host key on the device.

On the workstation-> adb kill-server; adb start-server
Plug the device into the computer via the USB cable.

Depending on the installed Android version, a popup will show up on the device with the host key that needs to be accepted for the device to communicate with the workstation.

Note, ‘adb devices’ should not show the device as ‘offline’. If it does, unplug the device, run adb under sudo on the workstation (sudo adb kill-server; sudo adb start-server), then plug the device back in.

In some cases, the device will continue to show offline, and the host key popup will not appear if the USB connection method is ‘MTP’ (default for some devices and versions of Android). Unchecking all options in the USB connection method (Settings -> Storage -> Menu -> USB computer connection -> MTP, PTP) seems to resolve this adb connection issue for some users.
Save the version of the current image on the device, if on Android, to use as a reference to revert back to. The version can be found by going to Settings > About Phone > Build Number.

5) Install Ubuntu flashing tool.

On the guide here: http://developer.android.com/sdk/index.html you will see many references to phablet-flash this is packaged in phablet-tools but is generally Ubuntu only, a helpful member of the Ubuntu community rewrote this Python tool into Go, another programming language which is easier to install.

So, firstly, install Go and Bazaar and any dependencies:

yum install golang bzr

Now, make a directory for your Go programs:

mkdir ~/gocode

then add it temporarily to your path:

export GOPATH=$HOME/gocode/

run this command to check it’s worked:

echo $GOPATH

Install Ubuntu-Device-Flash:

go get launchpad.net/goget-ubuntu-touch/ubuntu-device-flash

This, all going well, should download and install to gocode in your home directory, it doesn’t take long, seconds.

6) Flash your Nexus 7:

Change into the tool directory go the ubuntu-device-flash Go program:

$cd $GOPATH/bin/

Ensure your Nexus 7 is off, and plugged into your computer via USB.

Put your Nexus 7 into bootloader mode, with the device powered off, power on the device by holding the Power button + volume up + volume down.

Now, in a terminal, run this command to begin the flashing process, this should take care of everything, the whole process will take more then 10 minutes but should be less then 30.

./ubuntu-device-flash -bootstrap -channel=trusty

Now, it will go off to the website, download the trusty (developer version) of Ubuntu Touch for Nexus 7 (it detects your device) and install all the bits.

If successful, your Nexus 7 should reboot into recovery a couple of times, and reboot, once done, it should be at the Ubuntu Touch screen, if the screen is just black, and has been like that after rebooting, press the power once, it should wake up with Ubuntu Touch on your screen. If not, start again, probably from the bootloader screen mentioned above.

Thanks for reading, this is VERY VERY rough and too detailed in parts and not detailed enough in others, you might call it a brain fart. I’ll improve it if the interest is there.

Restoring Android (taken from: https://wiki.ubuntu.com/Touch/Install#Restoring_Android )
The Ubuntu Touch Preview image is not for everyone and may not suit your current needs (yet). The images can be found here. If you wish to roll back to an Android factory image, follow these steps:

Recall the version that was installed before flashing.
Download the factory image corresponding to your device’s model and version (initial table has links).
Ensure the device is connected and powered on.
Extract the downloaded file and cd into the extracted directory.
run adb reboot-bootloader

run ./flash-all.sh (use sudo if lack of permissions on the workstation don’t allow you to talk to the device).

If you want to lock the bootloader after restoring the factory image, follow these steps:

Power on the device by holding the Power button + volume up + volume down.
The device will boot into the bootloader.
Plug the device into the computer via the USB cable.
On your computer, press Ctrl+Alt+T to start a terminal. Type sudo fastboot oem lock, followed by Enter

Your device should boot into Android after the process is finished.

Once booted into Android, to restore your data you will need to do an initial setup of Android so you can enable the developer tools.

Once USB Debugging has been turned back on, plug it into you PC via USB if it’s not already and on your computer navigate to the folder where you stored your back and run this command:

$adb restore backup.ab

Follow the prompt on your tablet, press Restore my data.

Wait a while, if its a big backup, could take a long time.

That’s it. Hope this helped at least one person out there, even if it’s myself in a years time.

Site Resources:

http://fedoraproject.org/wiki/HOWTO_Setup_Android_Development
https://wiki.ubuntu.com/Touch/Install
https://launchpad.net/phablet-tools/ubuntu-device-flash
https://developers.google.com/android/nexus/images

7 Comments on “Installing Ubuntu Touch onto Nexus 7 2012 from Fedora 20 (in depth)

ahmet tekin
March 14, 2014 at 1:08 am

Thank you for the detailed walkthrough.

There is one small mistake I should mention though.

$source ~/.bash_source should be $source ~/.bash_profile.

Lee
March 14, 2014 at 6:20 am

Thanks, likely a typo when I was writing it, hope it helped you anyway.

Chris L
February 27, 2016 at 7:20 pm

Hi, thanks for the guide – I’m just looking to install Ubuntu Touch on my android tablet, although I am getting stuck when going to the $CD $GOPATH/bin/ directory as it say’s it does not exist, which it doesn’t as it wasn’t downloaded for some reason… I presume because of the age of the guide something must of changed, any ideas?

When I run this, this is the result:
[clech@localhost goget-ubuntu-touch]$ go get launchpad.net/goget-ubuntu-touch/ubuntu-device-flash
# launchpad.net/goget-ubuntu-touch/ubuntu-device-flash
../../../../src/launchpad.net/goget-ubuntu-touch/ubuntu-device-flash/snappy.go:153: undefined: snappy.AllowOEM
../../../../src/launchpad.net/goget-ubuntu-touch/ubuntu-device-flash/snappy.go:282: unknown provisioning.InstallMeta field ‘InitialVersion’ in struct literal
../../../../src/launchpad.net/goget-ubuntu-touch/ubuntu-device-flash/snappy.go:283: unknown provisioning.InstallMeta field ‘SystemImageServer’ in struct literal
../../../../src/launchpad.net/goget-ubuntu-touch/ubuntu-device-flash/snappy.go:297: unknown provisioning.InstallOptions field ‘Oem’ in struct literal

Lee
February 27, 2016 at 7:38 pm

Hi Chris, Ubuntu Touch support was stopped for Nexus 7 2012. It could be that the sources are no longer there.

In all honesty, it was unusable but served as a good bit of fun at the time.

Chris L
February 27, 2016 at 8:08 pm

Thanks Lee, I will abandon this then!

Lee
February 27, 2016 at 8:11 pm

Yeah, sorry for the false hope. I did then try installing Gingerbread on it, for kicks. Got the bootloader on it but couldn’t get a compiled ROM on it. Now it’s running Slimkat from slimroms and it’s fast enough for basic stuff. I used it in my car as a child appeasement device.

Lee
February 28, 2016 at 1:51 am

I reinstalled mine with slimkat which is usable.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.