#!/bin/bash
#================
# FILE          : preinit
#----------------
# PROJECT       : OpenSuSE KIWI Image System
# COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH. All rights reserved
#               :
# AUTHOR        : Marcus Schaefer <ms@suse.de>
#               :
# BELONGS TO    : Operating System images
#               :
# DESCRIPTION   : This file is called after the image root
#               : has changed by the linuxrc script
#               :
# STATUS        : BETA
#----------------
#======================================
# Functions...
#--------------------------------------
. /include

#======================================
# 1) update mount table
#--------------------------------------
updateMTAB

#======================================
# 2) check for union filesystem
#--------------------------------------
if [ ! -z "$UNIONFS_CONFIG" ]; then
	# /.../
	# we are using a special root setup with aufs. In this case
	# we can't use the SuSE Linux initrd but must stick to the
	# kiwi boot system.
	# ---- 
	exit 0
fi

#======================================
# 3) create initrd on diskful
#--------------------------------------
if test -L /boot/boot;then
	mount -t proc proc /proc
	mount -t sysfs sysfs /sys
	mkinitrd 
	umount /sys
	umount /proc
else
	Echo "Image doesn't provide kernel system map"
	Echo "Can't create initrd"
fi

#======================================
# 4) Install boot loader on diskful
#--------------------------------------
if test -f "/usr/sbin/grub";then
	Echo "Installing boot loader..."
	/usr/sbin/grub --batch --no-floppy < /etc/grub.conf >/dev/null 2>&1
else
	Echo "Image doesn't provide grub support"
	Echo "Can't install boot loader"
fi
