tips-computer-android-g1 debian cyanogenMod misc

This page contains misc notes about running Debian on an Android phone (specifically, I have an Android Developer Phone (ADP 1/T-Mobile G1/HTC Dream). Other pages about Android and about this phone are linked to from g1.

Misc notes

  adb forward tcp:1622 tcp:22 && ssh -p 1622 root@localhost

Using your PC's keyboard to type stuff into Android

Once you have Debian running, you can setup things so that when you're logged into Debian, you can run a program so that when you type on your PC, it'll type whatever you type on your phone as if you had typed it using the phone's builtin keyboard.

Copy and paste code from

http://github.com/bradfitz/android-misc/blob/master/type.pl

into a file (I just called it type.pl) on your phone, and chmod a+x that file.

On my particular device (ADP 1 running CyanogenMod? v3.6.8.1, which is based on Android 1.5r3), the /dev/input directory didn't exist inside of the Debian directory hierarchy, and also the right device turned out to be event3 (13,67) instead of event2 (13, 66), so I had to change the relevant line in that script from

  my $keyboard = "/dev/input/event2";

to

  my $keyboard = "/mnt/dev/input/event3";

and changed

  system("mknod", $filename, "c", 13, 66) and die "mknod failed.";

to

  system("mknod", $filename, "c", 13, 67) and die "mknod failed.";

Thanks to http://brad.livejournal.com/2400054.html

Some unison config notes

I have it setup so that I have a text file which is automatically synchronized between my phone and my computer, so that I can edit the file at either place, and the changes propagate (provided there is no edit conflicts :) ). This is my favorite use case for having a smart phone. I do this by running unison as a cron job in Debian.

unison is a file synchronization program. Mine is configured via the file /root/.unison/default.prf. I won't divulge the complete contents of this file, but part of it is:

# Roots of the synchronization
root = /root
root = ssh://USERNAME@MY_HOME_PCs_DNS//PATH_TO_MY_HOME_DIRECTORY

batch = true
log = false

# Paths to synchronize 
path = notes
....

I added unison to cron:

cat /dev/tty > /etc/cron.d/unison
# /etc/cron.d/logcheck: crontab entries for the logcheck package

PATH=/usr/local/bin:/bin:/usr/bin
MAILTO=root

11 * * * *       root   unison

This will run unison once an hour (if the phone is turned on -- I think it has to be awake, too) at the 11th minute.

Note that in my unison control file (/root/.unison/default.prf), I have the options (amongst others)

batch = true
log = false

to tell unison to, by default, run without asking questions (and skip conflicts), and to not log anything (since I run it frequently, I don't want it burning up my sdcard).

If you ever want to run something in just Debian

You may not ever want to do this, in case you can just skip this section, but sometimes it's nice to run something on Debian after booting into the recovery image, because then there isn't all that Android stuff and Android apps hogging memory and CPU time. Here's how to get Debian going, including wifi and the ssh server (so you can ssh in) after booting into cyanogen's recovery image (version 1.4):

adb shell

busybox mount -t auto /dev/block/mmcblk0p2 /system/sd -o rw,noatime
busybox mount -t devpts devpts /system/sd/dev/pts
busybox mount -t proc proc /system/sd/proc
busybox mount -t sysfs sysfs /system/sd/sys 
busybox mount --bind /sdcard /system/sd/mnt/sdcard 
  # for some reason /sdcard isn't working when i mount it
  # at boot, although i can do it later. i wonder why?
  # mb it isn't mounted yet at boot?
busybox mount --bind /system /system/sd/mnt/system
busybox mount --bind /data /system/sd/mnt/data
busybox mount --bind /dev /system/sd/mnt/dev
#  busybox mount --bind / /system/sd/mnt/root # doesn't work
busybox mount -t tmpfs tmpfs /system/sd/tmp -o noatime,mode=1777

  mount -t yaffs2 /dev/block/mtdblock3 /system -o noatime
  mount -t squashfs /system/modules/modules.sqf /system/modules -o ro
  mount -t squashfs /system/xbin/xbin.sqf /system/xbin -o ro 
  
  # We chown/chmod /data again so because mount is run as root + defaults
  mount -t yaffs2 /dev/block/mtdblock5 /data -o nodev
  chmod 0771 /data



  export PATH=/usr/bin:/usr/sbin:/bin:$PATH
  export TERM=linux
  export HOME=/root
  export SHELL=/bin/bash


# cp /system/etc/wifi/wpa_supplicant.conf /data/misc/wifi/wpa_supplicant.conf
insmod /system/lib/modules/wlan.ko
wlan_loader -f /system/etc/wifi/Fw1251r1c.bin -e /proc/calibration -i /system/etc/wifi/tiwlan.ini

cd /data/local/tmp
wpa_supplicant -f -Dtiwlan0 -itiwlan0 -c/data/misc/wifi/wpa_supplicant.conf &
ifconfig tiwlan0 192.168.1.66 netmask 255.255.255.0
ifconfig tiwlan0 up

busybox chroot /system/sd /bin/bash
route add default gw 192.168.1.1
/etc/init.d/ssh start

thx http://ubuntuforums.org/showthread.php?p=7652024

How to get into Debian manually

You probably can skip reading this section, because in the following two sections I'll show you how to make the phone do this stuff automatically on boot. But just in case you're curious:

Everytime you want to use Debian, you do:

su
busybox mount -t auto /dev/block/mmcblk0p2 /system/sd -o rw,noatime
export mnt=/system/sd
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
busybox mount -t devpts devpts $mnt/dev/pts
busybox mount -t proc proc $mnt/proc
busybox mount -t sysfs sysfs $mnt/sys 

# allows you to access the other
# parts of the Android filesystem from within Debian
busybox mount --bind /sdcard $mnt/mnt/sdcard
busybox mount --bind /system $mnt/mnt/system
busybox mount --bind /data $mnt/mnt/data
busybox mount --bind /dev /system/sd/mnt/dev

busybox chroot $mnt /bin/bash

(btw, "mount --bind" doesn't seem to work for rootfs; even after creating a mountpoint, i get "mount: mounting rootfs on /system/sd/mnt/root failed: Invalid argument")

On the standard Android setup, this will only work from within adb! "su" in Terminal Emulator will fail. This is a security precaution (to prevent rogue apps from gaining superuser). So the above method won't be very helpful alone. But you can either add a real "su" to the phone, and/or you can follow the instructions in one of the next two sections to modify your system image to do this stuff upon boot.

You may also want to cleanly unmount when you're done, or before phone shutdown:

export mnt=/system/sd
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root

busybox fuser -k $mnt
umount $mnt/dev/pts
umount $mnt/mnt/sdcard
umount $mnt/mnt/system
umount $mnt/mnt/data
umount $mnt/dev/pts
umount $mnt/sys 
umount $mnt

Unmounting isn't necessary if you use CyanogenMod?, because it does something similar automatically (currently, on CyanogenMod? builds ("ROMs"), every filesystem is remounted ro just before shutdown by /system/bin/shutdown). Unmounting before each phone shutdown or reboot is recommended otherwise, ESPECIALLY IF YOU ARE USING EXT2! This is the biggest reason for using CyanogenMod? with Debian.