[G1 Android Development] Alphacrux:
If there is enough demand I'll do a more in depth how-to but here's basically how it works...

Here are the commands for creating an ext2 image taken from Saurik's how-to for putting debian on the G1:

dd if=/dev/zero of=debian.img seek=749999999 bs=1 count=1
mke2fs -F ext2.img

*The above two commands are meant to be run off a normal linux desktop distro, not on the g1

The dd command tells linux to make a file called ext2.img, specifically it takes a starting point for a file, jumps 749999999 bytes forward (obviously linux makes sure this is unallocated space) and writes one zero making a very quick 750MB file. The 749999999 can be substituted for however big you want your image to be, and the image can be named whatever you want to name it. Also many people refer to the dd command as the data destroyer so be very careful when you type out this command.

The mke2fs command simply takes the empty file and formats it as ext2.

[edit]

If you're just moving apps over to your sd card using the image method you can go ahead and skip down to "Continue Here". If you want Debian as well you will need to do a couple extra commands after you create your image and then follow the rest of Saurik's instructions:

mkdir ext2dir
mount -o loop ext2.img ext2dir
cd ext2dir
mkdir debian
debootstrap --verbose --arch armel --foreign lenny debian http://ftp.de.debian.org/debian
cd ..
umount ext2dir

This is a direct copy of saurik's directions, only you call the directory "ext2dir" instead of "debian" and then create the folder "debian" inside the image after you've mounted it. This is because you will also be putting your app and app-private directories in here, so you give Debian its own folder so it will share the image.

There is actually a lot more to do to get Debian running so for right now I will just refer you again to saurik's page. If there is more demand I can create a script that will automate most of this for you guys and perhaps an image so you don't have to make one yourselves.

[/edit]

Continue Here:

Next you put your image file on the sd card and create an empty directory to mount it on, again mine is called ext2dir.

Then you modify the /system/init.rc file on your phone to mount the image to an empty directory on bootup. Here is my implementation:

on system
mount cramfs loop@/system/modules/modules.cramfs /system/modules ro
mount cramfs loop@/system/xbin/xbin.cramfs /system/xbin ro
insmod /system/modules/2.6.25-01843-gfea26b0/kernel/fs/ext2/ext2.ko
mknod /dev/block/mmcblk0 b 179 0 1000
mknod /dev/block/mmcblk0p1 b 179 1 1000
mount vfat /dev/block/mmcblk0p1 /sdcard
mount ext2 loop@/sdcard/ext2.img /sdcard/ext2dir noatime

Init.rc uses its own special formats for typical Linux commands so you old hats might notice how the commands are much different than normal. You can read more about how the G1 initialization process works here. Basically the first two cramfs lines are orginally already included in the init.rc file so we just keep them there. Next we load the ext2.ko module so our G1 knows how to deal with the ext2 filesystem. Next I found that in order to mount the image onto the empty directory, the sdcard would need to be mounted first or Android wouldn't be able to see the files. Normally this happens later in the initialization process but I go ahead and give the commands here. I've tested it out and I have not seen any negative consequences to mounting early in /system/init.rc. The first mknod creates the sdcard device, the second mknod creates the device for the first partition on the sdcard (they must be created in this order.) Then I mount the sdcard 1st partition (since I only have fat32 their is only 1 8 GB partition on my sdcard) device on the /sdcard directory. Then we mount the ext2.img file on the ext2dir directory using andriod's loopback device with the noatime option (saurik goes into more detail on how loopback devices work in his how-to if any of you are curious.) Normally to mount a file using the loopback device with the noatime option the command is:

mount -o loop,noatime ext2dir.img debian

however its different here cause its in the init.rc file

Next you copy the /data/app and /data/app-private files over to your new /sdcard/ext2dir directory exactly like you do in dwang's how-to only using /sdcard/ext2dir as your new directory instead of /sd. Also make sure you point the symlinks to the new directory as well.

Using this implementation there is no need to modify /system/etc/mountd.conf as there is still only 1 partition on the sd card, you will need to have the original mount.conf or their might be errors...

Thats pretty much all there is to it! Happy Hacking :)