[experimental] Debian running like a charm on Defy!!!

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
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:
Code:
apt-get install qemu-user-static debootstrap
But if you're on Ubuntu, use this:
Code:
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)
Code:
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)
Code:
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).
Code:
mkdir debian/sdcard
Second thing, is to run the chroot and configure some things:
Code:
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:
Code:
/debootstrap/debootstrap --second-stage
adduser
Then provide a username and password.

Now run the following, to fix some configs:
Code:
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:
Code:
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:
Code:
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:
Code:
apt-get install lxde tightvncserver
But if you prefer IceWM instead LXDE, then:
Code:
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
Code:
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.
Code:
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.

Code:
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:
Code:
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:
Code:
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:
Code:
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey

icewm &
lxsession
But if you've choosed IceWM, then use:
Code:
#!/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:
Code:
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:
Code:
bootdeb
And you should get the debian shell, and then run:
Code:
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:

 
Last edited:
  • Like
Reactions: xdaid

walter79

Recognized Developer
Dec 18, 2006
4,100
4,618
263
Did you tried Debian 6.0?

Lenny = 5.0

Squeeze = 6.0

Code:
build-arm-chroot --verbose --arch=armel --foreign squeeze debian http://ftp.us.debian.org/debian
 

xdaid

Inactive Recognized Developer
Jul 12, 2009
514
648
0
I was wondering what exactly is the final result here, maybe a REMOTE lxde (GUI for debian) for my defy running on PC or something like that..
well i got my answer here:

http://www.androidfanatic.com/community-forums.html?func=view&catid=9&id=1615

So, if you have the same doubt, NO, it's not a remote desktop, it is debian + lxde (or IceWm) running directly on your defy.
The connection through vnc is just a workaround to make it working.

Thanks Cocus for your nice step-by-step guide.
 

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
Hi. Thanks for the feedback. I've reuploaded the images to imageshack, now you can see them without any 403.


bash: build-arm-chroot: command not found

which package.deb include build-arm-chroot?
Hi john, are you running the command in Debian or Ubutnu?

Did you run the command of debootstrap?
Code:
# apt-get install debootstrap
Did you tried Debian 6.0?

Lenny = 5.0

Squeeze = 6.0

Code:
build-arm-chroot --verbose --arch=armel --foreign squeeze debian http://ftp.us.debian.org/debian
Nope, I haven't tryied it. In fact, I was trying to get it working. Now I would try to do some interesting things.


For the dumb ppl here, the second screenshot is of your phone running an OS?

Sent from my MB525 using XDA App
In fact, the kernel is the one that the phone booted. The only thing that I've done, is changing the root (/) path to another one, that is like swap the filesystem to another one. The other path, contains the debian root, so you will have a debian root, instead the default of your phone. With that, we can use the debian (armel) features, like aptitude (apt-get install) and such.


If anyone knowns how to mount images on loop or any thing like, please feel free to comment. I'm running out of space in my device (almost 10mb left). So, the image mount could be the best option, but I can't figure how to do that in the stock kernel.
 
Last edited:

xdaid

Inactive Recognized Developer
Jul 12, 2009
514
648
0
Hi. Thanks for the feedback....
Hi cocus,
is there any way to get it working without the vnc part? I mean, it would be great if we could load debian and lxde from our defy regardless of the vnc connection.
If i'm not wrong, to boot propely it needs to load some drivers from PC, that's why we need the vnc. Is it correct?
 

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
Hi cocus,
is there any way to get it working without the vnc part? I mean, it would be great if we could load debian and lxde from our defy regardless of the vnc connection.
If i'm not wrong, to boot propely it needs to load some drivers from PC, that's why we need the vnc. Is it correct?
The fact is, debian doesn't have access to the display. I really don't know why, because I'm kinda dumb on linux stuff.

If somebody knowns how to add graphical support (display), and/or mouse (touchscreen), it would be great. And, we could just close the dalvik and run the debian (a lot of ram would be free to use).

Now im trying to use the camera, audio and mic. They appears in /dev/, so the drivers are working fine, but I don't know with application to use.
 

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
If you can install Debian on a Defy, why isn't it possible to install Gingerbread ? :/
Not exactly installed. Let me clarify it.
The linux file system consists of directories and start at the root directory. (/). Imagine the Windows95 directory, and change the boot to the path of Windows98. Technically what boots (in this case the kernel) is the same, but what changes is the directory. So you'll have a working Debian, as if it were actually installed, but it really is not.

Debian can not access the screen (at least I do not know how to set it up) so you have to use VNC server locally to access the X11 (display manager).

Take into account that anything here is emulated at all, is running all native.

I really don't known nothing about Gingerbread.
 

johnw.xda

Senior Member
Jan 8, 2011
116
5
0
Hi john, are you running the command in Debian or Ubutnu?

Did you run the command of debootstrap?
Code:
# apt-get install debootstrap
hi cocus, yes i did install debootstrap, on my debian/and64.
dpkg -L debootstrap can not found build-arm-chroot too

which debian are you using? mine is unstable + testing.

thank you.
 

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
hi cocus, yes i did install debootstrap, on my debian/and64.
dpkg -L debootstrap can not found build-arm-chroot too

which debian are you using? mine is unstable + testing.

thank you.
Hi, I'm using Lenny on x86. (VM is VMWare Workstation).

You could download the netinstall iso, and install on a new VM.

It might be a problem with your AMD64. Thus I don't really know. Try installing x86 on a VM.
 

johnw.xda

Senior Member
Jan 8, 2011
116
5
0
Hi, I'm using Lenny on x86. (VM is VMWare Workstation).

You could download the netinstall iso, and install on a new VM.

It might be a problem with your AMD64. Thus I don't really know. Try installing x86 on a VM.
can you show me the output?
shell$ dpkg -S build-arm-chroot
also
shell$ which build-arm-chroot
and
shell$ dpkg -L debootstrap | grep build-arm-chroot
thank you.
 

cocus

Senior Member
Feb 2, 2010
88
5
0
Rosario, Santa Fe, AR
can you show me the output?
shell$ dpkg -S build-arm-chroot
also
shell$ which build-arm-chroot
and
shell$ dpkg -L debootstrap | grep build-arm-chroot
thank you.
Hi. I've done all of that, but without any outputs, and a lot of errors. I've researched, and I've made a mistake in my info.

Replace build-arm-chroot with debootstrap. Its the same.


(now edited on the main post)

Sorry for the inconvenience.
 

johnw.xda

Senior Member
Jan 8, 2011
116
5
0
Hi. I've done all of that, but without any outputs, and a lot of errors. I've researched, and I've made a mistake in my info.

Replace build-arm-chroot with debootstrap. Its the same.


(now edited on the main post)

Sorry for the inconvenience.
ok. i will retry it, when i back to home.
thank you.

can you run vim on your defy?
i really miss it, when i want to edit plain text file.