Ubuntu Internal emmc

From Joggler
Jump to: navigation, search

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 [1] and config file
  • Add aufs kernel patches [2]
  • Add r8168 driver [3]
  • 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 [4]
  • 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!

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

##########################################
## Re-partition mmc - format partitions
##########################################
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

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

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

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

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

_EOF_


##############################
## Setup booting
##############################
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

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}

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


#########
# Apply read-only initrd changes
#########
echo "Apply read-only initramfs scripts"
##The hook
cat << _EOF_ > ${JROOT}/etc/initramfs-tools/hooks/ro_root
#!/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

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

#!/bin/sh

PREREQ=''

prereqs() {
  echo "\$PREREQ"
}

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

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

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

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

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

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

# Correct the permissions of /:
chmod 755 "\${rootmnt}"

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

_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!!"