home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
redakcyjne
/
openSuSE
/
openSUSE-11.2-KDE4-LiveCD-i686.iso
/
boot
/
i386
/
loader
/
initrd
/
initrd~
/
init
< prev
next >
Wrap
Text File
|
2009-11-02
|
11KB
|
369 lines
#!/bin/bash
#================
# FILE : linuxrc
#----------------
# 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 changed to become the real
# : linuxrc script which is used to prepare the
# : operating system for the main image
# :
# :
# STATUS : BETA
#----------------
#======================================
# Exports (General)...
#--------------------------------------
export PATH="/sbin:/bin:/usr/sbin:/usr/bin"
export IFS_ORIG=$IFS
export DEBUG=0
export ARCH=`arch`
#======================================
# Exports (Configuration)...
#--------------------------------------
export systemIntegrity=clean
export LIVECD_CONFIG="/cdrom/config.isoclient"
export LIVECD="/livecd"
export LOCAL_BOOT="no"
#======================================
# Functions...
#--------------------------------------
. /include
#======================================
# Beautify Startup
#--------------------------------------
echo "Loading KIWI CD Boot-System..."
echo "------------------------------"
#======================================
# Update library path
#--------------------------------------
ldconfig
#======================================
# 1) Mounting local file systems
#--------------------------------------
mountSystemFilesystems &>/dev/null
closeKernelConsole
#======================================
# 2) probe for livecd_config in cmdline
#--------------------------------------
includeKernelParameters
if grep -i -q "livecd_config=[a-zA-Z0-9/]" /proc/cmdline; then
export LIVECD_CONFIG=`sed 's/.*livecd_config=\([^ ]*\).*/\1/' /proc/cmdline`
fi
#======================================
# 3) Prepare module load support
#--------------------------------------
touch /etc/modules.conf
touch /lib/modules/*/modules.dep
#======================================
# 4) run udevd
#--------------------------------------
udevStart
#======================================
# 5) start boot shell and logging
#--------------------------------------
startBlogD
startShell
errorLogStart
openKernelConsole
#======================================
# 6) Including required kernel modules
#--------------------------------------
probeDevices
#======================================
# 7) Mount the CD device
#--------------------------------------
CDMount
#======================================
# 8) Load configuration
#--------------------------------------
importFile < $LIVECD_CONFIG
if [ ! -z "$HYBRID_RW" ];then
if [ ! -z "$UNIONFS_CONFIG" ];then
UNIONFS_CONFIG=$(echo $UNIONFS_CONFIG | sed -e s@/dev/ram1@$HYBRID_RW@)
else
IMAGE=$(echo $IMAGE | sed -e s@/dev/ram1@$HYBRID_RW@)
fi
fi
#======================================
# 9) Download RW part of the CD image
#--------------------------------------
IFS="," ; for i in $IMAGE;do
field=0
IFS=";" ; for n in $i;do
case $field in
0) imageDevice=$n ; field=1 ;;
1) imageName=$n ; field=2 ;;
2) imageVersion=$n
esac
done
imageReadOnly="$imageName"
imageReadOnly=`echo $imageReadOnly | sed -e s@.$ARCH@@`
imageReadOnly="$imageReadOnly-read-only.$ARCH-$imageVersion"
imageName="/cdrom/$imageName-$imageVersion"
gzippName=$imageName.gz
imageMD5s="$imageName.md5"
if [ ! -z "$UNIONFS_CONFIG" ] || [ ! -z "$COMBINED_IMAGE" ];then
continue
fi
while true;do
IFS=" "
read sum1 blocks blocksize zblocks zblocksize < $imageMD5s
if ! validateSize;then
systemException \
"Not enough RAM available for this image" \
"reboot"
fi
needBytes=`gzip -l $gzippName|tail -n1|sed -e "s@ \+@:@g"|cut -f3 -d:`
needMByte=`expr $needBytes / 1024 / 1024`
if [ -x /usr/bin/dcounter ];then
errorLogStop
Echo -n "Loading $imageName [$imageDevice] "
gzip -cd $gzippName |\
dcounter -s $needMByte | dd of=$imageDevice &>/dev/null
errorLogContinue
echo
else
Echo "Loading $imageName [$imageDevice]..."
gzip -cd $gzippName | dd of=$imageDevice
fi
dd if=$imageDevice bs=1024 |\
head --bytes=$((blocks * blocksize)) |\
md5sum - > /etc/ireal.md5
read sum2 dumy < /etc/ireal.md5
if test $sum1 = $sum2;then
Echo "Image checksum test: fine :-)"
break
fi
Echo "Image checksum test failed:"
echo
Echo -b "1) Data corruption while loading the image:"
Echo -b " will give it a new try..."
echo
Echo -b "2) ramdisk size is too small for the image:"
Echo -b " try to set the kernel parameter ramdisk_size=<size>"
echo
Echo "Retry to load image..."
sleep 15
done
rm -f /etc/ireal.md5
done
CDUmount
#======================================
# 10) Get filesystem type
#--------------------------------------
if [ -z "$UNIONFS_CONFIG" ];then
probeFileSystem $imageDevice
if [ "$FSTYPE" = "luks" ];then
imageDevice=$(luksOpen $imageDevice)
probeFileSystem $imageDevice
export haveLuks=yes
fi
if test "$FSTYPE" = "reiserfs";then
Echo "Resize Reiser filesystem to full ramdisk space..."
luksResize $imageDevice
resize_reiserfs $imageDevice
fi
if test "$FSTYPE" = "ext2";then
Echo "Resize EXT2 filesystem to full ramdisk space..."
luksResize $imageDevice
resize2fs -f $imageDevice
fi
if test "$FSTYPE" = "ext3";then
Echo "Resize EXT3 filesystem to full ramdisk space..."
luksResize $imageDevice
resize2fs -f $imageDevice
fi
if test "$FSTYPE" = "ext4";then
Echo "Resize EXT4 filesystem to full ramdisk space..."
luksResize $imageDevice
resize2fs -f $imageDevice
fi
fi
#======================================
# 11) Check for swap space
#--------------------------------------
swapSpace=`searchSwapSpace`
if [ ! -z "$swapSpace" ];then
#======================================
# 11.1) use an existing swap partition
#--------------------------------------
Echo "Found swap space on: $swapSpace"
else
#======================================
# 11.1) use a swap file on a free part.
#--------------------------------------
swapDevice=`searchDiskSpace`
if [ ! -z "$swapDevice" ];then
FSTYPE_SAVE=$FSTYPE
probeFileSystem $swapDevice
SWTYPE=$FSTYPE
FSTYPE=$FSTYPE_SAVE
if [ $SWTYPE = "unknown" ];then
Echo "Can't use unknown filesystem for swap file... skipped"
else
Echo "Setting up swap file on: $swapDevice -> $SWTYPE"
mRAM=`cat /proc/meminfo | grep MemTotal | cut -f2 -d:`
mRAM=`echo $mRAM | cut -f1 -d" "`
SWSIZE=`expr $mRAM / 1024`
SWSIZE=`expr $SWSIZE \* 2`
if [ $SWSIZE -lt 64 ];then
SWSIZE=64
fi
SWDIR=/liveswap
SWFILE=$SWDIR/kiwiswap
mkdir -p $SWDIR
if ! mount -t $SWTYPE $swapDevice $SWDIR;then
Echo "Failed to mount swap device on: $swapDevice"
unset swapDevice
fi
if [ ! -f $SWFILE ];then
dd if=/dev/zero of=$SWFILE bs=1M count=$SWSIZE >/dev/null
if [ ! $? = 0 ];then
Echo "Failed to create swap file on: $swapDevice"
unset swapDevice
fi
if ! mkswap $SWFILE >/dev/null;then
Echo "Failed to initialize swap file"
unset swapDevice
fi
fi
Echo "Created swap file: kiwiswap [ $SWSIZE MB ]"
umount $SWDIR
fi
fi
fi
#======================================
# 12) Mount OS image to /mnt
#--------------------------------------
runHook premount
if [ -z "$UNIONFS_CONFIG" ] && [ -z "$COMBINED_IMAGE" ];then
#======================================
# 12.1) mount RW part and CD to /mnt
#--------------------------------------
if ! mount $imageDevice /mnt >/dev/null;then
systemException "Failed to mount RW root filesystem" "reboot"
fi
cdopt=$(CDMountOption $cddev)
mkdir -p $LIVECD && eval mount $cdopt $cddev $LIVECD
#======================================
# 12.2) Create RO Link list
#--------------------------------------
cd /mnt
if [ ! -d $LIVECD/read-only-system ];then
Echo "Mounting compressed read only tree..."
rosys="/read-only"
rosrc="$LIVECD/$imageReadOnly"
mkdir -p $rosys
if ! kiwiMount $rosrc $rosys "-o loop";then
systemException "Failed to mount RO root filesystem" "reboot"
fi
Echo "Creating live media links..."
for dir in bin boot lib lib64 opt sbin usr;do
ln -s read-only/$dir $dir
done
else
Echo "Creating live media links..."
for dir in bin boot lib lib64 opt sbin usr;do
if [ -d $LIVECD/read-only-system/$dir ];then
ln -s $LIVECD/read-only-system/$dir $dir
fi
done
fi
cd /
else
#======================================
# 12.1) mount CD to /mnt and unify
#--------------------------------------
if [ ! -z "$COMBINED_IMAGE" ]; then
Echo "Mounting compressed split tree..."
imageReadOnly=`echo $imageReadOnly | sed -e "s/-read-only//"`
else
Echo "Mounting compressed unified tree..."
fi
cdopt=$(CDMountOption $cddev)
mkdir -p $LIVECD && eval mount $cdopt $cddev $LIVECD
if ! mountSystem /dev/loop1 $LIVECD/$imageReadOnly;then
systemException "Failed to mount root filesystem" "reboot"
fi
fi
validateRootTree
runHook postmount
#======================================
# 13) Create system dependant files
#--------------------------------------
setupDefaultFstab /config
updateRootDeviceFstab /config $imageDevice
if [ ! -z "$swapSpace" ];then
updateSwapDeviceFstab /config $swapSpace
elif [ ! -z "$swapDevice" ];then
mkdir -p /mnt/liveswap
echo "$swapDevice /liveswap $SWTYPE defaults 1 1" >> /config/etc/fstab
echo "/liveswap/kiwiswap swap swap prio=42 0 0" >> /config/etc/fstab
fi
#======================================
# 14) copy system dependant files
#--------------------------------------
setupConfigFiles
#======================================
# 15) update system dependant files
#--------------------------------------
setupInittab /mnt
#======================================
# 16) setup real root device
#--------------------------------------
echo 256 > /proc/sys/kernel/real-root-dev
#======================================
# 17) umount system filesystems
#--------------------------------------
umountSystemFilesystems
#======================================
# 18) copy initrd files to image
#--------------------------------------
importBranding
cp /preinit /mnt
cp /include /mnt
#======================================
# 19) kill boot shell
#--------------------------------------
killShell
killBlogD
#======================================
# 20) Activate new root
#--------------------------------------
activateImage
#======================================
# 21) Unmount initrd / system init
#--------------------------------------
bootImage $@