Rev 259 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/bin/bash################################################################## Installes the LiveCD on local hard disk## Boot LiveCD and run this script as root## Urs Beyerle# Brent L. Bates################################################################################################################################ Definitions################################################################ set PATHPATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin"# RPMs that are no longer needed and may break future udpatesRPMS_TO_REMOVE="kernel-module-squashfs \kernel-module-unionfs \kernel-module-aufs \unionfs-.* \aufs-.* \squashfs-.*"# RPMs that can break future Scientific Linux updates# because there are not part of Scientific LinuxRPMS_TO_REMOVE_SL=""# RPMs that can break future PSI SL updates# because there are not part of PSI Scientific LinuxRPMS_TO_REMOVE_PSI=""# files which should be restored from .ori filesFILES_RESTORE="/etc/init.d/netfs \/etc/init.d/autofs \/etc/init.d/halt \/etc/init.d/network/etc/init.d/functions \/etc/rc.d/rc.sysinit \/etc/sysconfig/afs \/etc/motd \/etc/redhat-release \/etc/hotplug/blacklist \/etc/modprobe.d/blacklist \/lib/udev/udev_run_hotplugd \/etc/rc.d/rc.local"# LiveCD init scripts will be removedLIVECD_INIT_SCRIPTS="runfirst \runveryfirst \runlast \kudzu-auto \login"# Main directories which should be not be copiedDIR_NOT_COPY="/proc \/dev \/livecd \/boot \/afs \/sys \/media \/misc \/mnt \/net \/initrd"# Mount point of the new SL systemNEW=/mnt/harddisk# Name of the scriptSCRIPTNAME=$( basename $0 )# dir of mounted /$MOUNTDIR/liveMOUNTDIR=livecd# Default File System TypeFS_TYPE=ext3################################################################ Functions###############################################################function usage() {## Usage# ----------------------------------------------------------cat <<EOF$SCRIPTNAME [OPTIONS] -mbr=[DEVICE] [PARTITION | MOUNTED FILE SYSTEM]Installes LiveCD on PARTITION and the bootloader grub intothe Master Boot Record (MBR) of DEVICE. The MBR will bebacked up to PARTITION.OPTIONS:-h --help : Print this screen-swap=[partition(s)] : Use [partition(s)] as swap ("," or "|" separated)-win=[partition] : Your active Windows partition. If not given,$SCRIPTNAME tries to find it-nogrub : Do not install grub. You have to installmanually a bootloader (not recommended)-floppy : Needed, if grub should be installed on floppyIn this case use -mbr=/dev/fd0 -floppy-norpmremove : Do not remove RPMs that can break futureupdates (not recommended)-fstype : File system type (ext3,xfs,etc.), default is $FS_TYPE-y : Answer all questions with yesExample:$SCRIPTNAME -swap=/dev/sda3 -mbr=/dev/sda /dev/sda2Will install LiveCD on /dev/sda2 (= second partition onfirst SATA disk). All data on /dev/sda2 will be deleted./dev/sda3 has to be a Linux Swap partion. GRUB will beinstalled in the MBR of /dev/sda (= first SATA disk).Remarks:To display your hard disk partitions, user 'fdisk -l'.Use fdisk, qtparted or parted to create an empty Linuxpartition.EOF}function exit_now() {local exitcode=$1umount $INSTALL_PART 2>/dev/nullexit $exitcode}################################################################ Main################################################################## are we root?### -----------------------------------------------------------if [ "$( whoami )" != "root" ]; thenecho; echo "Please run this script as root: 'su - -c $SCRIPTNAME'"; echoexit_now 1fi### read options from command-line### -----------------------------------------------------------while [ $# -gt 0 ]; docase "$1" in-h)usage; exit_now;;--help)usage; exit_now;;-swap*)if echo $1 | grep -q '=' ; thenSWAP_PART=$( echo $1 | sed 's/^-swap=//' )elseshiftSWAP_PART=$1fi;;-mbr*)if echo $1 | grep -q '=' ; thenMBR_DEV=$( echo $1 | sed 's/^-mbr=//' )elseshiftMBR_DEV=$1fiMBR_DEV=$( echo "$MBR_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' );;-win*)if echo $1 | grep -q '=' ; thenWIN_PART=$( echo $1 | sed 's/^-win=//' )elseshiftWIN_PART=$1fi;;-nogrub)NOGRUB=$1;;-norpmremove)NORPMREMOVE=$1;;-floppy)FLOPPY=$1;;-fstype)shiftFS_TYPE=$1;;-y)YES=$1;;*)INSTALL_PART=$1;;esacshiftdoneecho### display fdisk -l### -----------------------------------------------------------echo "Output of 'fdisk -l' ..."fdisk -l 2>/dev/nullecho### test if $INSTALL_PART is defined### -----------------------------------------------------------if [ ! $INSTALL_PART ]; thenecho "No partition defined for installation."echo "Please see '$SCRIPTNAME -h'."; echoexit_now 1fi### test if MBR_DEV is given### -----------------------------------------------------------if [ ! $NOGRUB ]; thenif [ ! $MBR_DEV ]; thenecho "No MBR device defined."echo "Please see '$SCRIPTNAME -h'."echoexit_now 1fifi### test if $INSTALL_PART is mounted### -----------------------------------------------------------df -T -l | sed -e 's/ */ /g' | grep -q "${INSTALL_PART}"if [ "$?" = "0" ]; then### This is a mounted partition### -----------------------------------------------------------MOUNTED=1df -T -l | sed -e 's/ */ /g' | cut -d" " -f7 | grep -q "^${INSTALL_PART}$"if [ "$?" = "0" ]; then### Was given the mount point### -----------------------------------------------------------NEW=${INSTALL_PART}INSTALL_PART=`df -T -l | grep "${INSTALL_PART}$" | cut -d" " -f1`else### Was given the mount partition### -----------------------------------------------------------NEW=`df -T -l | grep "^${INSTALL_PART}" | sed -e 's/ */ /g' | cut -d" " -f7`fiFS_TYPE=`df -T -l | sed -e 's/ */ /g' | grep "^${INSTALL_PART}" | cut -d" " -f2`### Get boot defice information### Check for separate mounted boot partition### -----------------------------------------------------------INSTALL_DEV=`df -T -l | sed -e 's/ */ /g' | grep "boot$" | cut -d" " -f1`if [ "$?" = "0" ]; then### Separate boot partition### -----------------------------------------------------------INSTALL_BOOT_DIR=""else### Install and boot all one partition### -----------------------------------------------------------INSTALL_DEV=${INSTALL_PART}INSTALL_BOOT_DIR="/boot"fi### Is the boot device a RAID device### -----------------------------------------------------------mdadm -D $INSTALL_DEV 2>/dev/null | grep -q -i Versionif [ "$?" = "0" ]; then### Boot device is RAID### -----------------------------------------------------------BOOT_DRIVE=`mdadm -D $INSTALL_DEV | grep -v ':$' | grep "/dev/" | sed -e 's/ */ /g' | cut -d" " -f8 |head -1`INSTALL_PART_NR=$( echo "$BOOT_DRIVE" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )BOOT_DRIVE=$( echo "$BOOT_DRIVE" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )else### Boot device not RAID### -----------------------------------------------------------INSTALL_PART_NR=$( echo "$INSTALL_DEV" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )INSTALL_DEV=$( echo "$INSTALL_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )BOOT_DRIVE=$INSTALL_DEVfielse### Partition is NOT mounted### -----------------------------------------------------------MOUNTED=0### test if $INSTALL_PART exists### -----------------------------------------------------------fdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"if [ "$?" != "0" ]; thenecho "Partition $INSTALL_PART not found! See 'fdisk -l'."echo "Or you have to reboot first to make the partition table active."echoexit_now 1fi### test if $INSTALL_PART is a Linux partition### -----------------------------------------------------------fdisk -l 2>/dev/null | grep "Linux$" | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"if [ "$?" != "0" ]; thenecho "Partition $INSTALL_PART is not a Linux partition! (see 'fdisk -l')."echo "Use fdisk and/or qtparted to create a Linux partition!"echo "You have to reboot first to make the partition table active."echoexit_now 1fi### set $INSTALL_DEV (eg. /dev/sda)### -----------------------------------------------------------INSTALL_DEV=$( echo "$INSTALL_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )BOOT_DRIVE=$INSTALL_DEVINSTALL_PART_NR=$( echo "$INSTALL_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )INSTALL_BOOT_DIR="/boot"fi### test if $SWAP_PART exists and is a Linux Swap partition### -----------------------------------------------------------if [ "$SWAP_PART" ]; thenSWAP_PART=`echo ${SWAP_PART} |tr '[,|]' ' '`for SWAP_PARTITION in $SWAP_PART ; dofdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"if [ "$?" != "0" ]; thenecho "Swap partition $SWAP_PARTITION not found! (see 'fdisk -l')."echo "Or you have to reboot first to make the partition table active."echoexit_now 1fifdisk -l 2>/dev/null | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"if [ "$?" != "0" ]; thenecho "Partition(s) $SWAP_PARTITION is/are not a Linux swap partition! (see 'fdisk -l')."echo "Use fdisk and/or qtparted to create a Linux Swap partition !"echo "You have to reboot first to make the partition table active."echoexit_now 1fidonefi### print warning### -----------------------------------------------------------echo "------------------------------------------------------------"echo " LiveCD will be installed on partition $INSTALL_PART"[ "$SWAP_PART" ] && echo " Partition(s) $SWAP_PART will be used as swap partition(s)."[ ! $NOGRUB ] && echo " GRUB will be installed in Master Boot Record of $MBR_DEV"echo " !! All data on $INSTALL_PART will be lost !!"echo "------------------------------------------------------------"echo### continue?### -----------------------------------------------------------if [ ! $YES ]; thenecho -n "Continue (y/N)? "read keyecho[ "$key" != "y" ] && exit_now 0fi### format $SWAP_PART (don't format swap, if already formated)### -----------------------------------------------------------if [ "$SWAP_PART" ]; thenecho "Make swap on $SWAP_PART ..."swapoff -a >/dev/null 2>&1swapon -p 1 $SWAP_PART 2>/dev/nullif [ "$?" != "0" ]; thenfor SWAP_PARTITION in $SWAP_PART; doecho "Format $SWAP_PARTITION as swap."mkswap $SWAP_PARTITIONdonefiechofiif [ $MOUNTED = "0" ]; then### format $INSTALL_PART### -----------------------------------------------------------# define force option for mkfs commandFORCE=""[ "$FS_TYPE" = "xfs" ] && FORCE="-f"echo -n "Format $INSTALL_PART as $FS_TYPE, please wait ... "mkfs.$FS_TYPE $FORCE -q $INSTALL_PART || exit_now 1echo "done."; echo### mount $INSTALL_PART### -----------------------------------------------------------echo -n "Try to mount $INSTALL_PART to $NEW ... "mkdir -p $NEWmount $INSTALL_PART $NEW || exit_now 1echo "done."; echofi### copy root dirs### -----------------------------------------------------------echo "Copy Live System to $INSTALL_PART ..."root_dirs=$( ls / )for dir in $root_dirs; do# check if dir is not in $DIR_NOT_COPYdo_not_copy=""for not_dir in $DIR_NOT_COPY; doif [ "$not_dir" = "/$dir" ]; thendo_not_copy="yes"breakfidone# do not copy links[ -L /$dir ] && do_not_copy="yes"fail=""if [ ! $do_not_copy ]; thenecho -n " * Copy /$dir ... "# first delete $dir on hardiskrm -rf $NEW/$dircp -a -f /$dir $NEW || fail=trueecho "done."fifail=""doneechoif [ $fail ]; thenecho "ERROR: Not everything was copied to $INSTALL_PART"exit_now 1fi### move /usr/opt back to /opt### -----------------------------------------------------------if [ -d $NEW/usr/opt ]; thenecho -n "Move /opt back ... "mv $NEW/usr/opt $NEW/echo "done."; echofi### create dirs which were not copied### -----------------------------------------------------------for dir in $DIR_NOT_COPY; doif [ ! -d $NEW$dir ]; thenmkdir $NEW$dirfidone# we do not need this directoryrmdir $NEW/livecd# if not yet existing, createmkdir -p $NEW/srvmkdir -p $NEW/selinux### copy back original files### -----------------------------------------------------------echo -n "Restore original files ... "for file in $FILES_RESTORE; do[ -r $NEW${file}.ori ] && mv -f $NEW${file}.ori $NEW${file}doneecho "done."; echo### define kernel version### -----------------------------------------------------------rpm --quiet -q kernel && UP_installed=truerpm --quiet -q kernel-smp && SMP_installed=true[ $UP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp 2>/dev/null )if [ ! $KERNEL_VERSION ]; thenecho "ERROR: Kernel version could not be determined - installation failed"; echoexit_now 1fiif [ ! $NOGRUB ]; then### Backup Master Boot Record MBR### -----------------------------------------------------------# do we have already a backup?MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"if [ ! -e /tmp/$MBR_FILENAME ]; thenecho "Backup Master Boot Record (MBR) of $MBR_DEV ..."dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1ficp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAMEecho "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"echo### install grub### -----------------------------------------------------------echo "Run grub-install ... "mkdir -p $NEW/boot/grub[ ! $FLOPPY ] && NO_FLOPPY_OPT="--no-floppy"grub-install $NO_FLOPPY_OPT --root-directory=$NEW $MBR_DEV 2>/dev/null || GRUB_FAILED="yes"if [ $GRUB_FAILED ]; thenecho "grub installation failed. grub-install will run again at the end."elseecho "done."fiecho### check for device.map file### -----------------------------------------------------------DEVICE_MAP=$NEW/boot/grub/device.mapif [ ! -e $NEW/boot/grub/device.map ]; thenecho "ERROR: $NEW/boot/grub/device.map not found"exit_now 1fi### convert dev syntax to grub syntax### -----------------------------------------------------------GRUB_INSTALL_DEV=$( grep $BOOT_DRIVE $DEVICE_MAP | awk '{ print $1 }' )GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )### find active Windows partition### -----------------------------------------------------------if [ ! $WIN_PART ]; then# try to find active Windows partitionWIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )fiif [ $WIN_PART ]; thenWIN_installed=trueWIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )# convert dev syntax to grub syntaxGRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )# $GRUB_WIN_PART should be something like (hd0,0)echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )"echo "Will add entry for Windows in GRUB."echofi### create grub.conf file### -----------------------------------------------------------echo "Create grub.conf ..."TITLE="Linux"[ -e $NEW/etc/redhat-release ] && TITLE=$( cat $NEW/etc/redhat-release )DEFAULT=0# set default=1, if smp kernel is runninguname -r | grep -q smp[ "$?" = "0" ] && DEFAULT=1cat > $NEW/boot/grub/grub.conf <<EOF# grub.conf generated by $SCRIPTNAMEdefault=$DEFAULTtimeout=10splashimage=${GRUB_ROOT_PART}${INSTALL_BOOT_DIR}/grub/splash.xpm.gz#hiddenmenuEOFif [ $UP_installed ]; thenecho "Add entry for UP kernel into grub.conf"cat >> $NEW/boot/grub/grub.conf <<EOFtitle $TITLE (${KERNEL_VERSION})root $GRUB_ROOT_PARTkernel ${INSTALL_BOOT_DIR}/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PARTinitrd ${INSTALL_BOOT_DIR}/initrd-$KERNEL_VERSION.imgEOFfiif [ $SMP_installed ]; thenecho "Add entry for SMP kernel into grub.conf"cat >> $NEW/boot/grub/grub.conf <<EOFtitle $TITLE (${KERNEL_VERSION}smp)root $GRUB_ROOT_PARTkernel ${INSTALL_BOOT_DIR}/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PARTinitrd ${INSTALL_BOOT_DIR}/initrd-${KERNEL_VERSION}smp.imgEOFfiif [ $WIN_installed ]; thenecho "Add entry for Windows into grub.conf"cat >> $NEW/boot/grub/grub.conf <<EOFtitle Windowsrootnoverify $GRUB_WIN_PARTchainloader +1EOFfichmod 600 $NEW/boot/grub/grub.confln -s ../boot/grub/grub.conf $NEW/etc/grub.confln -s ./grub.conf $NEW/boot/grub/menu.lstecho "done."; echo### create /etc/sysconfig/grub file### -----------------------------------------------------------cat > $NEW/etc/sysconfig/grub <<EOFboot=$INSTALL_DEVforcelba=0EOFfi### install kernel and other files into /boot### -----------------------------------------------------------echo "Install kernel(s) ..."[ -e /boot/vmlinuz ] && BOOT_DIR=/boot[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/bootif [ ! $BOOT_DIR ]; thenecho "ERROR: No kernel found - installation failed"; echoexit_now 1ficp -a $BOOT_DIR/vmlinuz $NEW/boot/vmlinuz-${KERNEL_VERSION}cp -a $BOOT_DIR/vmlinuzs $NEW/boot/vmlinuz-${KERNEL_VERSION}smp 2>/dev/nullcp -a $BOOT_DIR/System.map-* $NEW/boot/cp -a $BOOT_DIR/config-* $NEW/boot/cp -a $BOOT_DIR/symvers-*.gz $NEW/boot/ 2>/dev/nullcp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/ 2>/dev/nullcp -a $BOOT_DIR/message.ja $NEW/boot/ 2>/dev/nullcp -a $BOOT_DIR/message $NEW/boot/ 2>/dev/nullecho "done."; echo### create /etc/sysconfig/kernel file### -----------------------------------------------------------cat > $NEW/etc/sysconfig/kernel <<EOF# UPDATEDEFAULT specifies if new-kernel-pkg should make# new kernels the defaultUPDATEDEFAULT=yes# DEFAULTKERNEL specifies the default kernel package typeDEFAULTKERNEL=kernelEOF### create /etc/fstab### -----------------------------------------------------------cat > $NEW/etc/fstab <<EOF$INSTALL_PART / $FS_TYPE defaults 1 1EOFif [ -z "$INSTALL_BOOT_DIR" ]; thenecho "$INSTALL_DEV /boot $FS_TYPE defaults 1 2" >> $NEW/etc/fstabficat >> $NEW/etc/fstab <<EOFdevpts /dev/pts devpts gid=5,mode=620 0 0tmpfs /dev/shm tmpfs defaults 0 0proc /proc proc defaults 0 0sysfs /sys sysfs defaults 0 0EOFif [ "$SWAP_PART" ]; thenfor SWAP_PARTITION in $SWAP_PART ; doecho "$SWAP_PARTITION swap swap defaults,pri=1 0 0" >> $NEW/etc/fstabdonefi### make initrd### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)### -----------------------------------------------------------echo "Create initrd(s) ..."# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrdif [ $UP_installed ]; thendepmod -a ${KERNEL_VERSION}/usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \$NEW/boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; thenecho "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"exit_now 1fifiif [ $SMP_installed ]; thendepmod -a ${KERNEL_VERSION}smp/usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \$NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smpif [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; thenecho "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"exit_now 1fifiecho "done."; echo### remove LiveCD init.d scripts### -----------------------------------------------------------for file in $LIVECD_INIT_SCRIPTS; dorm -f $NEW/etc/rc.d/init.d/$filefor n in 0 1 2 3 4 5 6; dorm -f $NEW/etc/rc.d/rc${n}.d/*$filedonedone### restore cronjobs### -----------------------------------------------------------mv $NEW/etc/cron_backup/sysstat $NEW/etc/cron.d/ 2>/dev/nullmv $NEW/etc/cron_backup/cfengine $NEW/etc/cron.d/ 2>/dev/nullmv $NEW/etc/cron_backup/psi-cronjobs $NEW/etc/cron.d/ 2>/dev/nullmv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/nullmv $NEW/etc/cron_backup/* $NEW/etc/cron.daily/ 2>/dev/null### prepare chroot to $NEW### -----------------------------------------------------------mount --bind /dev $NEW/devmount --bind /sys $NEW/sysmount -t proc proc $NEW/proc### turn on kudzu again### -----------------------------------------------------------chroot $NEW chkconfig kudzu on### turn on check_update again (only at PSI)### -----------------------------------------------------------chroot $NEW chkconfig check_update on 2>/dev/null### fix some services which were disabled### because of diskless NFS client### -----------------------------------------------------------if [ -e /$MOUNTDIR/service.on ]; thencat /$MOUNTDIR/service.on | while read $serv; dochroot $NEW chkconfig $serv ondonefi### remove some files### -----------------------------------------------------------rm -rf $NEW/usr/share/applications/livecd-install-gui.desktoprm -rf $NEW/usr/share/applications/save-localdata.desktop### remove RPMs that can break future updates### -----------------------------------------------------------if [ ! $NORPMREMOVE ]; thenecho "Remove RPMs that may break future updates ..."chroot $NEW rpm -qa 2>/dev/null > /tmp/rpmlist# Scientific Linux RPMsRPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_SL"# PSI Scientific Linux RPMsif [ -e /etc/sysconfig/psi ]; thenRPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_PSI"fifor rpm in $RPMSTOREMOVE; dorpms_remove=$( cat /tmp/rpmlist | grep "^$rpm" )for rpm_remove in $rpms_remove; dochroot $NEW rpm -e --nodeps $rpm_remove >/dev/null 2>&1[ "$?" = "0" ] && echo " removing $rpm_remove"donedoneecho "done."; echofi### disable nvidia driver### -----------------------------------------------------------# not in case of a PSI installationif [ ! -e /etc/sysconfig/psi ]; thenif [ -e $NEW/etc/X11/xorg.conf.nv_SAVED ]; thenecho "Remove nvidia driver and correct xorg.conf ..."# correct xorg.confsed -i "s/#nv_SAVED //" $NEW/etc/X11/xorg.confsed -i "/.*Driver.*nvidia.*/d" $NEW/etc/X11/xorg.conf# disable nvidia libs (if not yet done by rpm -e)LIB=lib[ $( arch ) = "x86_64" ] && LIB=lib64mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia \$NEW/usr/X11R6/$LIB/modules/extensions/libGLcore.a 2>/dev/nullmv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia \$NEW/usr/X11R6/$LIB/modules/extensions/libglx.a 2>/dev/nullrm -f $NEW/usr/X11R6/$LIB/modules/extensions/libglx.sorm -f $NEW/usr/X11R6/$LIB/libGL.so*rm -f $NEW/usr/$LIB/libGLcore.soecho "done."; echofifi### umount /dev /sys /proc from chroot### -----------------------------------------------------------umount $NEW/devumount $NEW/sysumount $NEW/proc### install grub for the 2. time, if it failed before### (happens on xfs filesystem), to be sure run it twice.### -----------------------------------------------------------if [ ! $NOGRUB ] && [ $GRUB_FAILED ]; thenecho "Run grub-install once more ... "[ ! $FLOPPY ] && NO_FLOPPY_OPT="--no-floppy"# 1. run grub-install, before re-mount partition (quite)[ $MOUNTED = "0" ] && umount $NEW && mount $INSTALL_PART $NEWgrub-install $NO_FLOPPY_OPT --root-directory=$NEW $MBR_DEV >/dev/null 2>&1# 2. run grub-install, before re-mount partition (verbose)[ $MOUNTED = "0" ] && umount $NEW && mount $INSTALL_PART $NEWgrub-install $NO_FLOPPY_OPT --root-directory=$NEW $MBR_DEVif [ "$?" != "0" ]; thenecho "grub-install failed again."echo "You can try to run grub-install manually as root with:"echoecho " mount $INSTALL_PART $NEW"echo " grub-install $NO_FLOPPY_OPT --root-directory=$NEW $MBR_DEV"echoexit_now 1fiecho "done."; echofi### umount $INSTALL_PART### -----------------------------------------------------------UMOUNT_LIST=`df -l | grep "$NEW" | sed -e 's/ */ /g' | cut -d" " -f6 | sort -r`umount $UMOUNT_LIST### print summary### -----------------------------------------------------------echo "--------------------------------------------------------------"echo " LiveCD installed on partition $INSTALL_PART"[ "$SWAP_PART" ] && echo " Partition(s) $SWAP_PART will be used as swap partition(s)"echo[ ! $NOGRUB ] && echo " GRUB installed in Master Boot Record (MBR) of $MBR_DEV"[ ! $NOGRUB ] && echo " MBR saved as $MBR_FILENAME on $INSTALL_PART and in /tmp"[ ! $NOGRUB ] && echo " If you have to restore MBR, execute under Linux:"[ ! $NOGRUB ] && echo " # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"echo[ $WIN_PART ] && echo " Entry created in grub.conf for Windows partition $WIN_PART"echo "--------------------------------------------------------------"echo "End of $SCRIPTNAME"echo### print (warn) message when using xfs and kernel has xfs.ko not included###rpm -ql kernel 2>/dev/null | grep -q \/xfs.koif [ "$?" != "0" ]; thenif [ "$FS_TYPE" = "xfs" ]; thenecho "--------------------------------------------------------------"echo "IMPORTANT NOTE:"echoecho "Formating the root file system with xfs can causes problems"echo "after a regular kernel update."echo "Please run the following command after each kernel update"echo "in order to correctly build the initial ram disk:"echoecho "# new-kernel-pkg --package kernel --mkinitrd --depmod \\"echo " --install 2.6.18-128.1.14.el5"echoecho "(replace 2.6.18-128.1.14.el5 with the version number of the"echo "updated kernel)"echo "--------------------------------------------------------------"echofifi