AnX11 Phone Project

method #2

step-by-step installation

This page outlines (in step-by-step fashion) a debootstrap installation method that will build a Debian system on your Android device. These are the same steps that the d4cm installer takes, so this page also documents the behavior of the installer. (Greater detail can be found in Appendix D of the Debian Installation Guide).

Specifically, this page explains how to install a Debian base system onto a disk image or SD card partition. After transferring that installation to your phone, you can run deb stage2 to complete the installation and add Android group IDs to the Debian system.

first-stage debootstrap

Step 1:   Install the necessary packages on your Debian desktop computer:

c$ su
c# apt-get install binutils debootstrap
c# exit


Step 2:   Create a directory for the debootstrap installation:

c$ mkdir -p /home/eryk/debian-chroot/wheezy/
c$ cd /home/eryk/debian-chroot/


Step 3:   You can install Debian to an SD card partition or to a disk image. To cover both cases, we'll use the variable $IMG to hold the location of the disk.

To create a 512MB disk image:

c$ IMG="debootstrap_wheezy.img"
c$ dd if=/dev/zero of=${IMG} bs=1048576 count=512

To use a disk partition:

c$ IMG="/dev/sdb2"


Step 4:   Format the disk:

c$ /sbin/mke2fs -i 12288 -t ext2 ${IMG}
c$ /sbin/tune2fs -c 0 -i 0 ${IMG}


Step 5:   Define a directory to (temporarily) hold the installation:

c$ su
c# MNT="/home/eryk/debian-chroot/debian"

If you're installing to a disk image, mount it with the "loop" option:

c# mount -o loop,noatime ${IMG} ${MNT}

If you're installing to an SD card partition, mount it:

c# mount -o noatime ${IMG} ${MNT}


Step 6:   Run the first stage of the "debootstrap" installation:

c# MNT=""
c# /usr/sbin/debootstrap --no-check-gpg --verbose --arch armel --include resolvconf --foreign wheezy ${MNT} http://ftp.us.debian.org/debian


Step 7:   While the disk is still mounted, add a few directories to the installation:

c# mkdir -p ${MNT}/proc
c# mkdir -p ${MNT}/sys
c# mkdir -p ${MNT}/dev/pts
c# mkdir -p ${MNT}/dev/block/vold
c# ln -s /proc/mounts ${MNT}/etc/mtab


Step 8:   Unmount the disk

c# umount /home/eryk/debian-chroot/debian
c# exit

If you installed Debian on a disk image, then push the image to Android:

c$ adb push ${IMG} /sdcard/.

If you installed Debian on an SD card, then insert it into your phone.

second-stage debootstrap

Assuming that you have already unpacked d4cm 1.7 on your phone, your last two steps are to configure the d4cm scripts and to run the second-stage of the installer.

Step 9:   Edit the d4cmdeb script, then push it and a deb script back to Android.

First, create the following deb script:

#!/system/bin/sh
exec /system/xbin/su -c "/data/local/deb/d4cmdeb $1"

Next, pull in the d4cmdeb script for editing:

c$ adb pull /data/local/deb/d4cmdeb

Your edits to the d4cmdeb script may be few. The only absolutely necessary task is to point the script to the location of your Debian installation. In the example below, I comment out the script's original ${IMG} variable and replace it with the disk partition where I installed Debian:

## IMG=${EXTERNAL_STORAGE:-/sdcard}/debian.img
IMG=/dev/block/vold/179:35

Now push the d4cmdeb script and the deb script back to Android:

c$ adb push deb /data/local/deb/deb
c$ adb push d4cmdeb /data/local/deb/d4cmdeb

Mark them executable:

c$ adb shell "chmod 755 /data/local/deb/deb"
c$ adb shell "chmod 755 /data/local/deb/d4cmdeb"

And create a symbolic link to the deb script in the path of the Android shell:

c$ adb shell
a$ su
a# mount -o rw,remount /system
a# ln -s /data/local/deb/deb /system/bin/deb
a# mount -o ro,remount /system
a# exit


Step 10:   Run deb stage2:

a$ deb stage2

And enjoy your new Debian system!

about deb stage2

As explained on the previous page, deb stage2 completes the bootstrapping process and then calls Sven-Ola's andromize script, which adds Android group IDs to the Debian system. Of particular importance are groups that allow access to the SD card (like media_rw (GID: 1023) and sdcard_r (GID: 1028)) and groups that allow access to the network (like inet (GID: 3003)).

Following the steps above should provide you with a working Debian installation on your Android device. The steps below are included for documentation purposes. They summarize the behavior of deb stage2 by explaining how you could alternatively complete the installation without running deb stage2.

Step A:   Mount the disk on your Android device:

c$ adb shell
a$ su
a# mount -t ext2 -o loop,noatime ${IMG} /data/local/mnt
a# mount -t proc -o bind /proc /data/local/mnt/proc
a# mount -o bind /sys /data/local/mnt/sys
a# mount -o bind /dev/pts /data/local/mnt/dev/pts
a# mount -o bind /dev/block/vold /data/local/mnt/dev/block/vold


Step B:   Run the second stage of the installer:

a# PATH=/usr/sbin:/usr/bin:/sbin:/bin /system/xbin/chroot /data/local/mnt /debootstrap/debootstrap --second-stage


Step C:   Enjoy your new Debian system!

Login to Debian as root user:

a# PATH=/usr/sbin:/usr/bin:/sbin:/bin /system/xbin/chroot /data/local/mnt /bin/bash --login

Start and stop SSH:

a# PATH=/usr/sbin:/usr/bin:/sbin:/bin /system/xbin/chroot /data/local/mnt service ssh start
a# PATH=/usr/sbin:/usr/bin:/sbin:/bin /system/xbin/chroot /data/local/mnt service ssh stop


Step D:   Unmount Debian:

a# umount /data/local/mnt/dev/block/vold
a# umount /data/local/mnt/dev/pts
a# umount /data/local/mnt/sys
a# umount /data/local/mnt/proc
a# umount /data/local/mnt


Eryk Wdowiak
last updated: 18 October 2016