#!/bin/bash

target="union"

function write() {
  [ -z "${1}" ] && return 1

  mkdir -p ${target}/$(dirname ${1})
  cat > ${target}/${1}
}

function chroot() {
  $(which chroot) ${target} env -i /bin/bash
}

function setup_fs() {
  if [ ! -f fs ]; then
    dd if=/dev/null of=fs bs=1k seek=512k
    mkfs.ext2 -q -F fs
  fi

  mkdir -p rootfs ${target}
  mount -n -o loop fs rootfs

  codename=$(lsb_release -c -s)

  case "${codename}" in

  lucid|natty|oneiric)
    mount -n -t aufs -o br:rootfs=rw:../../base/rootfs=ro+wh none ${target}
    ;;

  precise)
    mount -n -t overlayfs -o rw,upperdir=rootfs,lowerdir=../../base/rootfs none ${target}
    ;;

  *)
    echo "Unsupported: '${codename}'"
    exit 1
    ;;

  esac
}

function teardown_fs() {
  umount ${target}
  umount rootfs
}

#!/bin/bash

target="union"

function write() {
  [ -z "${1}" ] && return 1

  mkdir -p ${target}/$(dirname ${1})
  cat > ${target}/${1}
}

function chroot() {
  $(which chroot) ${target} env -i /bin/bash
}

function setup_fs() {
  if [ ! -f fs ]; then
    dd if=/dev/null of=fs bs=1k seek=512k

    # - don't include a journal
    # - skip initialization of block groups
    mkfs.ext4 -q -F -O "^has_journal,uninit_bg" fs
  fi

  mkdir -p rootfs ${target}
  mount -n -o loop fs rootfs

  codename=$(lsb_release -c -s)

  case "${codename}" in

  lucid|natty|oneiric)
    mount -n -t aufs -o br:rootfs=rw:../../base/rootfs=ro+wh none ${target}
    ;;

  precise)
    mount -n -t overlayfs -o rw,upperdir=rootfs,lowerdir=../../base/rootfs none ${target}
    ;;

  *)
    echo "Unsupported: '${codename}'"
    exit 1
    ;;

  esac
}

function teardown_fs() {
  umount ${target}
  umount rootfs
}

Move back to ext4 with some tweaks
warden: Move back to ext4 with some tweaks

Change-Id: If470ce8eea6b6f024afb402d0f21b8b7fe2dff9e
