Xperia on Ubuntu (Udev rules, Flashtool, ADB&Fastboot)

Search This thread

Logseman

Senior Member
Nov 22, 2010
2,513
651
35
Tenerife
logseman.svbtle.com
This is a thread written to try and get poor MilkyJoePD up and running with his Ubuntu build, but it should be of help to anyone.

First of all, what you need:

1) Any version of Ubuntu from 10.04 onwards, with superuser access. The upcoming LTS Ubuntu 12.04 will be a great idea when it comes out, as it'll be maintained for 5 years (so the instructions to install it there will be valid for all that time).
2) Your Xperia Play (or any Xperia phone actually).
3) A Micro USB cable to connect it.
4) An open mind about terminal emulators. They're useful because they allow you to do things quickly and cleanly, if you just know their syntax.

What will we be doing in this thread: we'll set up our Xperia Play so that it gets recognized properly by Ubuntu. In addition, we'll set up ADB and Flashtool, which are programs with which our Xperia Play can interact. Lastly, we'll cover how to summon the "adb" and "fastboot" commands from any point in the terminal, by adding them to the $PATH variable.

Setting up the Xperia phone: udev rules

Android devices don't need specific drivers to work in Linux: you can plug an Android phone and it will be recognised as a flash drive. However, if we want deeper levels of interaction, such as the ones which ADB, Fastboot and Flashtool provide, we have to set up udev rules. Long story short, udev rules allow us to give the proper permissions that these modes require without having to function as superuser the whole time (an undesirable state of things in Ubuntu). Much more about them can be found here for the curious minds out there.

But let's not get lost. We want to set up udev rules, so we'll do it. First of all, we need to know the following: a device connected while it functions normally is not "seen" as the same device when it's connected in the Flash or Fastboot modes. In order to identify it, we can run "lsusb" which lists all of the ports, and connected devices, in our computer.

So, let's connect a Xperia phone which is turned on. We don't have to mount the sdcard as a flash drive, just plug it in. Once you have done that, open a terminal and type
Code:
lsusb
It will list you a boatload of devices, but only one of them is relevant to you right now:
Code:
Bus 00x Device 00y: ID 0fce:aaaa Sony Ericsson blah blah
The device is identified with two alphanumeric chains. The first one is the vendor ID, and the second one is the Product ID, which are the identificators we're going to use for the udev rules later on.
Let's switch off our phone, and plug it in "Flash" mode (hold the Back button while you connect it). Run "lsusb" again in the terminal again, and you'll find:
Code:
Bus 00x Device 00y: ID 0fce:bbbb Sony Ericsson blah blah
The Vendor ID is the same (0fce) for all Sony Ericsson devices, but the Product ID is different, as you can see. This is consistent with the idea that it's identified as "another" device.
The last part would be plugging the phone in Fastboot mode, holding the Search key while we plug the phone. Typing "lsusb" in the terminal again will give us:
Code:
Bus 00x Device 00y: ID 0fce:cccc Sony Ericsson blah blah
Which is, as we know already, a different Product ID.

Now that we have the device ID needed for the udev rules, we can write them. The most expedite way is to write in that lovely terminal:
Code:
sudo gedit /etc/udev/rules.d/99-android.rules
That means, we'll use the standard text editor (gedit) to create the file 99-android.rules in the /etc/udev/rules.d folder. If we visit said folder we'll find other udev rules created already, but they're not interesting for our task. Notice that we ask for superuser permissions with "sudo" as we need them to write or modify udev rules. Once we have put our password we'll find an empty text file. And now we just copy-paste the following syntax:
Code:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”aaaa″, MODE=”0666″
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”bbbb″, MODE=”0666″
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”cccc″, MODE=”0666″
In human language, this means "Give the devices that are connected through USB and which have the mentioned ID codes the permissions 0666 (read/write access), which need root access".

Once we've filled the gaps, we just save the file. After we close it, we have to type in the terminal "sudo restart udev" and we've taken care of that part. Rebooting the computer has the same effect, but it's a bit of overkill, really.

Flashtool

With the udev rules fixed, we can go to the next step, which would be using Flashtool. It is necessary to mention that unlike the Windows version, Flashtool doesn't need any installation of any kind in Linux, you just run the program (the file called Flashtool) and you're set. You have to download the Flashtool folder, uncompress it and run the program. The folder is compressed in .7z format: Ubuntu doesn't manage 7z packages "out of the box", but that's no problem: go to your terminal, type:
Code:
sudo apt-get install p7zip-full
and that should take care of it. If you're not familiar with that command, "apt-get install" is the way to install packages from your existing repositories in Debian/Ubuntu; installing software in Ubuntu requires superuser access, as I'm sure you know. p7zip-full is a package which adds 7zip support to the archive manager of Ubuntu.

I won't cover how to use Flashtool, since I already did so in this post. While I made the tutorial for an older version of Flashtool, the base functions are exactly the same as before.

Optional: ADB and Fastboot; setting them in $PATH

OK, now we're going to the stronger stuff: if you want to do a bit more than restoring official ROMs and flashing kernels you'll do well in using the ADB and Fastboot programs. They're part of the platform tools of the Android SDK. You can download the latest Android SDK here: http://developer.android.com/sdk/index.html

Once you've downloaded and uncompressed the Linux version of the SDK, go to the "tools" folder and run the "android" file (you need to mark it as executable first, in the properties). That file is the Android SDK Manager. Once it's running, you only need to install the SDK Platform Tools package. The rest are not necessary for our purposes.

Once you install the package, you'll notice that the folder where you unpacked the SDK is bigger. You'll find there the "platform-tools" folder, which contains adb and fastboot. You can run them from a terminal, but that requires you to have your terminal running in the exact folder where your /<Path/to/SDK> directory lies. This can get old really quickly if you use ADB and/or Fastboot frequently, so we'll do a trick that will allow us to summon them from any folder: we'll add them to our PATH variable.

In order to do this, we need to open a new terminal. It will start in our home directory. There is a file called .bashrc in our home folder that we need to tweak, so let's go to it. You don't see it normally, as it's hidden. All files which begin with a . in Linux will be hidden by default. You can see them in Nautilus by pressing Ctrl+H, and in a terminal by typing "ls -a". At any rate, this file is hidden because you usually don't need to touch it, but we'll do it here.

In our terminal, we write
Code:
gedit .bashrc
Again, gedit is the standard text editor in Ubuntu.

We see a lot of stuff we don't need to touch. We just need to go to the final line, after the word "fi" and write below:
Code:
# ADB and Fastboot direct link (this is a comment, so we remember what we did)
PATH=$PATH:/home/Path/to/SDK/platform-tools/
export PATH

We save the modified file, close any terminal we had left open, and now we can use adb and fastboot directly from any folder. Just connect your device with debug mode on for example, and type "adb devices": you should see the ADB identificator of your device.

And with that, I cover the installation guide of Xperia phones in the Ubuntu environment. I hope it's useful to everyone, particularly to MilkyJoePD who has inspired me to write it. If I've missed something I should have mentioned, by all means say it.
 
Last edited:

captain67

Senior Member
May 23, 2011
1,068
217
Aldergrove
Haven't used Ubuntu for a while but I'm taking note of this for later. Thank you for the info.

Sent from a Galaxy far, far away
 

williamwd

New member
Feb 15, 2012
4
0
Santa Maria
don't forget to install de dependencies:
Code:
sudo apt-get install libusb-1.0
on 64 systems, you need 32bits libraries, so run:
Code:
sudo apt-get install ia32-libs
 

MilkyJoePD

Senior Member
Oct 30, 2011
990
187
With the news of Sony not releasing ICS, I decided to try again to get fastboot working.

While installing the dependencies, I get this:

W: Duplicate sources.list entry cdrom://Ubuntu 11.10 _Oneiric Ocelot_ - Release i386 (20111012)/ oneiric/main i386 Packages (/var/lib/apt/lists/Ubuntu%2011.10%20%5fOneiric%20Ocelot%5f%20-%20Release%20i386%20(20111012)_dists_oneiric_main_binary-i386_Packages)
W: Duplicate sources.list entry cdrom://Ubuntu 11.10 _Oneiric Ocelot_ - Release i386 (20111012)/ oneiric/restricted i386 Packages (/var/lib/apt/lists/Ubuntu%2011.10%20%5fOneiric%20Ocelot%5f%20-%20Release%20i386%20(20111012)_dists_oneiric_restricted_binary-i386_Packages)
W: You may want to run apt-get update to correct these problems



Where do I go from here?
 

skeltonh

Senior Member
Oct 31, 2010
113
12
New Castle, PA
Remove CD-ROM reference from sources

Edit your sources and comment-out / turn off the references for the installation disk (CDROM/DVD). It should be the first thing you turn of after any install anyway. In my humble opinion.

Then run

sudo apt-get update
sudo apt-get -f install

this should resolve any pending issues and get you running.
 

MilkyJoePD

Senior Member
Oct 30, 2011
990
187
Or can somebody can tell me what it means so I can Google it?

Sent from my R800i using XDA
 

IE-coRe

Senior Member
Mar 17, 2011
1,319
179
Güstrow
I have a problem, when I try to use fastboot even in the platform-tools folder it says:
fastboot: command not found
 

JnkPanchal008

Member
Dec 26, 2011
34
2
Bengaluru
I have created udev rules as said above, but flashtool still says 'Add udev rules'.

What I am missing here. I'm using Ubuntu 12.04.
Any help is appreciated.
 

cyrusalmighty

Senior Member
May 30, 2009
1,110
240
Hartford
Big Thanks for this Tutorial Logesman. :good: Just wanted to add that I think...anyone having trouble installing SDK + Manager has to install Java JDK first. Yes, I got stuck at installing SDK.:silly: I tried to run android file in tools folder (as executable) which opens manager.
From Terminal:
sudo apt-get install openjdk-7-jdk openjdk-7-jre
 

paxChristos

Retired Forum Moderator
Aug 27, 2011
2,032
1,779
37
West Bend
i am unable to run "adb devices" command in ubuntu 12.04.. please help :crying:







I am having same problem on 12.04! I did everything in this thread afaik, and the ubuntu forums. I could really use some help , because I also have problems with adb.

Sent from my R800i using xda premium

Have you tried running adb as root? (After a week of testing 12.04, I left to go back to 10.04, a much better release, imo)

Pax

Sent from my R800x using Tapatalk 2
 

syin16

Senior Member
Oct 9, 2010
103
11
Teluk Intan
I have a problem, when I try to use fastboot even in the platform-tools folder it says:
fastboot: command not found

seems like you didn't path the fastboot command correctly, try check back again at your .bashrc

i am unable to run "adb devices" command in ubuntu 12.04.. please help :crying:

same case as the above

I am having same problem on 12.04! I did everything in this thread afaik, and the ubuntu forums. I could really use some help , because I also have problems with adb.

Sent from my R800i using xda premium

would you mind telling what does the error says?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 37
    This is a thread written to try and get poor MilkyJoePD up and running with his Ubuntu build, but it should be of help to anyone.

    First of all, what you need:

    1) Any version of Ubuntu from 10.04 onwards, with superuser access. The upcoming LTS Ubuntu 12.04 will be a great idea when it comes out, as it'll be maintained for 5 years (so the instructions to install it there will be valid for all that time).
    2) Your Xperia Play (or any Xperia phone actually).
    3) A Micro USB cable to connect it.
    4) An open mind about terminal emulators. They're useful because they allow you to do things quickly and cleanly, if you just know their syntax.

    What will we be doing in this thread: we'll set up our Xperia Play so that it gets recognized properly by Ubuntu. In addition, we'll set up ADB and Flashtool, which are programs with which our Xperia Play can interact. Lastly, we'll cover how to summon the "adb" and "fastboot" commands from any point in the terminal, by adding them to the $PATH variable.

    Setting up the Xperia phone: udev rules

    Android devices don't need specific drivers to work in Linux: you can plug an Android phone and it will be recognised as a flash drive. However, if we want deeper levels of interaction, such as the ones which ADB, Fastboot and Flashtool provide, we have to set up udev rules. Long story short, udev rules allow us to give the proper permissions that these modes require without having to function as superuser the whole time (an undesirable state of things in Ubuntu). Much more about them can be found here for the curious minds out there.

    But let's not get lost. We want to set up udev rules, so we'll do it. First of all, we need to know the following: a device connected while it functions normally is not "seen" as the same device when it's connected in the Flash or Fastboot modes. In order to identify it, we can run "lsusb" which lists all of the ports, and connected devices, in our computer.

    So, let's connect a Xperia phone which is turned on. We don't have to mount the sdcard as a flash drive, just plug it in. Once you have done that, open a terminal and type
    Code:
    lsusb
    It will list you a boatload of devices, but only one of them is relevant to you right now:
    Code:
    Bus 00x Device 00y: ID 0fce:aaaa Sony Ericsson blah blah
    The device is identified with two alphanumeric chains. The first one is the vendor ID, and the second one is the Product ID, which are the identificators we're going to use for the udev rules later on.
    Let's switch off our phone, and plug it in "Flash" mode (hold the Back button while you connect it). Run "lsusb" again in the terminal again, and you'll find:
    Code:
    Bus 00x Device 00y: ID 0fce:bbbb Sony Ericsson blah blah
    The Vendor ID is the same (0fce) for all Sony Ericsson devices, but the Product ID is different, as you can see. This is consistent with the idea that it's identified as "another" device.
    The last part would be plugging the phone in Fastboot mode, holding the Search key while we plug the phone. Typing "lsusb" in the terminal again will give us:
    Code:
    Bus 00x Device 00y: ID 0fce:cccc Sony Ericsson blah blah
    Which is, as we know already, a different Product ID.

    Now that we have the device ID needed for the udev rules, we can write them. The most expedite way is to write in that lovely terminal:
    Code:
    sudo gedit /etc/udev/rules.d/99-android.rules
    That means, we'll use the standard text editor (gedit) to create the file 99-android.rules in the /etc/udev/rules.d folder. If we visit said folder we'll find other udev rules created already, but they're not interesting for our task. Notice that we ask for superuser permissions with "sudo" as we need them to write or modify udev rules. Once we have put our password we'll find an empty text file. And now we just copy-paste the following syntax:
    Code:
    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”aaaa″, MODE=”0666″
    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”bbbb″, MODE=”0666″
    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0fce″, ATTRS{idProduct}==”cccc″, MODE=”0666″
    In human language, this means "Give the devices that are connected through USB and which have the mentioned ID codes the permissions 0666 (read/write access), which need root access".

    Once we've filled the gaps, we just save the file. After we close it, we have to type in the terminal "sudo restart udev" and we've taken care of that part. Rebooting the computer has the same effect, but it's a bit of overkill, really.

    Flashtool

    With the udev rules fixed, we can go to the next step, which would be using Flashtool. It is necessary to mention that unlike the Windows version, Flashtool doesn't need any installation of any kind in Linux, you just run the program (the file called Flashtool) and you're set. You have to download the Flashtool folder, uncompress it and run the program. The folder is compressed in .7z format: Ubuntu doesn't manage 7z packages "out of the box", but that's no problem: go to your terminal, type:
    Code:
    sudo apt-get install p7zip-full
    and that should take care of it. If you're not familiar with that command, "apt-get install" is the way to install packages from your existing repositories in Debian/Ubuntu; installing software in Ubuntu requires superuser access, as I'm sure you know. p7zip-full is a package which adds 7zip support to the archive manager of Ubuntu.

    I won't cover how to use Flashtool, since I already did so in this post. While I made the tutorial for an older version of Flashtool, the base functions are exactly the same as before.

    Optional: ADB and Fastboot; setting them in $PATH

    OK, now we're going to the stronger stuff: if you want to do a bit more than restoring official ROMs and flashing kernels you'll do well in using the ADB and Fastboot programs. They're part of the platform tools of the Android SDK. You can download the latest Android SDK here: http://developer.android.com/sdk/index.html

    Once you've downloaded and uncompressed the Linux version of the SDK, go to the "tools" folder and run the "android" file (you need to mark it as executable first, in the properties). That file is the Android SDK Manager. Once it's running, you only need to install the SDK Platform Tools package. The rest are not necessary for our purposes.

    Once you install the package, you'll notice that the folder where you unpacked the SDK is bigger. You'll find there the "platform-tools" folder, which contains adb and fastboot. You can run them from a terminal, but that requires you to have your terminal running in the exact folder where your /<Path/to/SDK> directory lies. This can get old really quickly if you use ADB and/or Fastboot frequently, so we'll do a trick that will allow us to summon them from any folder: we'll add them to our PATH variable.

    In order to do this, we need to open a new terminal. It will start in our home directory. There is a file called .bashrc in our home folder that we need to tweak, so let's go to it. You don't see it normally, as it's hidden. All files which begin with a . in Linux will be hidden by default. You can see them in Nautilus by pressing Ctrl+H, and in a terminal by typing "ls -a". At any rate, this file is hidden because you usually don't need to touch it, but we'll do it here.

    In our terminal, we write
    Code:
    gedit .bashrc
    Again, gedit is the standard text editor in Ubuntu.

    We see a lot of stuff we don't need to touch. We just need to go to the final line, after the word "fi" and write below:
    Code:
    # ADB and Fastboot direct link (this is a comment, so we remember what we did)
    PATH=$PATH:/home/Path/to/SDK/platform-tools/
    export PATH

    We save the modified file, close any terminal we had left open, and now we can use adb and fastboot directly from any folder. Just connect your device with debug mode on for example, and type "adb devices": you should see the ADB identificator of your device.

    And with that, I cover the installation guide of Xperia phones in the Ubuntu environment. I hope it's useful to everyone, particularly to MilkyJoePD who has inspired me to write it. If I've missed something I should have mentioned, by all means say it.
    1
    I think the error was adb not valid command or something similar.

    Sent from my R800i using xda premium

    Then you don't have platform/tools in your paths

    Pax