# Local filesystem mounting			-*- shell-script -*-

pre_mountroot()
{
  [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/fliwi-top"
  run_scripts /scripts/fliwi-top
  [ "$quiet" != "y" ] && log_end_msg

  wait_for_udev 10

  # Load ubi with the correct MTD partition and return since fstype
  # doesn't work with a char device like ubi.
  if [ -n "$UBIMTD" ]; then
    modprobe ubi mtd=$UBIMTD
  fi
}

mountroot()
{
  pre_mountroot

  [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/fliwi-premount"
  run_scripts /scripts/fliwi-premount
  [ "$quiet" != "y" ] && log_end_msg

  # Mount root
  mount -n -t tmpfs -o size=444M tmpfs /root || panic "ALERT!  Failed to setup a root-mount.  Dropping to a shell!"
  tar -C /root -x -f /system_root.tar || panic "ALERT!  Failed to extract contents into root-mount.  Dropping to a shell!"
  cp -a /lib/modules /root/lib/ 2>/dev/null || true
  cp -a /lib/firmware /root/lib/ 2>/dev/null || true
  cp -a /etc/fliwi-in-memory-system /root/etc/fliwi-in-memory-system

  [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/fliwi-bottom"
  run_scripts /scripts/fliwi-bottom
  [ "$quiet" != "y" ] && log_end_msg

}
