[Transformer TF300T Android Development] Geometry:
initramfs for Linux with update-initramfs

I want to provide here some more detailed information on the initramfs and how to produce it for Linux with update-initramfs. Although much of this has been mentioned in previous posts it does not seem to be widely known that this method works well on the tf300t (and similar devices).

To boot a system on the tf300t one needs two indgredients: the kernel (usually in a compressed file called "zImage") and the initramfs (usually in a compressed file called "initrd.img"). Thesese are usually packed together in a single file, an "Android boot image" and placed into the boot partition. When the device is switched on, the boot image is read from this partition and kernel with initramfs are executed. (The recovery works exactly in the same way using the recovery partition instead.) If you use a second stage boot loader with kexec such as this one, you also need to provide these two ingredients (kernel+initramfs).

Under Android the initramfs is simply the root file system that Andoid will be running under. So the initramfs is really an integral part of the Android system (or ROM) togther with the content of /system and some other ingredients. Under Linux the initramfs is only a temporary root file system that is used to mount the actual root file system. It is discarded (from memory) once the system is properly running. In contrast to Android, a Linux distribution does not come with a prepared initramfs, because the initramfs you need generally depends on your setup. So how do you get the initramfs? This is what update-initramfs is for. This is part of the initramfs-tools, included in Linux distributions such as Ubuntu. It turns out this way of generating the initramfs not only works well on your desktop linux system, but also works perfectly on your tf300t. To generate the initramfs you need to call "update-initramfs -c -k <version>" from inside the Linux system, where <version> is the kernel version, for the tf300t this is "3.1.10" or "3.1.10-something". This requires the kernel configuration file to be present in "/boot" as "/boot/config-3.1.10(-something)". The initramfs created will also be placed in "/boot" and be named "/boot/initrd.img-3.1.10(-something)". (To execute "update-initramfs" from inside the Linux system you do not necessarily need to boot it, but can use chroot either from another Linux system that is already working or from Android.)

Before executing "update-initramfs" you need one more ingredient: A configuration file to specify where your Linux root files system is. This file goes into "/etc/initramfs-tools/conf.d/". It can have an arbitrary name. Lets call it "specify_rootfs". If your Linux system is at the root of a partition an example for the content of this file is:

ROOT="/dev/mmcblk1p1"
ROOTFSTYPE="ext4"
ROOTFLAGS="-o noatime,nodiratime,barrier=1,nomblk_io_submit,discard,data=writeback"

If your Linux system is contained in an image file an exmaple content for "specify_rootfs" would be this:

ROOT="/dev/mmcblk0p8"
ROOTFSTYPE="ext4"
ROOTFLAGS="-o noatime,nodiratime,barrier=1,nomblk_io_submit,discard,data=writeback"
LOOP="/media/linuxrootfs.img"
LOOPFSTYPE="ext4"

(Here the image file is located at "/data/media/linuxrootfs.img" under Android.)

In this way the information about the location of the Linux root file system is contained in the initramfs, and there is no need to put this information in the kernel command line.

The update-initramfs tool has one important shortcoming: It does not support the rootfs to be a subdirectory of a partition. Fortunately, this is easy to fix. I have written a small script that adds to update-initramfs the capability to support mount from a subdirectory. This script, called "enable-root-bindmount" has to be put into "/etc/initramfs-tools/scripts/local-bottom/". It is contained in the attached file "initramfs-bindmount.tar.gz". It does nothing, except if you define in "specify_rootfs" a variable "ROOTDIR" (you need the "export" command here), for example:

ROOT="/dev/mmcblk0p8"
ROOTFSTYPE="ext4"
ROOTFLAGS="-o noatime,nodiratime,barrier=1,nomblk_io_submit,discard,data=writeback"
export ROOTDIR="/media/linuxroot"

(Here the Linux root is at "/data/media/linuxroot/" under Android.)

In this way you can put for example this xubuntu rootfs as a subdirectory into "/data" rather than on an external sdcard.