#!/sbin/busybox sh
# initramfs pre-boot init script
+# Initial version copied from http://whiteboard.ping.se/Android/Debian
# Mount the /proc and /sys filesystems
/sbin/busybox mount -t proc none /proc
# Populate /dev
/sbin/busybox mdev -s
-# Mount the root filesystem, second partition on micro SDcard
-/sbin/busybox mount -t ext4 -o noatime,nodiratime,errors=panic /dev/mmcblk1p2 /mnt/root
+# Mount the Debian root filesystem, third partition on micro SDcard
+# We don't care if this fails, we'll handle that later
+/sbin/busybox mount -t ext4 -o noatime,nodiratime,errors=panic /dev/mmcblk1p3 /debian/
+
+# This directory exists in both the initramfs and the Debian fs
+/sbin/busybox mount -t ramfs ramfs /debian/android
+
+# Copy from the initramfs into the new android root
+cd /debian/android
+/sbin/busybox gunzip -c < /initrd.img | /sbin/busybox cpio -i
+
+exec >>/debian/android/log/boot-wrapper.log 2>&1
+
+/sbin/busybox echo "`/sbin/busybox date` Booting"
+
+/sbin/busybox [ -x /debian/etc/stage2init.sh ] && /sbin/busybox chroot /debian/ /debian/etc/stage2init.sh
+
+/sbin/busybox echo "`/sbin/busybox date` Cleaning up boot mounts"
# Clean up
/sbin/busybox umount /proc
/sbin/busybox umount /sys
/sbin/busybox umount /dev
-# Transfer root to SDcard
-exec /sbin/busybox switch_root /mnt/root /etc/init
+/sbin/busybox echo "`/sbin/busybox date` Starting Android's init"
+
+# Chroot into /debian/android/ and start Android's init
+exec /sbin/busybox chroot /debian/android/ /init "$*"