Howto create a Debian chroot on an Android phone

Howto create a Debian chroot on an Android phone (HTC Desire and Motorola Milestone)

This page will grow once I have everything running, but this is a starting point:…

  1. [HTC Desire, unbranded, European version]: Flashed (pre-rooted and with busybox included) firmware from…, taking file
  2. On a Debian squeeze (amd64, but with i386 it will be similar) box:
    1. sudo apt-get install debchroot qemu-user
    2. Download qemu-arm-static from (and its dependency) to get the build-arm-chroot script
    3. dd if=/dev/zero of=debian.img bs=1024 count=1950000
    4. sudo mkfs.ext2 -F debian.img
    5. sudo tune2fs -c0 debian.img
    6. mkdir debian
    7. sudo mount -o loop debian.img debian/
    8. sudo build-arm-chroot –verbose –arch=armel –foreign squeeze debian
    9. sudo mkdir debian/sdcard
    10. sudo mount -t proc none debian/proc/
    11. sudo mount -t sysfs sysfs debian/sys/
    12. sudo mount -t devpts devpts debian/dev/pts
    13. sudo chroot debian/ /bin/bash
    14. export HOME=/root
    15. export USER=root
    16. export LC_ALL=C
    17. echo ‘deb squeeze main contrib non-free’ > /etc/apt/sources.list
    18. aptitude update
    19. aptitude install –without-recommends lxde tightvncserver xfonts-base
    20. [optional, this is my personal package selection]: aptitude install psmisc nmap aircrack-ng ruby1.8 rubygems driftnet wireshark tshark subversion openssh-client openssh-server git
    21. aptitude clean
    22. echo localhost > /etc/hostname
    23. echo ’nameserver’ > /etc/resolv.conf
    24. to create VNC server startup files (setting connect password, I used password ‘debian’):
      [for HTC Desire]: vncserver -geometry 800x480
      [for Motorola Milestone]: vncserver -geometry 854x480
    25. sed -i ’s/\/etc\/X11\/Xsession/lxsession/’ /root/.vnc/xstartup
    26. echo > /usr/sbin/lxde <<EOF
      export USER=root
      vncserver -geometry 800x480
    27. chmod +x /usr/sbin/lxde
    28. echo > /usr/sbin/klxde <<EOF
      killall Xtightvnc && killall lxsession
    29. chmod +x /usr/sbin/klxde
    30. killall /usr/bin/qemu-arm-static
    31. exit
    32. sudo umount debian/proc
    33. sudo umount debian/dev/pts
    34. sudo umount debian/sys
    35. sudo umount debian/
  3. Copy this debian.img file to the SD card under a newly created folder “debian”.
  4. Copy the startdeb and stopdeb scripts to the same “debian” folder.
  5. Deactivate the hard disk mode so that the SD card is again available to Android running on the phone.
  6. On the mobile phone (e.g. via a “local” shell with ConnectBot or with “adb shell” from the connected Debian box):
    1. mkdir data/local/debian
    2. mkdir data/local/debian/mnt
    3. sh /sdcard/debian/startdeb
    4. lxde
    5. Use any local VNC client to connect to localhost, port 5091 using the password set previously
    6. klxde
    7. sh /sdcard/debian/stopdeb
René Mayrhofer
René Mayrhofer
Professor of Networks and Security & Director of Engineering at Android Platform Security; pacifist, privacy fan, recovering hypocrite; generally here to question and learn