setup_live()
{
    echo "Setting up live cd"
     
    echo "#!/bin/sh -e
    cd /
    unset DURING_INSTALL
    [ ! -x /usr/bin/update-menus ] || /usr/bin/update-menus --nofork -v
    [ ! -f /etc/firsttime.d/menu ] || rm -f /etc/firsttime.d/menu
    if [ -d /etc/firsttime.d ];then
     for i in /etc/firsttime.d/*;do \$i; done ||:
    fi
    if [ -x /sbin/depmod ];then
	for i in /lib/modules/*;do
	    /sbin/depmod -a -F /boot/System.map-\`basename \$i\` \`basename \$i\`
	done
    fi
    " >$ROOT/makelive
    chmod 555 $ROOT/makelive
    $in_chroot /makelive
    rm -f $ROOT/makelive
cat <<E_O_F >> $ROOT/etc/remounttab
/mnt
/media  size=50k
E_O_F

cat <<E_O_F >> $ROOT/etc/overlaytab
/etc
/dev
/var
/lib
/bin
/sbin
/home
/root
E_O_F

cat <<E_O_F >> $ROOT/etc/sysconfig/network
NETWORKING=yes
FORWARD_IPV4=false
HOSTNAME=$SUITE
DOMAINNAME=localhost
E_O_F

cat <<E_O_F >> $ROOT/etc/HOSTNAME
$SUITE.localhost
E_O_F

cat <<E_O_F>>$ROOT/etc/init.d/functions
# Remount root fs parts via tmpfs
remount_root_readwrite()
{
    REMOUNTTAB=/etc/remounttab
    LIVETAB=/etc/overlaytab
    if [ -s \$REMOUNTTAB ]; then
        grep -ve '^\(#\|\$\)' \$REMOUNTTAB |while read mntpt rest; do
            if [ -d \$mntpt ]; then
                [ -z "\$rest" ] || rest="-o \$rest"
                echo -n "Remounting \$mntpt read/write:"
		(cd \$mntpt && tar cp --same-owner --same-permissions . 2> /dev/null) |\
		(mount -n -ttmpfs \$rest /dev/shm \$mntpt && tar xp -C \$mntpt/ 2>/dev/null) && echo_success || echo_failure
		echo
            fi
        done

        if [ -s \$LIVETAB ]; then
	    grep -ve '^\(#\|\$\)' \$LIVETAB |while read mntpt; do
    		if [ -d \$mntpt ]; then
		   mkdir -p /mnt/root/\$mntpt
    		   echo -n "Remounting \$mntpt to overlay:"
		   mount -n -tunionfs -o dirs=/mnt/root/\$mntpt=rw:\$mntpt=ro /mnt/root/\$mntpt \$mntpt && echo_success || echo_failure
		   echo
        	fi
    	    done
	fi
    else
	action "Remounting root filesystem in read/write mode:" mount -n -o remount,rw /
    fi
}

E_O_F

subst "s|action \"Remounting root filesystem in read/write mode:\" mount -n -o remount,rw /|remount_root_readwrite|" $ROOT/etc/rc.d/rc.sysinit

}

setup_live
echo "/dev/root / auto  defaults,ro 0 0" >>$ROOT/etc/fstab
echo "tmpfs /tmp tmpfs defaults 0 0" >>$ROOT/etc/fstab
# stage1 need this
$in_chroot /bin/mkdir /image
