notes-computer-android-g1 debian cyanogenMod quick

This page is about installing CyanogenMod? and/or Debian onto the Android Developer Phone (ADP 1/T-Mobile G1/HTC Dream). Other pages about Android and about this phone are linked to from g1.

Here is a list of commands, taken from below, that should install CyanogenMod? and Debian and set some things up. This page is a less verbose version of some of the instructions on the page g1_debian_cyanogenMod.

Most explanation, acknowledgments, choices, and instructions for making backups, have been omitted from the quick instructions, so if you are unsure, or encounter problems, or want to see the acknowledgements/hyperlinks, then you may want to refer to the more verbose instructions. If you want Debian without CyanogenMod?, refer to the verbose instructions.

These instructions may or may not work for other Android phones. I'm not sure but I'm guessing that they will only have to be modified a little bit for other Android phones which have a USB cable, for instance, maybe /dev/block/mmcblk0p2 and /mnt/dev/block/\/vold/179\:1 have to be replaced by something else. If your phone isn't yet rooted, I don't know much about how to/if you can root it, but see here: http://forum.xda-developers.com/showthread.php?t=442480 (I think links that page may be G1 specific; but presumably there are other such guides for other devices; search Google for the word "root" plus the name of your phone).

Most of these instructions were written down after the fact, so they may not be correct or complete. I'd recommend reading through a given section before you follow the instructions in that section, to make sure you understand, and to make sure I didn't make a mistake and tell you to do something obviously wrong. Please tell me if you discover any errors or omissions in this document, so that I can fix it (my email is at http://biomail.ucsd.edu/~bshanks/hosting/ucsd_email_small.jpg).

We assume your PC is running Debian GNU/Linux.

Install adb

Install the android SDK from http://developer.android.com/sdk/.

The "adb" command, which interfaces with the phone over the USB cable, is in the SDK, in the "tools" subdirectory -- you might want to put it in your PATH first.

If adb ever says the device is not found, then it may be because you are running the adb daemon on your PC without root permissions (here I'm talking about root permissions with respect to your PC's operating system; not root permissions with respect to your phone). As root, do "adb kill-server" and then "adb shell". If you get into the shell, just exit. The adb daemon will stay running on your PC, but now with root permissions.

Repartitioning your sdcard to have an ext partition

Attach the phone to the PC via the usb cable, and put the the phone into USB mass storage mode.

On the PC, as root:

aptitude install gparted
gparted

Resize the first partition (it is either FAT16 or FAT32) and create a new, second partition that is ext3. I gave my ext partition about 75% of total space.

To upgrade from ext3 to ext4 (this is optional), on your PC, as root, assuming that the phone is at /dev/sdc, and that your PC currently has ext4 support:

tune2fs -O sparse_super,filetype,dir_index,has_journal,extents,uninit_bg /dev/sdc2 

e2fsck -pDf /dev/sdc2

# you'll get some errors being fixed but that's apparently normal. i got some checksum invalids. 

Install Cyanogen Recovery Image and CyanogenMod

See http://forum.xda-developers.com/showthread.php?p=3915123 . Don't reboot yet.

Download the latest CyanogenMod? stable build onto your PC from http://forum.xda-developers.com/showthread.php?t=537204 . On your PC, do:

  adb push update-cm-*-signed.zip /sdcard/update.zip

Rebooted the phone while holding down the Home key and the Power key until it goes into Cyanogen's recovery. From the menu, select the option to flash /sdcard/update.zip. Reboot (I think it reboots automatically).

Install Debian

Put the phone into USB mass storage mode.

On the PC, assuming the phone is at /dev/sdc:

mkdir /media/android-linux
mount /dev/sdc2 /media/android-linux  
aptitude install debootstrap
debootstrap --verbose --arch armel --foreign lenny /media/android-linux http://ftp.us.debian.org/debian
umount /media/android-linux
adb root
adb shell
  su
  # now you're in the adb root shell:
  export mnt=/system/sd
  export PATH=/usr/bin:/usr/sbin:/bin:$PATH
  export TERM=linux
  export HOME=/root
  
  busybox chroot $mnt /debootstrap/debootstrap --second-stage
    # takes about 15 minutes
  
  echo 'deb http://ftp.us.debian.org/debian lenny main' >$mnt/etc/apt/sources.list 
  echo 'nameserver 4.2.2.2' >$mnt/etc/resolv.conf 
  
  busybox chroot $mnt /bin/bash
  # now you're in the chroot jail, i.e. in Debian!
  
    mount -t devpts devpts /dev/pts
    mount -t proc proc /proc
    mount -t sysfs sysfs /sys 
    rm -f /etc/mtab
    ln -s /proc/mounts /etc/mtab 
    
    mkdir -p /mnt/sdcard
    mkdir -p /mnt/system
    mkdir -p /mnt/data
    mkdir -p /mnt/dev

    # set the root password with:
    passwd root 

    # At this point I installed the following Debian packages, also:
    aptitude install less emacs openssh-server openssh-client mutt offlineimap unison python awesome screen tightvncserver qiv
    aptitude clean

Exit out of adb shell, and (still on your PC):

adb root
adb remount  # remember, you may have to run this command a few times before it works

cat /dev/tty > userinit.sh  # or you can use a text editor
#!/system/bin/sh

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

  # why burn out your sdcard with frequently updated log files, and
  # things that don't need to persist across boots
busybox mount -t tmpfs tmpfs /system/sd/var/log -o noatime,mode=1777 
busybox mount -t tmpfs tmpfs /system/sd/var/run -o noatime,mode=1777 
busybox mount -t tmpfs tmpfs /system/sd/var/spool -o noatime,mode=1777 
busybox mount -t tmpfs tmpfs /system/sd/var/tmp -o noatime,mode=1777 

busybox chroot /system/sd /etc/init.d/ssh start
busybox chroot /system/sd /etc/init.d/cron start
busybox chroot /system/sd /etc/init.d/exim4 start
^D
adb push userinit.sh /system/sd/userinit.sh
adb shell chmod 755 /system/sd/userinit.sh

cat /dev/tty > d
#!/system/bin/sh

  export PATH=/usr/bin:/usr/sbin:/bin:$PATH
  export TERM=linux
  export HOME=/root
  export SHELL=/bin/bash
  su -c 'busybox chroot /system/sd /bin/bash'
^D
adb root
adb remount # remember, you may have to run this command a few times before it works
adb push d /system/bin/d
adb shell chmod 755 /system/bin/d

NOTE: in CyanogenMod? 4.2.14 there's a bug so you have to copy a version of busybox that has chroot, say from http://www.mwyann.com/busybox.cyanogen.chroot , move it onto your android at /data/chroot (either d/l it onto the sdcard and then move it from the shell, or use adb push. You have to chmod 775 it, too), and then change the above script to use /data/chroot rather than just chroot.

To test everything so far, reboot the phone, and then on your PC, do:

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

If everything is working, you should be ssh'd into your phone (over the USB cable). For future use, You may want to put that last line in a shell script or alias on your PC.

And, to further test, on the phone, run the Terminal Emulator app. You get a prompt; enter "d"; a window will popup labeled "SU Request". You can select "Allow" or "Always Allow". Then you're back in the terminal, in Debian (you can tell you're in Debian because of the "localhost:/#" prompt).

Next, put the following at the end of your .bashrc on the phone:

  . ~/.bashrc-local

And then create a file at ~/.bashrc-local on the phone containing:

  mount -t vfat /mnt/dev/block//vold/179\:1 /mnt/sdcard/

To prevent man-db from making a cache, on the phone, in Debian, edit /etc/manpath.config, and uncomment the NOCACHE directive at the bottom of the file.

For passwordless logins between phone and PC, On your phone, in Debian, do the following, and enter an empty password when prompted:

  ssh-keygen -t dsa

Do the same thing on your PC. Append the contents of ~/.ssh/id_dsa.pub (from your PC) to the file ~/.ssh/authorized_keys (on your phone). Append the contents of ~/.ssh/id_dsa.pub (from your phone) to the file ~/.ssh/authorized_keys (on your PC).

To create a desktop shortcut to the Debian commandline on the phone, login to root@localhost using Connectbot. Press the Home key. Long click on the desktop. Click Shortcuts. Click Connectbot. Click root@localhost.

To setup VNC (as a replacement for X windows on the phone)

In Debian, on the phone:

  aptitude install tightvncserver

You probably also want a window manager. In Debian, on the phone:

  aptitude install awesome

On the phone, in Android, install the app AndroidVNC?.

On the phone, in Debian, do the following to setup tightvncserver:

export USER=root
vncserver -geometry 480x320
# (enter a password, but after that just enter "n" to decline to set a view only password)
vncserver -kill :1
nano ~root/.vnc/xstartup # or use your favorite text editor

and in the text editor, comment out the line for xsession: # #/etc/X11/xsession

and add two lines to the bottom: awesome& xterm

Save and quit it.

Put the following in a script file (I put mine at "/usr/local/bin/x"):

!#/bin/sh
export USER=root
vncserver -geometry 480x320

To start the VNC server, run "x", on the phone, in Debian.

On the Android side, open androidVNC app, address localhost, port 5901.

To attach to your PC's X-windows session from the phone

On your PC, do:

aptitude install x11vnc
x11vnc -storepasswd # and enter a password
x11vnc -ncache 10 -rfbauth ~/.vnc/passwd

then on the phone, use Android VNC Viewer to connect to your PC, port 5900

Other items of interest

In addition to or after following those instructions, you may also be interested in the content on the pages: g1_debian_cyanogenMod_misc and g1.