Unlocking the Nexus S from Ubuntu

android ubuntu

I've had my Nexus S for a while now, and I've wanted to root it since I got it. Rooting it will give me full control over my device, which will in turn let me save money and protect my privacy (firewall, anyone?).

However, since it's my primary phone, I've been putting off messing with it. But with the release of Ice Cream Sandwich, and my discovery of the android.stackexchange.com site, I think I've got enough incentive and information to go ahead and root the thing.

There are several different tutorials out there on how to do this, but most of them seem to be out of date, incomplete, or unclear. These are the specific steps that I had to do for ubuntu 11.10, your mileagle might vary.

Make backups!

Unlocking the bootloader on the nexus S (and probably on all other android phones) causes a factory reset. Most of the settings/etc are synced automatically to google's cloud servers, so those aren't at risk. Assuming you've got the 'sync' settings enabled on your phone, the following will be safe from the factory reset: contacts, gmail, desktop wallpaper, picasa photos, etc.

  1. Make a list of all of the free apps that you have installed. Google doesn't sync that list, so you'll have to find and reinstall these after the factory reset. (Paid apps are attached to your account and will be remembered automatically).
  2. Copy the contents of your USB card somewhere. I did this by plugging it into my laptop's USB, then running:
    • tar czvf ~/local/backups/nexuss.backup.tgz /media/XXXX-XXXX/*

Upgrade (or install) the android SDK

I had previously installed the android SDK, which was apparently out of date. I don't really think this was necessary either, but it's certainly a good idea.

  1. cd ~/local/opt/android-sdk-linux_x86
  2. start the android SDK interface
    • ./tools/android
  3. follow the instructions in the UI to upgrade the various packages.

Install the fastboot executable

The fastboot executable is necessary for installing new boot images or changing the unlock state. It doesn't come with the compiled android SDK distribution, but it seems like it comes with the source version and/or the windows SDK. Finding a decent copy was the hard part.

  1. Download the file from the replicant project. They actually seem legitimate, as opposed to downloading random executables from webforums, which sets off every bad-idea-alarm in my head.
  2. Optionally verify that the executable is legitimate. This is nearly impossible, but I ran strings on it to see if it had anything obviously malicious.
    • strings ~/Downloads/fastboot
  3. Move that file to your android SDK tools folder
    • mv ~/Downloads/fastboot ~/local/opt/android-sdk-linux_x86/tools/
  4. Make that file executable
    • chmod 755 fastboot

Create a udev "rules" file

This step is probably not needed. Ubuntu already automatically detects my nexus when I plug it in normally. The reason I did this was because I was having trouble finding out how to get the phone to appear when running 'adb devices' when in fastboot mode, but that probably won't ever work.

  1. Plug in the device to a USB port
  2. Verify that it's detected by the USB system:
    • lsusb
    • look for an entry like:
      • Bus 002 Device 004: ID 18d1:4e21 Google Inc. Nexus S
  3. Create a new udev rules file with elevated permissions:
    • sudo $EDITOR /etc/udev/rules.d/51-android.rules

    Enter the following as the contents, making sure the idProduct values match the device outputs from lsusb. These lines are, in order, fastboot mode, normal mode, and recovery/debug mode. I've left out the 'OWNER' field because the GROUP field should be sufficient for things to work.

    SUBSYSTEM"usb", SYSFS{idVendor}"18d1", ATTRS{idProduct}"4e20", MODE="0666", GROUP="plugdev" SUBSYSTEM"usb", SYSFS{idVendor}"18d1", ATTRS{idProduct}"4e21", MODE="0666", GROUP="plugdev" SUBSYSTEM"usb", SYSFS{idVendor}"18d1", ATTRS{idProduct}=="4e22", MODE="0666", GROUP="plugdev"

  4. Set that file to be world-readable:
    • sudo chmod a+r /etc/udev/rules.d/51-android.rules
  5. Restart the udev service (this is an upstart job these days):
    • service restart udev

Unlock the bootloader

Finally, we're ready to do the unlocking!

  1. Unplug the phone from your computer.
  2. Turn off the phone.
  3. While holding down the 'Volume Up' button, press and hold the 'Power' button until the phone bootloader appears
  4. plug the phone back into your computer's ng USB port
  5. Check that the device is detected by fastboot:
    • cd ~/local/opt/android-sdk-linux_x86
    • ./tools/fastboot devices
    • Confirm that your device is listed. If not, time to troubleshoot. (Good luck!)
  6. Run the unlock command from your computer:
    • ./fastboot oem unlock
  7. On the phone, follow the instructions to confirm the unlocking and the factory reset
  8. Restart the phone when done

Reinstall/restore files/etc

Now that everything is unlocked, go through the initial setup procedure again, reinstall apps, set up accounts again, etc. A surprising number of things get synced by google.

Next Steps

Now that the phone is unlocked, it's time to do something with it! I'm not completely sure which way I'll be going with this, but some of the options are:

And of course once Android 4.0 (Ice Cream Sandwich) gets pushed to my phone, I'll probably have to do this all over again. But then that's why I'm documenting this in the first place.

Things that aren't needed

I found several things around the web that didn't seem useful or relevant for unlocking/rooting the phone. They probably serve other purposes, but I haven't come across those yet. Those include:

  1. creating ~/.android/adb_usb.ini . I'm working with fastboot, not adb, so this wasn't needed.

Other References

These sites/pages were very helpful while sorting this out: