[Nexus 4 Q&A, Help & Troubleshooting] Pickout:
Hi, this is a guide to install a Linux image on your rooted Android phone with the debootstrap + chroot method.

In this guide, we'll install a Debian image, but the steps are practically the same, with a few tweaks.

If you need help to install a Linux image, feel free to ask on this thread.

For this guide, all credit goes to them:

http://linux-expert.net/?Trucs_et_astuces___Android___Tutoriel_%3A_Chroot_Debian (in french)

http://xdaforums.com/showthread.php?p=45457799

http://xdaforums.com/showthread.php?t=2312013

http://xdaforums.com/showthread.php?t=631389

http://xdaforums.com/showthread.php?t=1418546

http://xdaforums.com/showpost.php?p=5671794&postcount=124

VNC

________________

I. On your PC

So first, you have to create the .img file that will contain the OS.

In a GNU/Linux environment (PC) and with the root permissions, type these commands:

# mkdir debian
# dd if=/dev/zero of=wheezy-armhf.img bs=1M count=0 seek=2048
[COLOR="Red"](NOTE: "of=" will be the name of our .img file and "seek=" the size of the file (MB). Here, we create a file named "wheezy-armhf.img" of 2 GB)[/COLOR]
# mkfs.ext4 -F wheezy-armhf.img
# mount -o loop wheezy-armhf.img /debian

Then we have to fill up the filesystem.

# debootstrap --foreign --arch=armhf wheezy debian/
# umount debian

Finally, move it to your SD Card. In my case, I moved it on /data/local/

II. On your phone

On your phone, in a terminal emulator and with the root permissions, type the following commands:

# mount -o rw,remount rootfs /
# export LINUXROOT=/linux
(NOTE: here we'll install Debian on the root of the internal memory, in "/", but we can also install Debian on the SD Card or in /data/loca/linux by changing the path after "LINUXROOT=")
# mkdir $LINUXROOT
# busybox mknod /dev/block/loop100 b 7 100
# losetup /dev/block/loop100 /sdcard/wheezy-armhf.img
# mount -t ext4 /dev/block/loop100 $LINUXROOT
# chroot $LINUXROOT /bin/sh
# export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# /debootstrap/debootstrap --second-stage

The debootstrap's second part should start. Grab a cup of coffee while it's working!

When it's finish, leave the chroot by typing

# exit
# su

Let's mount the filesystem. We're close!

# mount -t proc none /proc
# mount -t sysfs none /sys
# mount -o bind /dev /dev
# mount -t devpts none /dev/pts

Now, we have to set the environment variable. Ensure that you have set the correct path of LINUXROOT in case you've chosen another path than /linux.

# export LINUXROOT=/linux

# export TMPDIR=/tmp
# export USER=root
# export HOME=/root
# export SHELL=/bin/bash
# export TERM=linux
# export LC_ALL=C
# export LANGUAGE=C
# export LANG=C

And finally, chroot.

# chroot $LINUXROOT /bin/bash
su

Welcome on Debian!

III. DNS and Mirrors

Set a DNS. We'll set the free Google DNS but you can set yours if you want.

echo -e "domain local\nsearch local\n" >> /etc/resolv.conf
echo -e "# DNS Google\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n" >> /etc/resolv.conf

You can add mirrors to your sources.list if you want. I'm french so I added french mirrors:

# echo -e "## Debian Wheezy sources.list\n\n" > /etc/apt/sources.list
# echo -e "## Debian.org FR mirror\ndeb http://ftp.fr.debian.org/debian/ wheezy main contrib non-free\ndeb-src http://ftp.fr.debian.org/debian/ wheezy main contrib non-free\n\n" >> /etc/apt/sources.list
# echo -e "## Debian security updates\ndeb http://security.debian.org/ wheezy/updates main contrib non-free\ndeb-src http://security.debian.org/ wheezy/updates main contrib non-free\n >> /etc/apt/sources.list

IV. VNC

To access your Debian in a graphical environment from your PC or your phone, you have to set up a VNC Server and install a Desktop Environment. Let's install VNC and LXDE.

We'll follow the steps described on the LXDE wiki:

su
# apt-get update
# apt-get install lxde
# apt-get install tightvncserver

Set up the VNC server by typing the following command, which will ask you to set two passwords (let the second password if you want):

# vncserver

Kill the session:

# vncserver -kill :1

Go to /root/.vnc/ and edit the xstartup file: comment out #/etc/X11/xsession and add these two lines:

To start a VNC session, type "vncserver -geometry x". For the Nexus 4, we would type "vncserver -geometry 1184x768"

To access your Desktop Environment from your phone, download android-vnc-viewer and launch it.

In the password field, type your password. In the address field, type "127.0.0.1", in port type "5901" and select 24-bit color (4bpp).

V. Script

I've made three scripts to mount, launch and unmount Debian. Whenever you reboot your phone, you'll have to mount Debian, set the environment variables and chroot.

VI. Credit

All credit goes to them:

http://linux-expert.net/?Trucs_et_astuces___Android___Tutoriel_%3A_Chroot_Debian (in french)

http://xdaforums.com/showthread.php?t=2312013

http://xdaforums.com/showthread.php?t=631389

http://xdaforums.com/showthread.php?t=1418546

http://xdaforums.com/showpost.php?p=5671794&postcount=124

VNC

Sorry for my bad english, I hope this will help :)