[Optimus V Android Development] bigsupersquid:
non-loop sd-ext chroot method (prebuilt!)

Standard disclaimer:

These scripts and chroot method may bork up your phone, trash your userdata, destroy system files, get you slapped by your mother, make your phone catch fire and/or explode, and etc., ad nauseum.

Use at your own risk.

MAKE A NANDROID BACKUP BEFORE DOING THIS!

You'll probably be just fine, but it's nice to have a backup in case something goes haywire.

Disclaimer aside, it's worked great for me since March, hasn't crashed for months, and I use it multiple times per day.

My main inspiration was Saurik and his Debian & Android together on G1.

I'm sorry that I can't point to all the many, many sources I read through over the couple weeks it took me to get this set up, I took little bits from here, there, and everywhere, but Saurik's work was the main core of this system.

Apologies if you see some tidbit of your work in this... let me know and I'll be happy to give you credit.

Dysfunctions:

Info:

On to the meat of the matter. I'm using an 8Gb SD card. I advise no smaller than 4Gb unless you just want to do command-line work in Debian and don't need a GUI.

First, these instructions require a Linux pc. On M$ Windoze? Use a Live CD or a virtual box, or you're on your own.

The first part of these instructions is to be completed on your pc. I'll let you know when to switch to the phone.

1) Mount your <empty> SD card on the pc. If it's not empty, back it up, because this will wipe it out. You'll need at least two partitions on it, three if you're using something like apps2sd (which I'm not using, and not really familiar with, so this tutorial is set up assuming you don't need to dodge an existing ext partition,) and another if you have a swap-enabled kernel and want to use it.

2) Use Gparted or a similar tool to partition the SD card. First partition FAT32 for Android, whatever size you feel you need. I'm using 1Gb.

Second partition is an ext2, ext3, or ext4 partition. Apps2SD style, you know what size and filesystem type you need here, I don't. For Debian on the 2nd partition, I advise 3Gb or more, ext2. ext4 corrupted my files, so I switched back to ext2. If you need an apps2sd partition, Debian will go on the 3rd partition, and you'll have to modify the two attached scripts accordingly.

If you're lucky enough to have a swap-enabled kernel, you can make a swap partition; it'll go last, whatever size is left. 256Mb-1Gb should be plenty depending on whether you use image processing or large compiling projects or some other memory hogging programs.

3) Mount the sd FAT32 and Debian ext partitions on the pc.

4) Download to your pc the base Debian Squeeze filesystem which I've debootstrapped, configured, and uploaded for you to save hours of hassle.

Also download to the same directory the two attached script files.

boot.txt

firstrun.txt

5) Open a ROOT shell. You need root privleges to untar the filesystem and retain its permissions. If you don't have a root shell, put sudo in front of the tar and cp-av commands.

6) cd to the directory you downloaded the squeeze_05_2011.tar.gz into. then type

tar -zxvf squeeze_05_2011.tar.gz
cp -av ./freshsqueeze/* /full/path/to/sdextDebianpartition
sync

and wait for it to finish.

7) type

cp ./boot.txt /full/path/to/sdFAT32partition/boot
cp ./firstrun.txt /full/path/to/sdFAT32partition/firstrun
sync

8) Now is the time to copy back the stuff you backed up from the SD card to the FAT32 partition, and any apps2sd style stuff if you have it. Then unmount your SD card and put it in the phone.

Now all remaining steps are done on your Optimus. You're finished with the desktop pc.

9) Open a terminal on your Optimus. I like SL4A, but Terminal Emulator works well too. Both are free.

10) Next step merges your existing Android system files into the Debian partition. This is neccesary because I haven't compiled a kernel and don't know of one for the Optimus with UFS enabled. So, Debian gets bind-mounted over the Android rootfs ( / directory) and having the Android system files accessible in the Debian filesystem is required to keep them playing nicely together, while protecting the original Android files from Debian at the same time.

sh /sdcard/firstrun

You won't need this script ever again unless you change ROMs and/or need to reinstall Debian. Changing ROMS without reinstalling a fresh copy of Debian may mess things up a bit since system files vary between ROMs and you'll still have the Android files from your previous ROM in your Debian filesystem.

This script and the 'boot' script are both listed at the bottom of this post if you want to read 'em.

11) Next, remount system r/w, copy the 'boot' file to /system/xbin and chmod 4755 /system/xbin/boot. If scripts are in /system/xbin and executable, you can run them with 'su -c'

su
mount -o remount,rw /system /system
cp /sdcard/boot /system/xbin
chmod 4755 /system/xbin/boot
mount -o remount,ro /system /system

OK, a basic Debian filesystem with no extra packages is now installed!

my Debian filesystem is on my 2nd sdcard partition. The comments in the 'boot' script should explain how to use another partition if you have apps2sd running or somesuch (I don't have many Android apps on my phone so don't need/use apps2sd function)

to use the script as-is, your linux flavor should be in the 2nd card partition. I use Debian, but any Debian-based distro should work, for example Ubuntu or DSL.

open a terminal and type

su -c boot

don't kill the terminal app... leave it running in the background.

when you're finished with linux, reopen the same terminal and type

exit

to cleanly dismount your linux. No reboot required!

Before you exit the first run of your new Debian system, you should download some packages. I advise tightvncserver, xfce4 (and xfce4-goodies if you want the extra glitz like a cpu monitor, bandwidth monitor, and such, without hunting the individual packages) and iceweasel so you can have a real rebranded firefox on your Optimus.

apt-get update
apt-get install tightvncserver xfce4 xfce4-goodies iceweasel

It'll take a while to download all that. Lots of data.

Once it's done downloading, configure tightvncserver.

vncserver

It'll ask you for a password. Choose one that's easy to remember. You'll need to enter it in the VNC viewer as well (next step)

IMPORTANT!

tightvncserver will ask you if you want a view-only password. Tell it no!

next:

vncserver -kill :1

to politely exit the vncserver. Otherwise you'll have to exit the chroot, reboot the phone, and run the 'boot' script again or it'll open server :2, :3, and so on each time you type vncserver. Each instance will eat more CPU, RAM, etc.

configure /root/.vnc/xstartup

echo '#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1
xfce4-session&' > /root/.vnc/xstartup

after that,

you should use

passwd

to set a root password, and

adduser

to get a non-root account on there.

exit

will close the chroot. You can close the terminal after that until you're finished setting up the VNCviewer and want to start your lovely GUI.

Now, set up the VNC viewer like in the OP. Make sure your password matches the one you gave tightvncserver!

I advise 24 bit color. It slows things down ever so slightly, but to me, it's well worth the increase in eye candy you get over 8 bit.

most of the tutorials on the VNC suggest modifying the /root/.bashrc file to start the vncserver automatically (like here on xda) but I don't like that myself. I use the shell a lot, and the vncserver eats system resources. So, I manually start and stop the vncserver from the command line.

vncserver

to start, it defaults to a 1024x768 which seems to make programs happier than the 480x320 phone native resolution.

vncserver -kill :1

to stop it politely. Otherwise a phone reboot is required to get rid of vncserver files (by clearing out everything in the / directory which isn't replaced by the boot.img ramdisk) which make it open desktop :2, :3, and so on each time you run the program.

One major advantage to the bind-mounting in the rootfs is that Thunar works as a root explorer, and has access to the entire Android filesystem (except for the bind-mounted Debian directories, which hide the Android directories underneath, including /system/etc which is symlinked to /etc by the boot.img ramdisk,) as well as the complete Debian filesystem.

Pretty much everything I've tried works, unless it wants speed from the display. The VNC just slows that down way to much to use for video or games or suchlike. I'm working on native window support for X, but I need more practice in C to get it done.

Iceweasel works great, if a little slow, a rebranded full firefox on an ARMv6 device that mozilla won't release an apk for its wussy mobile version on. Go figure. The biggest problem is finding plugins compiled for ARM, the 'get plugin' button send you to sites offering x386 versions of the plugins. Yuk.

Icedtea open source java works fine.

Gnash plays ads but not videos.

Gimp works well.

Qemu works!

Eclipse even installs and runs (very slowly)

get-flash-videos captures flash exceptionally well. combined with an Android video player for .mp4 files, you can download and watch flash from lots of places, just not streaming.

alsa audio works through Iceweasel. Played audio clips from yodajeff.com just to test it.

3g works great.

Wifi detects the connection with iwconfig, I haven't tried sending data through it but the way 3g plugs right in I bet that wifi works equally well.

Since wifi and 3g work out of the box, I bet bluetooth would too with some config, but it needs extra packages to see the functionality.

The network meter plugin for xfce works. The device is rmnet0.

The cpu meter plugin also works.

At one point I had the battery meter from xfce-power-manager working but my last install broke it somehow. Ah, well.

once it's all together

open a terminal

to start it up:

su -c boot

for a gui,

vncserver

to kill the GUI,

vncserver -kill :1

to exit the chroot,

exit

the first time you run the GUI, you might want to add my Xfce_large theme to make the scrollbars and menubars easier to hit on the touchscreen. See the earlier post.

hopefully this helps people out. I spent quite a while getting it just how I wanted it, many googlings and picking bits from here and there.

contents of the scripts follow.

firstrun

#make /sd-ext directory if it doesn't exist
if [ ! -d /sd-ext ]
then
mkdir /sd-ext
fi
# mount 2nd sdcard partition
# if your linux is on a different partition than 2, substitute that number for the 2 in .../mmcblk0p2 below
# first unmount it; if not already mounted, system will echo 'umount: can't forcibly umount /dev/block/mmcblk0p2: Invalid argument' but this isn't an error to worry about

umount -l /dev/block/mmcblk0p2
mount -o noatime,exec,suid /dev/block/mmcblk0p2 /sd-ext
#copy files from Android to Debian without overwriting anything
yes n | cp -aiv /etc/* /sd-ext/etc
yes n | cp -aiv /root/* /sd-ext/root
yes n | cp -aiv /sbin/* /sd-ext/sbin
yes n | cp -aiv /sys/* /sd-ext/sys

boot

# debian lives here

export mnt=/sd-ext

# remount / and /system rw

mount -o remount,rw / /
mount -o remount,rw /system /system

# make new subdirectories in / for binding

for x in \
bin boot home lib media \
opt selinux tmp usr var
do
mkdir /$x
done

#make $mnt directory if it doesn't exist
if [ ! -d $mnt ]
then
mkdir $mnt
fi

# mount 2nd sdcard partition
# if your linux is on a different partition than 2, substitute that number for the 2 in .../mmcblk0p2 below
# first unmount it; if not already mounted, system will echo 'umount: can't forcibly umount /dev/block/mmcblk0p2: Invalid argument' but this isn't an error to worry about

umount -l /dev/block/mmcblk0p2
mount -o noatime,exec,suid /dev/block/mmcblk0p2 $mnt

# cleanup last session's tmp files, including last VNC session

rm -r -f $mnt/tmp
mkdir $mnt/tmp

# bind mount debian directories to /

for x in \
bin boot home lib media \
opt selinux tmp usr var \
etc root sbin
do
mount --bind $mnt/$x /$x
done

# set some system variables

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc:/sys:$PATH
export TERM=linux
export USER=root
export HOME=/root

# mount proc,sys,devpts
umount -l devpts
mount -o remount -t proc proc /proc
mount -o remount -t sysfs sysfs /sys
mount -t devpts devpts /dev/pts

# softlink framebuffer (for future use,) and existing mounts
ln -s /dev/graphics/fb0 /dev/fb0
cat /proc/mounts > /etc/fstab
cat /proc/mounts > /etc/mtab

# 'boot' with chroot into debian bash shell at /

chroot / /bin/bash

# done now, clean up after exit to keep Android happy
# remove softlinks and replace backed up mtab and fstab
rm /dev/fb0

cd /

# unmount subdirectories
for x in \
bin boot home lib media \
opt selinux tmp usr var \
etc root sbin
do
umount -l /$x
done

# remove non-Android subdirectories
for x in \
bin boot home lib media \
opt selinux tmp usr var
do
rmdir /$x
done

# remount / and /system ro
mount -o remount,ro / /
mount -o remount,ro /system /system