#!/bin/sh
export PATH=/bin:/sbin
mount -t proc none /proc
CMDLINE=`cat /proc/cmdline`
umount /proc

# CDROM suchen und mounten
CDROM=""
for x in hda hdb hdc hdd
do
  mount -t iso9660 -r /dev/${x} /cdrom > /dev/null 2>&1
  if [ "$?" = "0" ]
  then
         CDROM="${x}"
         break
  fi
done

# wenn CDROM nicht gefunden
if [ "${CDROM}" == "" ]
then
  exec /bin/sh
  exit
fi

#/bin/bash

CDBOOT="yes"
export CDBOOT

# mount root und erstelle rw Verzeichnisse 
modprobe unionfs
mount -t squashfs -o loop /cdrom/files/source.img /new > /dev/null 2>&1
mount -t tmpfs -o size=64m none /new/ramdisk > /dev/null 2>&1
mount -t unionfs -o dirs=/new/ramdisk=rw:/new=ro none /new > /dev/null 2>&1

# starte Original Debian init Script

cd /new
pivot_root . live
exec /usr/sbin/chroot . /bin/sh <<- EOF >dev/console 2>&1
exec /sbin/init ${CMDLINE}
EOF

