[Milestone 2 General] raj47i:
Chrooting Linux on Android is a very popular topic, and you can find many tutorials online. I am not going to post a detailed how to here.. but, I will explain the generalized steps for the process! If anyone have any questions or need help, feel free to ask!

Get Root Access on your phone

There are many ways to get root access; Easiest will be using z4root or SuperOneClick ! Rooting is mandatory because: You need to install Busybox; Need to mount file system, etc..​

Install SuperUser App from the Market

This application allows you to grant Root access to other applications (when needed). Depending on how you rooted your phone, superuser.apk may be already installed on your phone.​

Install Busybox App from the Market

Depending on how you rooted your phone, Busybox may be already installed on your phone. In any case install this app from the market and update your busybox to the latest version. Busybox is a set of commonly used linux commands, which are not available in android by default. Eg: cp, chroot, etc.​

Install Connectbot from Android market

Connect bot is a terminal client application for android. There are other alternatives but, I recommend Connectbot! Also Connectbot has SSH support, so if you are installing an SSH server on your Ubuntu, you can connect to it using connectbot and you may totally skip the VNC for GUI. Anyway, note that you need a terminal app to start the chroot daemon!​

Install AndroidVNCViewer from Android market

With androidVNCViewer we can get GUI access to our ubuntu! This App works so fine in my Milestone 2 with Ubuntu; It even supports mouse pointer!​

Download/build a Linux rootfs for your flavour of linux

Now, you need the Ubuntu/Debian/Other linux file system for your Phone's processor. Like most of the Android phones, Milestone 2 uses an ARM processor. And Ubuntu offers full support for ARM processors. It is so easy to build ubuntu for ARM(OMAP) platform using rootstock/bootstrap method. I used rootstock method for Ubuntu as explained here.

PS: For your first time, make sure you build, "Ubuntu Lucid" (just use the --seed/-s parameter of rootstock command. I was not able to use 11.04(Natty). Once you get Lucid to work, you can surely try yourself for the other versions! ;) )​

Create a mountable .img file with a size suited for you

From rootstock, you will get a .tgz file! You will need to convert this to a mountable .img file.

In order to create an empty ubuntu.img file, use the followed command in your ubuntu-desktop's terminal; the last arguement (2048) specifies size of the Ubuntu rootfs (If you need much disk space when you are in ubuntu, use a large value here. Normally 2GB will be sufficient for you; even with GUI/VNC).

dd if=/dev/zero of=ubuntu.img bs=1MB count=0 seek=2048

Next, format our empty ubuntu.img with a suitable ext2/ext3/ext4 file system!

For Milestone 2, you should use ext3 (I think it does not support ext2). ext4 is supported only in Gingerbird+. So, you should use the appropriate command based on your mobile

mkfs.ext2 -F ubuntu.img
mkfs.ext3 -F ubuntu.img
mkfs.ext4 -F ubuntu.img

You can find out the suitable file system by opening Connectbot in your mobile and entering the followed command. In the output, look for words ext2/ext3/ext4!

su
mount

Once you format ubuntu.img with appropriate file system. We should temporarily mount the ubuntu.img in a somewhere and we should extract the armel-rootfs-xx.tgz to it. You can use these commands

sudo mount -o loop ubuntu.img /mnt
sudo tar -C /mnt -zxf armel-rootfs--xx.tgz
sudo umount /mnt

Download(and modify) or create a Shell script for automatically mounting your Chroot image

This is the most important part, we have to run a set of commands in our android shell to get into the ubuntu. To make things easier, we will write these command-sequence in a shell script, and whenever we need we simple call this script. :) Cool isn't it?. Basically this is what this script should do:

1. Check if there exists an ubuntu.img file as we specify in command line
2. Create a loop device with the ubuntu.img - ie. Make android(linux) believe that ubuntu.img is a mountable device.
3. Mount the newly created loop device to a folder. My script mounts the image to /data/local/chrootos
4. Set some environment variables in the shell
5. Mount the [I]devpts, proc, sysfs[/I] for the ubuntu!
6. Run the Chroot command. This command actually changes the root of file system to a new directory we specify. ie. we fake [B]/data/local/chrootos[/B] as the rootfs![B]/[/B]

Create a folder in your Phone's SD Card and copy one or more(If you want to choose between: Debian/Ubuntu/Puppy/etc) .img files and your shell script for booting linux into it.

Create a folder named .chroot in your SD Card. If you have a "." as the first character, this folder will be hidden in the Android File Browser. And will avoid you accidentally modifying these files.​

Get into your Phone's Shell through ConnectBot / USB-ADB / Terminal Emulator

Enter su in the terminal to get root access

Remount your Android filesystem to get write access to your phones

By default, the android file system is read only. So in order to write to the files sytem, we have to remount it with the following command.

mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system

Copy your bootscript to /system/bin so that you can easily start your Linux

If you have downloaded my bootscript, the file name will be bl - short for boot linux;). So, once you copied you will have your shell script at /system/bin/bl. Once we copy the shell script to the bin directory, it will work as a shell command.​

Start your linux and customize it

If you have done everything correctly so far, you can now boot into your ubuntu.img with the following command. Note that you do not need to specify the full file name "ubuntu.img".

bl ubuntu

Start your linux and customize it

If Chroot was a success, you will see the ubuntu shell prompt. And then you can start installing more stuff, etc. root@localhost:​

Downloads & Screenshots

Screenshots: http://goo.gl/PzVI0

My Shell Script for starting linux: http://goo.gl/il3nJ

My ubuntu.img: Coming Soon
​

Password

arunraj.in

Common Errors

The most common error will be when we are dealing with the "loop device". Because, according to the apps installed in your device, there may not be a free loop device available. If you are facing errors, feel free to ask me and I will try and help!​