preinit 4.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#!/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) start error log
#--------------------------------------
errorLogStart
Echo "Calling pre-init stage in system image"

#======================================
# 2) check for LOCAL_BOOT
#--------------------------------------
if [ "$LOCAL_BOOT" = "yes" ] && [ -z "$KIWI_RECOVERY" ];then
	exit 0
fi

#======================================
# 3) start udev
#--------------------------------------
mountSystemFilesystems
udevSystemStart

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

#======================================
# 5) create framebuffer devices
#--------------------------------------
createFramebufferDevices

#======================================
# 6) create initrd on diskful
#--------------------------------------
if \
	[ -z "$UNIONFS_CONFIG" ] && [ -z "$COMBINED_IMAGE" ] && \
	[ ! "$OEM_KIWI_INITRD" = "yes" ]
then
	#======================================
	# use distro initrd via mkinitrd
	#--------------------------------------
	setupSUSEInitrd
else
	#======================================
	# use kiwi initrd from RW partition
	#--------------------------------------
	bootLoaderOK=1
fi

#======================================
# 7) Check FAT requires on syslinux
#--------------------------------------
if [ "$loader" = "syslinux" ];then
	# /.../
	# if syslinux is used we need to make sure that the
	# filename on the boot partition is correct 8+3
	# ----
	count=1
	IFS="," ; for i in $KERNEL_LIST;do
		if test -z "$i";then
			continue
		fi
		kernel=`echo $i | cut -f1 -d:`
		initrd=`echo $i | cut -f2 -d:`
		mv /boot/$kernel /boot/linux.$count
		mv /boot/$initrd /boot/initrd.$count
		running=$(uname -r)
		rlinux=vmlinuz-$running
		rinitrd=initrd-$running
		ln -s /boot/linux.$count  /boot/$rlinux
		ln -s /boot/initrd.$count /boot/$rinitrd
		count=`expr $count + 1`
	done
	IFS=$IFS_ORIG
fi

#======================================
# 8) Install boot loader if ok
#--------------------------------------
if [ $bootLoaderOK = 1 ];then
	installBootLoader
fi

#======================================
# 9) copy recovery related files
#--------------------------------------
if [ "$LOCAL_BOOT" = "no" ] && [ ! -z "$OEM_RECOVERY" ];then
	IFS=$IFS_ORIG
	Echo "Setting up recovery configuration archive..."
	mkdir -p /reco-save
	if ! mount $imageRecoveryDevice /reco-save >/dev/null;then
		systemException "Failed to mount recovery device" "reboot"
	fi
	backupBootFiles=""
	for i in \
		/etc/fstab \
		/etc/sysconfig/kernel \
		/etc/sysconfig/bootloader \
		/etc/grub.conf \
		/etc/lilo.conf
	do
		test -e $i && backupBootFiles="$backupBootFiles $i"
	done
	tar -czf /reco-save/boot-1.tgz $backupBootFiles
	backupBootFiles=""
	for i in $(find /boot -type f); do
		if ! echo $i | grep -q -E "\.sys";then
			backupBootFiles="$backupBootFiles $i"
		fi
	done
	tar -czf /reco-save/boot-2.tgz $backupBootFiles
	Echo "Installing boot loader into recovery partition"
	setupBootLoaderRecovery / /reco-save OEM
	installBootLoaderRecovery
	umount /reco-save
	rmdir /reco-save
fi

#======================================
# 10) create /etc/ImagePackages
#--------------------------------------
if [ "$LOCAL_BOOT" = "no" ];then
	if [ -x /bin/rpm ];then
		Echo "Creating initial image package info file"
		rpm -qa --last > /etc/ImagePackages
	fi
fi

#======================================
# 11) setup console
#--------------------------------------
setupConsole

#======================================
# 12) kill udev
#--------------------------------------
udevSystemStop
umountSystemFilesystems