Friday, December 31, 2010

Tether Android Phone to Ubuntu for Internet Connectivity

I take no credit for this. This article is a reproduction of Shannon VanWagner's in case his ever goes down or is inaccessible

Important note for 64-bit Linux users: adb needs 32-bit libraries to function, so simply do a:
sudo aptitude install ia32-libs
before all this.

(Update 09-03-10 - Get the python script for setting this up automatically via this link [ sha1sum: bee940daef16aaa0439a0fb04d4043abb6b08bed ]). Based on reader comments, I've added the functionality for the script to use either yum or apt-get (Fedora or Ubuntu). I've also changed the script so that it will add udev rules to allow HTC, Motorola, and Samsung Android-based phones. 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.)
Based on reader comments, I've added the functionality for the script to use either yum or apt-get (Fedora or Ubuntu). I've also changed the script so that it will add udev rules to allow HTC, Motorola, and Samsung Android-based phones. 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.)

I wanted the capability to tether my Droid as an Internet modem to my Ubuntu GNU/Linux machine using the USB cable.

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 a purchase price. Though my phone is rooted, I'm a cheap... errr... frugal guy and wanted to find a free way.

What I found are some easy tethering instructions by the masterful Shwan.c (link at using James Perry's azilink 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 machine (Works with 9.10 & 10.04 so far - 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 - these instructions have been tested 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):
(instead of steps 1-3 you can alternatively find the adb tool in various places on the web without having to jump through all the hoops of getting and installing the rest of the Android SDK)
1.) Download the current Android SDK (for Linux (i386)) from:

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

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) note: I chose instead to put the adb executable in the azilink folder within my /home. It doesn't really matter where it is as long as you call it properly when executing it.)
#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"

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

$ adb devices
List of devices attached

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/yourusername/Downloads/
mkdir azilink
cd azilink
adb install -r azilink-2.0.2.apk

11.) Create a replacement resolv.conf file to be copied over to your /etc directory at run-time: (note: I backed up my original /etc/resolv.conf beforehand just to be safe.)
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

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:

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.

(Update 09-03-10 - Get the python script for setting this up automatically via this link. Based on reader comments, I've added the functionality for the script to use either yum or apt-get (Fedora or Ubuntu). I've also changed the script so that it will add udev rules to allow HTC, Motorola, and Samsung Android-based phones. 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.)

If you're trying to set this up on CentOS and it's not working, checkout hughesjr's post on

(08-14-2010) For Gentoo GNU/Linux users, checkout "Tether your Motorola Droid on Gentoo Linux (USB Version)" on the Faction Clash blog

For those looking for similar instructions for Mac OSX, checkout the article "Tethering Your Android Phone to OS X via USB" on

Haven't replaced your iphone with the Android yet? Checkout Ashton Mills' article at to tether your iphone to Ubuntu GNU+Linux.

Update: 08-31-10 - Just received the Android 2.2 (froyo) update for my Verizon Droid Incredible. Tethering works perfectly for me after the update.

Shannon VanWagner
Updated 12-13-10

PS3 Media Server on 64-bit Linux

I was having the darnedest time getting MKV files to play from PS3 Media Server from fresh Ubuntu 10.04 Lucid Lynx. They worked fine from Windows and from an old 32-bit 9.04 Jaunty Jackalope system. Turns out Warriorcookie found the problem. 64-bit Linux systems need to install 32-bit libraries (ia32-libs for Ubuntu) for some packages, including Tsmuxer, apparently. So I simply:

sudo aptitude install ia32-libs

Then I rebooted and all was well. WOOHOO!!

Wednesday, December 29, 2010

The "Find" Command

The find command is not only useful for finding files by name, size, owner, etc, but it is also very powerful in limiting files to which you apply other commands either by using the pipe or arguments to find. For example, to change permissions on files only you can use:

find -maxdepth 1 -type f -exec chmod 644 {} \;

This command will change permissions in the present working directory (-maxdepth 1) to 644 on files only.

To change permissions on directories only use:

find -maxdepth 1 -type d -exec chmod 755 {} \;

This command will also be limited to the present working directory. It will change permissions to 755 on directories only. If you want to control recursion, you can use a different number with the -maxdepth option or leave it out altogether to recurse into all lower directories. Be careful, though, the find command is very powerful and can lead to unexpected and disastrous results if not used properly.

Sunday, December 19, 2010

Change Files on Droid 2

After rooting the Droid 2, there are sometimes files you want to change. You can pay for the Root Explorer app or use the free Android Terminal Emulator with linux commands on your phone. To change the system folder and below from read-only to read-write, do the following:

mount -o remount,rw -t yaffs2 /dev/block/mtdblk3 /system
rm /system/app/Gmail.apk

Saturday, December 18, 2010

Root The Droid 2

This is from other people: (there are other ways, like using adb from the Android SDK)

Visit the market and get the free Android Terminal Emulator installed.
Visit the market and make sure you have Astro installed.
Grab with your phone
Use Astro to navigate to the /sdcard/download folder
Long press on the file and "extract to this directory"
The 4 files, from the zip file should now be in the /sdcard/download folder (rageagainstthecage-arm5.bin, su, superuser.apk and busybox.
What are we going to do?
Steps 1- 5: Change to the /tmp folder on your phone, copy the file to the tmp directory, change its permissions. run it, and wait.

Step 6: make sure we can proceed

Steps 7 - 14: make system read-writable, copy the superuser. su and busybox files to where they need to go, use chmod to change their permissions, then make the system folder read-only, and exit Terminal Emulator.

If you want to know more about the commands being used here: cd, cp, chmod, mount, and exit are all Linux commands you can look up on your favorite search engine.

Okay, let's do it - type the blue parts in Terminal Emulator

cd /tmp
cp /sdcard/download/rage*.bin /tmp/
chmod 777 rage*.bin

This will take some time, just wait for the $ to show up so you know it is done.
Go to Settings > Applications > Manage Applications > Terminal Emulator > and Force Stop the application
Sanity check - Go into Terminal Emulator again and make sure you have a # symbol as a prompt. If so you are ready to proceed.

mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
cp /sdcard/download/Superuser.apk /system/app/Superuser.apk
cp /sdcard/download/su /system/bin/su
cp /sdcard/download/busybox /system/bin/busybox
chmod 4755 /system/bin/su
chmod 4755 /system/bin/busybox
mount -o ro,remount -t ext3 /dev/block/mmcblk1p21 /system

Thursday, December 2, 2010

Setting Up a Separate Data Partition

Now that I went through the process of learning how to move /home to a separate partition, I learn that it isn't always the best practice. Actually, if one is running multiple versions of Linux, it can cause problems because configuration files are stored for each user in the /home folder and they will rarely be compatible from one installation to the next.

Still, I learned a lot and can apply what I learned to an even better alternative—keeping /home on the root partition but having a common, separate /data partition. This way, you can easily backup the configuration files in your small /home folder if you want (although this data won't typically be as important as user documents, etc.)—even back it up to the /data partition—and keep them separate to each installation (if you have multiple on one machine), while storing all of your documents, photos, videos, audio, etc. on the one, separate /data partition. Pretty smart idea I got from the Ubuntu Forums.

I plan to implement this soon, and many of the same principles and steps from moving /home to a separate partition will apply to setting up a separate /data partition.

Wednesday, December 1, 2010

Move Home Folder to Separate Partition

*NOTE* See "Setting Up a Separate Data Partition" before deciding to put your home folder on a separate partition.

There are several benefits to having the home folder (the one in which all user data is kept) stored on a separate partition, not the least of which is making re-installs or new installs cleaner and separate from user data. As with most things on this blog, I learned this from other sources and am consolidating the steps here for documentation's sake and to include small things that were left out of other tutorials.

First, boot from an Ubuntu CD so you are not booted from the drive you need to change. When in the Live CD environment, use GParted to repartition your hard disk drive and create an empty partition to be your home partition, formatted with the same filesystem (i.e. ext3 or ext4) as your root linux installation. I won't cover the details of this process.

Now, for this example, we'll assume your linux root partition is on the hard disk drive /dev/sda and found at /dev/sda5. We'll also assume the new, empty home partition is at /dev/sda7 and both are formatted with the ext4 fielsystem.

Since we booted from Live CD, we must mount the original linux partition and the new one where home will be. We do this by executing the following commands in a terminal:

sudo mkdir /original
sudo mount -t ext4 /dev/sda5 /original
sudo mkdir /new
sudo mount -t ext4 /dev/sda7 /new

Next, we copy the original home to the new home partition, move the original home to home_backup just in case we need a backup, then make a fresh and empty home folder on the root partition into which the new home partition will be mounted:

cd /original/home
find . -depth -print0 | sudo cpio –null –sparse -pvd /new/
sudo mv /original/home /original/home_backup
sudo mkdir /original/home

The above "find" command is one place I ran into problems. The guides I found did not have "sudo" after the pipe, which caused the copy operation to fail due to "permission denied" errors.

Now we need to backup the fstab file, then open it with an editor. (The following uses GEdit graphical editor. You may use your favorite editor as long as you have root privileges. For example, to use a terminal editor, replace the whole gedit line below with "sudo nano -w /original/etc/fstab"):

sudo cp /original/etc/fstab /original/etc/fstab_backup
gksudo gedit /original/etc/fstab

Now add a line to fstab that mounts the home partition into the /home folder on the root partition at boot time:

/dev/sda7 /home ext4 nodev,nosuid 0 2

Another problem I had related to file and folder ownership. I had two users in my home folder, one with user id (uid) 1000 (we'll call him bob). Some of the copied folders and files showed ownership of user "root" instead of uid 1000. To fix this, still booted from the Live CD, I used the following command after ensuring the new home partition was mounted and changing to the proper folder (i.e. "cd /new/bob":

find -user root -print0 | sudo xargs -0 chown 1000:1000

The "find" portion of the above searches the present working directory and below for files and folders owned by "root". The xargs feeds each line produced by the "find" command to chown (change ownership), which then changes the ownership to the uid 1000.

Now you can reboot normally.