Friday, August 19, 2011

Tether Android to Ubuntu / Fedora Linux

(Update 11-15-11 - CLICK HERE for the automatic setup script - Now Just 296KB! sha1sum: f3b79c2e191baf8060367681bae27ac75fab9886 ). Based on reader comments, I've added the functionality for the script to use either yum or apt-get (Fedora or Ubuntu). Includes updated Azilink by Charlie Snider - for Android 2.3.x. READ the install instructions here (e.g., PLUG YOUR DROID INTO THE USB FIRST!)) Let me know how it works for you in the comments.)



So if you're like me you recently picked up the fabulous Verizon Droid Linux-based phone, and now you're one happy camper.

I've been cruising along with my Droid (Android Linux based device) for a month now, and I'm happy as a clam. I have to tell you... The Verizon Droid is quite a fine Linux-based device indeed.

So now that I've used the Droid for awhile, I set out in search of a piece of functionality that I hadn't yet replaced from my Blackberry days. That is: The capability to tether my Droid as an Internet modem to my Ubuntu GNU/Linux 9.10 machine using the USB cable.

On the Blackberry, this was as simple as, a.) provisioning the data service through Verizon(yes, this does cost extra), and then b.) setting up the "Berry4All/BBTether" script (by the extravagant Mr. Thibaut Colar) on my Ubuntu Linux box.

In my search for a solution, the first place I checked for a tethering application was in the Android Market. And while there are many other applications, the only app I was able to find for tethering, required for my phone to be "rooted". And so instead of jumping right into that, I went looking for an easier solution, and voila! - I found it.

What I found are some easy tethering instructions by the masterful Shwan.c (link at ubuntuforums.org) using James Perry's azilink (modified for Android 2.3.x by Charley Snider) from Google Project Hosting, GNU+Linux, and the FOSS program openvpn. So now there was only one problem: I'm using the Verizon Droid, not the HTC Magic. The good news is that the process is generally the same, except for a difference in hardware id information for the udev rules settings in Ubuntu.

So after some minor changes, I've now successfully tethered my Verizon Droid via USB as a modem for my Ubuntu GNU/Linux 9.10 machine(Works with 10.04 too - only difference is that you may have to uncheck "Work Offline" in Firefox after connecting (Thanks to Gene for mentioning this)). Update:06-04-10 - I've tested these instructions and they work successfully with both the Motorola Droid and the HTC Incredible Android phones.

So here are the easy steps to get you up and running with using your Droid as a USB tethered modem (and a big Thanks to Shwan.c for posting the original idea):

1.) Download the current Android SDK (for Linux (i386)) from: http://developer.android.com/sdk/index.html

Update(thanks for comments!): 12-13-10 adb does not come with the new SDK by default so you have to add it via the Android SDK and AVD Manager.
2.) Extract the SDK, run the "Android SDK and AVD Manager", then to get the adb tool, install "Android SDK Platform-tools, revision 1":

tar xvf android-sdk_r07-linux_x86.tgz
cd android-sdk-linux_86
tools/android


In the Android SDK and AVD Manager, expand "Available Packages", put a checkmark by "Android SDK Platform-tools, revision 1", click "Install Selected" and follow the prompts to complete the download/installation of adb into your SDK folder (screenshot below).


3.) Change Directory into the "platform-tools" directory, then copy the "adb" application to your Ubuntu /usr/bin directory (sudo privs needed)
#From the extracted "android-sdk-linux_86" directory:
cd platform-tools
sudo cp adb /usr/bin/adb

4.) Create/edit/save a rules file for udev to allow your machine to see your device
sudo vi /etc/udev/rules.d/91-android.rules

Put the text below into the file(using "i" to enter "insert" mode and hitting the escape key to return to "select" mode before saving.. C'mon, what fun would Linux be without using vi? If you really don't like vi, you can substitute with something like gedit, or nano, or kate, or etc.), replace USERNAME with your Linux username, then type ZZ to save the file from vi.

SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", SYMLINK+="android_adb", MODE="0666", OWNER="USERNAME"
If you have an HTC Android phone - use this rule instead of the one above:
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", SYMLINK+="android_adb", MODE="0666", OWNER="USERNAME"
If you have the Samsung Galaxy Android phone, use this rule instead of the one above:
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", SYMLINK+="android_adb", MODE="0666", OWNER="USERNAME"  
If you have the Sony Ericsson X11 Android phone, use this rule instead of the one above (Thanks to Steven from the comments):
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", SYMLINK+="android_adb", MODE="0666", OWNER="USERNAME"If you have the LG Optimus V(Virgin Mobile) Android phone, use this rule instead of the one above: 
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", SYMLINK+="android_adb", MODE="0666", OWNER="USERNAME" 


5.) Set the appropriate permissions to the rules file you just created.
sudo chmod a+r /etc/udev/rules.d/91-android.rules


6.) Restart udev to load the new rule.
sudo restart udev


7.) Enable "USB debugging" on your Verizon Droid via Settings | Applications | Development


8.) Connect your Droid to the computer with the USB cable and then use the following adb command to check for your device.
adb devices


example:
$ adb devices
List of devices attached
040364FA0901E011


9.) Install openvpn on your computer so you can connect to your device with it.
sudo apt-get install openvpn
sudo /etc/init.d/networking restart
sudo /etc/init.d/network-manager restart



*For Fedora and Yum, replace the commands above with this:
sudo yum install openvpn
sudo /etc/init.d/networking restart



Note for those without Internet: If you need to install the openvpn package (and dependencies) separately, these packages are what you will need: (liblzo2-2 libpkcs11-helper1 openssl-blacklist openvpn-blacklist openvpn). It's best to use the package manager to install openvpn because it will automatically install the dependencies, but if you can't get your Ubuntu machine onto to the Internet, then you can download the above packages (in .deb format) to a separate medium (i.e., USB drive, CDR, etc.)separately and then install them in the order listed to achieve the same result as installing from the package manager.


10.) Install openvpn on your Verizon Droid. Note: the line "adb install" actually installs the azilink application on your Droid device. After azilink is installed, an icon that looks like a flying insect will appear on your Droid in th applications area.
cd /home/Downloads/
mkdir azilink
cd azilink
#Manually download the Azilink-debug.apk - fixed by Charley Snider for Android 2.3.x from

#http://code.google.com/p/azilink/issues/detail?id=43#c15
adb install -r Azilink-debug.apk
wget http://azilink.googlecode.com/files/azilink.ovpn


11.) Create a replacement resolv.conf file to be copied over to your /etc directory at run-time:
vi resolv.conf


#Type in the text below(hit "i" for insert first, then ESC after the insert, before saving) and then hit ZZ to save
domain lan
search lan
nameserver 192.168.56.1


12.) Now create a very small script to start the modem
vi start_modem


#Type in the text below, then hit ZZ to save
adb forward tcp:41927 tcp:41927
sudo cp resolv.conf /etc/
sudo openvpn --config azilink.ovpn


13.) Set your new script to be executable.
chmod 755 start_modem


14.) On your Verizon Droid, launch the azilink app and place a checkmark by "Service active" so it can receive the connection from your Ubuntu machine.


15.) With your wireless connection in Ubuntu "unchecked"(via right-click of the Network manager applet), launch the the connection script you just made in the Terminal:
/home/Downloads/azilink/start_modem


You should now be able to surf the Internet, using your Verizon Droid as a tethered modem. When you're finished - hit ctrl+c at the Terminal from which you started the connection script. Then uncheck "Service active" in Azilink on your Droid.


Here's a Speedtest (courtesy of speakeasy.net/speedtest) of the connection from Seattle, WA:
Download Speed: 1448 kbps (181 KB/sec transfer rate)
Upload Speed: 281 kbps (35.1 KB/sec transfer rate)


If you have any questions, feel free to leave a comment.

Sunday, August 14, 2011

Google+ Here's my invitation to you (about 150 of you actually)

For those who haven't signed up to Google+, I extend my invitation (about 150 of them actually).

http://goo.gl/X5zCf

With Google+ you get:

Circles - control who has access to what, where messages get sent, etc

Hangouts - Video Cam chat with several people at once (also share youtube videos in the main area)

Games - Addicting, fun, Destined to waste your time.. Awesome!

Sparks - follow/share/collaborate about your interests

And, the reason I like it best:

Data Liberation - Download all your input to Google+ at any time (in zipped format) (yes, unlike fb)

Plus - so much more...

Cheers!

Shannon VanWagner

Thursday, August 11, 2011

"Immutable" ( chattr setting ) - When You Can't Change a File in GNU/Linux



So today I learned about a little thing in the GNU/Linux filesystem called "chattr" and making files "immutable". Basically you can have a plain text file that you think you have full permissions over and then not be able to modify it, rename it, delete it, etc. This nifty (and possibly maddening) trick can be setup with the "chattr" command. See my examples below...

Create a simple text file
shannon@ubuntu-star:~$ echo Linux Rocks > testfile

Check the permissions of the file you just created:
shannon@ubuntu-star:~$ ls -l testfile 
-rw-r--r-- 1 shannon users 12 2011-08-10 23:47 testfile

Note that in the above state, I can write to the file, `mv` the file to a different name, `rm` it, etc. Now, for the magic (Or "basic commands" for a "novice" type stuff, according to http://tldp.org/LDP/abs/html/basic.html )

Use chattr to set the "immutable" attribute to the file.
shannon@ubuntu-star:~$ sudo chattr +i testfile 

Notice how nothing special shows in `ls` for the file:
shannon@ubuntu-star:~$ ls -l testfile 
-rw-r--r-- 1 shannon users 12 2011-08-10 23:47 testfile

And yet, magic ensues.. I can't edit the file, mv the file, rm the file, etc (even as root):
shannon@ubuntu-star:~$ echo Say it Again >> testfile 
bash: testfile: Permission denied
shannon@ubuntu-star:~$ sudo echo Say it Again >> testfile 
bash: testfile: Permission denied
shannon@ubuntu-star:~$ mv testfile testfile2
mv: cannot move `testfile' to `testfile2': Operation not permitted
shannon@ubuntu-star:~$ sudo mv testfile testfile2
mv: cannot move `testfile' to `testfile2': Operation not permitted
shannon@ubuntu-star:~$ sudo rm testfile 
rm: cannot remove `testfile': Operation not permitted

Amazing!

So now to stop the madness:
shannon@ubuntu-star:~$ sudo chattr -i testfile
shannon@ubuntu-star:~$ mv testfile testfile2
shannon@ubuntu-star:~$ ls -l testfile2
-rw-r--r-- 1 shannon users 12 2011-08-10 23:47 testfile2

So if you ever find yourself not being able to edit a file, and if you already know the partition you're working on is not set to read-only, and if you already know that you have full permissions to change a file - maybe "immutable" is your problem...

Setting the immutable property is only one of the options for the chattr command, run `man chattr` to read about other things you can do.

So I learn something new with GNU/Linux every day. Is this awesome or what?

PS: If you've ever wondered what chmod 753 means, here's the answer:
7 -  "owner" gets to read/write/execute
5 -  "group" gets to read/execute
3 -  "others" gets to write/execute

Cheers!
Shannon VanWagner