Ubuntu Internal emmc

=Warning= This page is _not_ intended for every day users!

The instructions here purposefully erase all trace of the default O2/openframe firmware and will result in a system considered useful to a small percentage of users.

NO GUI whatsoever will even be running at the end of this process. This procedure is aimed at making a starting point for people who want their joggler to do a specific task - and who know how to implement what is required to do so.

=Introduction= This page aims to document the process of creating a minimal Ubuntu installation on the internal emmc - replacing the original O2/openframe firmware.

It will run a read-only root fs with a volatile rw-system overlaid allowing most apps to function normally whilst preventing ware on the flash memory and allowing the system to be powered off at any time without risk of filesystem corruption. This is ideal for systems which will just run a simple GUI that either does't need to save any data - or saves all their data remotely.

I had my own reasons for doing this - however others have expressed interest here so I will attempt to re-create the procedure from memory here. Please amend mistakes or ask questions where required

=Requirements=
 * Joggler
 * Bootable Debian/Ubuntu usb stick.
 * Another PC with Ubuntu (in order to build kernel without taking all year)

=Procedure outline= The steps we need to perform - details will follow. This is mostly me trying to remember what I did and in what order at present. I will try to flesh out the details later.

On joggler

 * Boot from the Ubuntu usb device
 * Delete all but the first partitions from the internal emmc,
 * Create a new 2nd partition filling the free space,
 * format as ext2
 * mount it
 * debootstrap oneiric to it
 * chroot into it
 * Set password, install misc required apps

On a fast PC

 * Download vanilla kernel 3.2.4, apply buZz's patches and config file
 * Add aufs kernel patches


 * Add r8168 driver
 * Build it all
 * Install emgd driver
 * Transfer results to joggler

Back on joggler

 * install the initramfs tools
 * customise initramfs for read-only root fs as detailed here
 * Add additional joggler specific customisations, I "reverse engineered" these from BuZs's but maybe he can provide some details.
 * build the initramfs.
 * Configure grub
 * Reboot

=Details= These are the actual steps required, some of this will vary slightly from above as I have decided to document this base on applying the same procedure to another joggler and trying to make each step as copy/paste freindly as I can.

Boot Joggler into Ubuntu
Not much to say here, boot your joggler into ubuntu or similar using one of the many bootable images. Either setup ssh and login to it or connect keyboard, open a terminal and gain root privileges.

Install steps / script !!! INCOMPLETE / WIP !!!
Now either read through the below typing step by step or if you like just copy paste the whole lot!

BUT!! Beware until this message is removed it is incomplete!

Part 1
Coming soon

This part will be run on the PC to create a kernel for joggler - it will be vanilla kernel 3.2.4 with BuZz's joggler patches applied. Also added, the aufs, r8168, emgd modules. The result of this part will generate a tarball containing the kernel, modules, config, and grub.efi.

Part 2
This is (a nearly complete - needs some error checking) part two, to be run on the joggler, it needs the kernel.tar.bz2 archive which results from step 1 (yet to be written).

Note : Edit MAC= line and add your desired mac address before using this script!

export JROOT=/tmp/mnt/root export JBOOT=${JROOT}/boot export MAC=XX:XX:XX:XX:XX:XX export KVER=3.2.4
 * 1) Set some vars

echo "re-partiiton emmc..." echo -e "2,99,0xef,*\n103,,0x83" | sfdisk -uM /dev/mmcblk0 echo "Format Boot FS" mkfs.msdos /dev/mmcblk0p1 -n BOOT echo "Format Root FS" mkfs.ext2 /dev/mmcblk0p2 -L ROOT
 * 1) Re-partition mmc - format partitions
 * 1) Re-partition mmc - format partitions

echo "Mount Root FS" mkdir ${JROOT} -p mount /dev/mmcblk0p2 ${JROOT} echo "debootstrap Root FS" apt-get -y --force-yes install debootstrap debootstrap --arch i386 --variant=minbase oneiric ${JROOT}  http://archive.ubuntu.com/ubuntu/ chroot ${JROOT} apt-get -y --force-yes install net-tools

echo "Mount proc fs on Root" mount -t proc none ${JROOT}/proc echo "Mount sysfs on Root" mount -t sysfs none ${JROOT}/sys

echo "Custom joggler config files..." cat << _EOF_ > ${JROOT}/etc/modprobe.d/joggler.conf

blacklist rt2800usb
 * 1) rt2800usb is the kernel wireless driver. was problematic on older
 * 2) kernels but may be better on newer than the vendor driver.
 * 3) rt2870sta is the vendor driver packaged on the joggler ppa
 * 4) if one driver is problematic, consider switching
 * 1) blacklist rt2870sta

blacklist r8169
 * 1) the kernel r8169 driver can lockup (even in linux 3.1)
 * 2) so  we will use the r8168 vendor driver

options snd-hda-intel position_fix=1 bdl_pos_adj=64
 * 1) snd-hda-intel audio fixups

_EOF_

echo "mount Boot FS" mount /dev/mmcblk0p1 ${JBOOT} echo "configure EFI boot loader" echo "grub" > ${JBOOT}/boot.nsh echo "fs1:boot" > ${JBOOT}/startup.nsh echo "fs0:boot" >> ${JBOOT}/startup.nsh
 * 1) Setup booting
 * 1) Setup booting

echo "Configure grub boot loader" cat << _EOF_ > ${JBOOT}/grub.cfg set timeout=2 menuentry "Ubuntu 11.10 (Oneiric) - ${KVER}-joggler" { set root=(hd0,1) linux /vmlinuz-${KVER}-joggler root=/dev/mmcblk0p2 quiet thermal.psv=80 initrd /initrd.img-${KVER}.ro } _EOF_

echo "Unpack kernel and config, also grub.efi atm" tar jxf ./kernel.tar.bz2 -C ${JROOT}

echo "Customise initramfs-tools for joggler" cp /etc/mtab ${JROOT}/etc echo "r8168" > ${JROOT}/etc/initramfs-tools/modules cat << _EOF_ > ${JROOT}/etc/initramfs-tools/hooks/joggler
 * 1) create initrd
 * 2) It might be useful to be able to boot into a normal RW system so we will create two initrd's
 * 3) 1) apply joggler specific initrd mods
 * 1) It might be useful to be able to boot into a normal RW system so we will create two initrd's
 * 2) 1) apply joggler specific initrd mods
 * 1) 1) apply joggler specific initrd mods
 * 1) prevent df from whining in update-initramfs
 * 1) !/bin/sh

PREREQ=''

prereqs { echo "\$PREREQ" }

case \$1 in prereqs) prereqs  exit 0  ;; esac

. /usr/share/initramfs-tools/hook-functions copy_exec /sbin/ifconfig /sbin cp -p /etc/modprobe.d/joggler.conf \$DESTDIR/etc/modprobe.d/

_EOF_

chmod +x ${JROOT}/etc/initramfs-tools/hooks/joggler

echo "/sbin/ifconfig eth0 hw ether ${MAC}" > ${JROOT}/etc/initramfs-tools/scripts/init-premount/fix_mac chmod +x ${JROOT}/etc/initramfs-tools/scripts/init-premount/fix_mac

echo "Generate initrams for RW use" chroot ${JROOT} update-initramfs -c -k ${KVER} mv ${JBOOT}/initrd.img-${KVER} ${JBOOT}/initrd.img-${KVER}.rw

echo "Apply read-only initramfs scripts" cat << _EOF_ > ${JROOT}/etc/initramfs-tools/hooks/ro_root
 * 1) Apply read-only initrd changes
 * 1) Apply read-only initrd changes
 * 1) The hook
 * 1) !/bin/sh

PREREQ=''

prereqs { echo "\$PREREQ" }

case \$1 in prereqs) prereqs  exit 0  ;; esac

. /usr/share/initramfs-tools/hook-functions manual_add_modules aufs manual_add_modules tmpfs copy_exec /bin/chmod /bin

_EOF_

chmod +x ${JROOT}/etc/initramfs-tools/hooks/ro_root

cat << _EOF_ > ${JROOT}/etc/initramfs-tools/scripts/init-bottom/ro_root
 * 1) The boot script


 * 1) !/bin/sh

PREREQ=''

prereqs { echo "\$PREREQ" }

case \$1 in prereqs) prereqs  exit 0  ;; esac

ro_mount_point="\${rootmnt%/}.ro" rw_mount_point="\${rootmnt%/}.rw"

mkdir "\${ro_mount_point}" "\${rw_mount_point}"
 * 1) Create mount points for the read-only and read/write layers:

mount --move "\${rootmnt}" "\${ro_mount_point}"
 * 1) Move the already-mounted root filesystem to the ro mount point:

mount -t tmpfs root.rw "\${rw_mount_point}"
 * 1) Mount the read/write filesystem:

mount -t aufs -o "dirs=\${rw_mount_point}=rw:\${ro_mount_point}=ro" root.union "\${rootmnt}"
 * 1) Mount the union:

chmod 755 "\${rootmnt}"
 * 1) Correct the permissions of /:

mkdir "\${rootmnt}/ro" "\${rootmnt}/rw" mount --bind "\${ro_mount_point}" "\${rootmnt}/ro" mount --bind "\${rw_mount_point}" "\${rootmnt}/rw"
 * 1) Make sure the individual ro and rw mounts are accessible from within the root
 * 2) once the union is assumed as /.  This makes it possible to access the
 * 3) component filesystems individually.

_EOF_

chmod +x ${JROOT}/etc/initramfs-tools/scripts/init-bottom/ro_root

echo "Generate read-only initramfs" chroot ${JROOT} update-initramfs -c -k ${KVER} mv ${JBOOT}/initrd.img-${KVER} ${JBOOT}/initrd.img-${KVER}.ro

echo "umount file systems" umount ${JROOT}/sys umount ${JROOT}/proc umount ${JROOT}/boot umount ${JROOT}

echo "All Done!!"