anchor.diff:  # Copy file system from temporary rootdir to EBS volume
   tar -cSf - -C $imagedir . | sudo tar xvf - -C $ebsimagedir
   
  +# Unmount 
   umount $imagedir
   umount $ebsimagedir
   
  
positive.code: chroot $imagedir /tmp/custom_user_script
  # END CUSTOM USER SCRIPT
  
  # Clean up chroot environment
  chroot $imagedir umount /proc
  #chroot $imagedir umount /dev/pts
  rm -f $imagedir/usr/sbin/policy-rc.d
  
  # Wait for EBS volume to be attached
  dev=<%= ebs_device %>
  while [ ! -e $dev ]; do sleep 1; done
  
  # Format and mount the EBS volume
  
negative.code: mount -o loop $image $imagedir
  
  # Allow network access from chroot environment
  # cp fails because the symlink reference doesn't exist. Create a backup for now. 
  mv $imagedir/etc/resolv.conf $imagedir/etc/resolv.conf.bak
  cp /etc/resolv.conf $imagedir/etc/
  
  # Upgrade and install packages on the target file system
  chroot $imagedir mount -t proc none /proc
  
  # prevent daemons from starting during apt-get 
  cat <<EOF | tee $imagedir/usr/sbin/policy-rc.d > /dev/null
  #!/bin/sh
  exit 101
  EOF
  
  chmod 755 $imagedir/usr/sbin/policy-rc.d
  
  chroot $imagedir apt-get update
  chroot $imagedir apt-get dist-upgrade -y
  
  