[Defy Android Development] cocus:
Hi. Well, I've researched a lot to get to this. For now, I haven't used the mount commands (because there isn't support for loop devices, or at least, that I think; in my stock rom). Because of that, the files are in a folder in the Filesystem of android.

There are Screenshots at the end of my post.​

The steps are a little bit long, but I assure you, that LXDE running on VNC + debian applications (like amsn, ice weasel, etc) is f*cking amazing.

Revision of the Tutorial: 3. Date: 14/feb/2011.

What you need:

A PC with Debian (lenny or squeeze) or a VM with that OS (you can use Ubuntu too) with 2GB or more disk free space

A internet connection (or packages of Debian armel locally downloaded)

A rooted Motorola Defy (requiered to run some commands later)

Overclocked Motorola Defy (optional, but increases the performance) (find "SetVsel" on market)

At least 300MB (for "console only") or 750MB (for "console" and graphical stuff) on the /data/local of the internal phone memory (I'm not using mount points, for some software issues with the kernel)

Same amount of free space on your SD (to copy files from PC to Internal storage. you could use adb, but I like the SD method, as you don't need any drivers)

A lot of time to do this (optional hehehe)

As I don't like to use "su" or "sudo" commands, I use a Root Terminal.

(sudo su)

Well, create a directory in your account folder, I mean if you're the user "cocus", create a folder called /home/cocus/debian

You could use any other folder, but take care in the scripts, and replace with the one that you're using.

We have to be in the parent folder, so make a cd to /home/cocus/

Next, get the packages to create the deboostrap, and run the chroot.

To do this, if you're on Debian run the following:

apt-get install qemu-user-static debootstrap

But if you're on Ubuntu, use this:

apt-get install qemu-arm-static debootstrap

Then, we have to get the armel files, using deboostrap:

If you want to install Debian Lenny (5.0, tested by me)

debootstrap --verbose --arch=armel --foreign lenny debian http://ftp.us.debian.org/debian

And for Debian Squeeze (6.0, tested by johnw.xda without the graphical stuff)

debootstrap --verbose --arch=armel --foreign squeeze debian http://ftp.us.debian.org/debian

In fact, we could use a Ubuntu distro, like karmic. But I recommend debian, because it has more support for armel.

Ok, that will be at least 5 mins downloading data and unpacking other stuff. When that finishes, we have to tweak the system to run without errors.

First thing, is to create the mount point of the sdcard (in fact, is a system link).

mkdir debian/sdcard

Second thing, is to run the chroot and configure some things:

cp /usr/bin/qemu-arm-static debian/usr/bin
chroot debian /bin/bash

If succed, you will have a # (root) shell, then put the following:

/debootstrap/debootstrap --second-stage
adduser

Then provide a username and password.

Now run the following, to fix some configs:

echo 'nameserver 8.8.8.8' > /etc/resolv.conf
rm -f /etc/mtab
ln -s /proc/mounts /etc/mtab

If you're installing Debian Lenny, then run this:

echo 'deb http://ftp.us.debian.org/debian lenny main contrib non-free' > /etc/apt/sources.list
apt-get update

But if you're installing Debian Squeeze, then run this:

echo 'deb http://ftp.us.debian.org/debian squeeze main contrib non-free' > /etc/apt/sources.list
apt-get update

With that, the system will run ok in the Defy, but I would like to add the x11, lxde, vnc packages (because installing on the chroot in pc is more faster than in the phone).

If you want LXDE, then do:

apt-get install lxde tightvncserver

But if you prefer IceWM instead LXDE, then:

apt-get install icewm tightvncserver

Ok, I really dont remember, but that stuff cost about 350MB more of disk. By the way, while installing the packages, it might ask something, you just say Ok on all messages and complete if it requieres.

Once finished, type

exit

Well, now we have to fix the "LC_LOCALE" error, and the "HOME=/root" for conveinence. To do that, in your local Debian (not the chroot), add the following lines to the file

/home/cocus/debian/etc/init.d/rc.

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export $PATH

export HOME=/root
export LC_ALL=C

Add these lines replacing the original PATH.

After that, we have to move the files to internal storage, so, to do that, I've used tar bzip2 to compress all the files and saving the attributes too.

tar -cjf /home/cocus/debian.tar.bz2 /home/cocus/debian/*

That command will generate a file in /home/cocus called debian.tar.bz2. Once you've got this, copy to your SD.

By the way, create a file called bootdeb in the SD root, with the following contents:

echo " "
echo " a888a "
echo " d888888b "
echo " 8P YP Y88 "
echo " 8|o||o|88 "
echo " 8. .88 "
echo " 8 ._. Y8. "
echo " d/ 8b. "
echo " .dP . Y8b. "
echo " d8: ::88b. "
echo " d8 Y88b "
echo " :8P :888 "
echo " 8a. : _a88P "
echo " ._/ Yaa_ : .| 88P| "
echo " \ YP | 8P \. "
echo " / \._____.d| .| "
echo " --..__)888888P ._.|"
echo " "
echo " COCUS WAS HERE (I hate JAVA) "

export mnt=/data/local/debian

export TERM=linux
export HOME=/root
export OLDPATH=$PATH

echo "mnt: $mnt"
echo "PATH: $PATH"
echo "TERM: $TERM"
echo "HOME: $HOME"

busybox mount -o bind /dev $mnt/dev
busybox mount -o bind /sys $mnt/sys
busybox mount -o bind /proc $mnt/proc
busybox mount -o bind /sdcard $mnt/sdcard
busybox mount -t devpts devpts $mnt/dev/pts

echo "Type EXIT to end session"
echo "Make sure you do a proper EXIT for a clean kill of Debian!"
echo " "

export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

busybox chroot $mnt /bin/bash

#After exit command is executed clear it all up

busybox umount -f /data/local/debian/dev/pts /data/local/debian/proc /data/local/debian/sys /data/local/debian/sdcard /data/local/debian/dev

export PATH=$OLDPATH
echo "Filesystems have unmounted"

Create another file, called vnc with the following contents:

export USER=root
cd /
rm -r -f tmp
mkdir tmp
cd /
vncserver -geometry 1280x720

(you could change the resolution of the X11 desktop there :D)

And at last, create the last file called xstartup. Take care here, if you have choosed LXDE, use the following:

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey

icewm &
lxsession

But if you've choosed IceWM, then use:

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey

icewm &
xterm

Here, we have to run commands, but in the phones shell (adb, ssh, terminal emulator).

Remember to mount the SD again (in the case that youre using USB SD Massive storage).

Well, we have to get root access in the shell, so you have to root your Defy first. If you have root acces, then run the following in your mobile:

mkdir /data/local/debian
cp /sdcard/bootdeb /data/local
busybox tar -xvf /sdcard/debian.tar.bz2 -C /data/local
rm /data/local/debian/root/.vnc/xstartup
cp /sdcard/xstartup /data/local/debian/root/.vnc/xstartup
cp /sdcard/vnc /data/local/debian/bin/vnc
ln -s /data/local/bootdeb /system/bin/bootdeb
chmod 0755 /data/local/bootdeb
chmod 0755 /data/local/debian/bin/vnc

If everything worked and no errors appeared, then you can run debian via your Terminal Emulator:

bootdeb

And you should get the debian shell, and then run:

vnc

to start vnc server on localhost. Take note of the localhost:x (where x is a number). That number is what you have to use to connect, I mean:

If the number is 1:

the port is 5901

If the number is 9:

the port is 5909

Thats all!

I will try to make a yaffs2 image to mount, but I really dont trust on the mount command, because it gives me a lot of errors, even with correct stuff.

Some Screenshots: