Subversion Repositories livecd

Rev

Rev 145 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15 beyerle@PS 1
#!/bin/bash
2
#
3
###############################################################
4
#
63 beyerle@PS 5
# Installes the LiveCD on local hard disk
15 beyerle@PS 6
# 
7
# Boot LiveCD and run this script as root
8
#
169 beyerle@PS 9
# Urs Beyerle
15 beyerle@PS 10
#
11
###############################################################
12
 
13
 
14
###############################################################
15
# Definitions
16
###############################################################
17
 
32 beyerle@PS 18
# set PATH
19
PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin"
20
 
145 beyerle@PS 21
# RPMs that are no longer needed and may break future udpates
29 beyerle@PS 22
RPMS_TO_REMOVE="kernel-module-squashfs \
23
                kernel-module-unionfs \
45 beyerle@PS 24
                kernel-module-aufs \
25
                unionfs-.* \
26
                aufs-.* \
27
                squashfs-.*"
29 beyerle@PS 28
 
30 beyerle@PS 29
# RPMs that can break future Scientific Linux updates
29 beyerle@PS 30
# because there are not part of Scientific Linux
145 beyerle@PS 31
RPMS_TO_REMOVE_SL=""
29 beyerle@PS 32
 
30 beyerle@PS 33
# RPMs that can break future PSI SL updates
29 beyerle@PS 34
# because there are not part of PSI Scientific Linux
35
RPMS_TO_REMOVE_PSI=""
36
 
15 beyerle@PS 37
# files which should be restored from .ori files
38
FILES_RESTORE="/etc/init.d/netfs \
39
           /etc/init.d/autofs \
40
           /etc/init.d/halt \
41
           /etc/init.d/network
42
           /etc/init.d/functions \
43
           /etc/rc.d/rc.sysinit \
44
           /etc/sysconfig/afs \
45
           /etc/motd \
46
           /etc/redhat-release \
29 beyerle@PS 47
	   /etc/rc.d/rc.local"
15 beyerle@PS 48
 
33 beyerle@PS 49
# LiveCD init scripts will be removed
16 beyerle@PS 50
LIVECD_INIT_SCRIPTS="runfirst \
51
                    runveryfirst \
52
                    runlast \
33 beyerle@PS 53
                    kudzu-auto \
54
                    login"
15 beyerle@PS 55
 
56
# Main directories which should be not be copied
16 beyerle@PS 57
DIR_NOT_COPY="/proc \
58
              /dev \
59
              /livecd \
60
              /boot \
61
              /afs \
62
              /sys \
139 beyerle@PS 63
              /media \
64
              /misc \
16 beyerle@PS 65
              /mnt \
139 beyerle@PS 66
              /net \
36 beyerle@PS 67
              /initrd"
15 beyerle@PS 68
 
69
# Mount point of the new SL system
70
NEW=/mnt/harddisk
71
 
21 beyerle@PS 72
# Name of the script
15 beyerle@PS 73
SCRIPTNAME=$( basename $0 )
74
 
137 beyerle@PS 75
# dir of mounted /$MOUNTDIR/live
76
MOUNTDIR=livecd
16 beyerle@PS 77
 
78
 
21 beyerle@PS 79
 
15 beyerle@PS 80
###############################################################
81
# Functions
82
###############################################################
83
 
84
function usage() {
85
 
86
   ## Usage
87
   # ----------------------------------------------------------
88
 
89
   cat <<EOF
21 beyerle@PS 90
 
22 beyerle@PS 91
  $SCRIPTNAME [OPTIONS] -mbr=[DEVICE] [PARTITION]
15 beyerle@PS 92
 
26 beyerle@PS 93
    Installes LiveCD on PARTITION and the bootloader grub into 
94
    the Master Boot Record (MBR) of DEVICE. The MBR will be 
95
    backed up to PARTITION.
15 beyerle@PS 96
 
21 beyerle@PS 97
  OPTIONS:
15 beyerle@PS 98
 
34 beyerle@PS 99
    -h   --help       : Print this screen
100
    -swap=[partition] : Use [partition] as swap
101
    -win=[partition]  : Your active Windows partition. If not given, 
22 beyerle@PS 102
                        $SCRIPTNAME tries to find it
34 beyerle@PS 103
    -nogrub           : Do not install grub. You have to install 
26 beyerle@PS 104
                        manually a bootloader (not recommended)
34 beyerle@PS 105
    -floppy           : Needed, if grub should be installed on floppy
31 beyerle@PS 106
                        In this case use -mbr=/dev/fd0 -floppy
34 beyerle@PS 107
    -norpmremove      : Do not remove RPMs that can break future 
108
                        updates (not recommended)
109
    -y                : Answer all questions with yes
15 beyerle@PS 110
 
21 beyerle@PS 111
  Example:
112
 
22 beyerle@PS 113
  $SCRIPTNAME -swap=/dev/sda3 -mbr=/dev/sda /dev/sda2
21 beyerle@PS 114
 
115
    Will install LiveCD on /dev/sda2 (= second partition on 
116
    first SATA disk). All data on /dev/sda2 will be deleted.
117
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
118
    installed in the MBR of /dev/sda (= first SATA disk).
119
 
31 beyerle@PS 120
  Remarks:
121
 
122
    To display your hard disk partitions, user 'fdisk -l'.
123
    Use fdisk, qtparted or parted to create an empty Linux
124
    partition.
125
 
15 beyerle@PS 126
EOF
127
}
128
 
129
 
21 beyerle@PS 130
function exit_now() {
131
 
132
    local exitcode=$1
133
    umount $INSTALL_PART 2>/dev/null
134
    exit $exitcode
135
}
136
 
137
 
138
 
15 beyerle@PS 139
###############################################################
140
# Main
141
###############################################################
142
 
16 beyerle@PS 143
### are we root?
144
### -----------------------------------------------------------
15 beyerle@PS 145
if [ "$( whoami )" != "root" ]; then
31 beyerle@PS 146
    echo; echo "Please run this script as root: 'su - -c $SCRIPTNAME'"; echo
21 beyerle@PS 147
    exit_now 1
15 beyerle@PS 148
fi
149
 
16 beyerle@PS 150
 
15 beyerle@PS 151
### read options from command-line
16 beyerle@PS 152
### -----------------------------------------------------------
15 beyerle@PS 153
while [ $# -gt 0 ]; do
154
 
155
    case "$1" in
156
       -h)
21 beyerle@PS 157
            usage; exit_now;;
22 beyerle@PS 158
 
21 beyerle@PS 159
       --help)
160
            usage; exit_now;;
22 beyerle@PS 161
 
24 beyerle@PS 162
       -swap*)
22 beyerle@PS 163
           if echo $1 | grep -q '=' ; then
164
	       SWAP_PART=$( echo $1 | sed 's/^-swap=//' )
165
	   else
166
	       shift
24 beyerle@PS 167
               SWAP_PART=$1
22 beyerle@PS 168
	   fi
34 beyerle@PS 169
	   ;;
22 beyerle@PS 170
 
24 beyerle@PS 171
       -mbr*)
22 beyerle@PS 172
           if echo $1 | grep -q '=' ; then
173
	       MBR_DEV=$( echo $1 | sed 's/^-mbr=//' )
174
	   else
175
	       shift
24 beyerle@PS 176
               MBR_DEV=$1
22 beyerle@PS 177
	   fi
34 beyerle@PS 178
	   ;;
22 beyerle@PS 179
 
24 beyerle@PS 180
       -win*)
22 beyerle@PS 181
           if echo $1 | grep -q '=' ; then
182
	       WIN_PART=$( echo $1 | sed 's/^-win=//' )
183
	   else
184
	       shift
24 beyerle@PS 185
               WIN_PART=$1
22 beyerle@PS 186
	   fi
34 beyerle@PS 187
	   ;;
22 beyerle@PS 188
 
16 beyerle@PS 189
       -nogrub)
34 beyerle@PS 190
            NOGRUB=$1;;
22 beyerle@PS 191
 
29 beyerle@PS 192
       -norpmremove)
34 beyerle@PS 193
            NORPMREMOVE=$1;;
29 beyerle@PS 194
 
18 beyerle@PS 195
       -floppy)
34 beyerle@PS 196
            FLOPPY=$1;;
22 beyerle@PS 197
 
15 beyerle@PS 198
       -y)
34 beyerle@PS 199
            YES=$1;;
15 beyerle@PS 200
 
201
       *)
34 beyerle@PS 202
            INSTALL_PART=$1;;
15 beyerle@PS 203
    esac
204
 
34 beyerle@PS 205
    shift
206
 
15 beyerle@PS 207
done
208
echo
209
 
16 beyerle@PS 210
 
28 beyerle@PS 211
### display fdisk -l
212
### -----------------------------------------------------------
213
echo "Output of 'fdisk -l' ..."
214
fdisk -l
215
echo
216
 
217
 
30 beyerle@PS 218
### test if $INSTALL_PART is defined
22 beyerle@PS 219
### -----------------------------------------------------------
220
if [ ! $INSTALL_PART ]; then
49 beyerle@PS 221
    echo "No partition defined for installation."
222
    echo "Please see '$SCRIPTNAME -h'."; echo
22 beyerle@PS 223
    exit_now 1
224
fi
225
 
226
 
15 beyerle@PS 227
### test if MBR_DEV is given
16 beyerle@PS 228
### -----------------------------------------------------------
229
if [ ! $NOGRUB ]; then
230
    if [ ! $MBR_DEV ]; then
18 beyerle@PS 231
	echo "No MBR device defined."
49 beyerle@PS 232
	echo "Please see '$SCRIPTNAME -h'."
233
	echo
21 beyerle@PS 234
	exit_now 1
16 beyerle@PS 235
    fi
15 beyerle@PS 236
fi
237
 
16 beyerle@PS 238
 
15 beyerle@PS 239
### test if $INSTALL_PART exists
16 beyerle@PS 240
### -----------------------------------------------------------
15 beyerle@PS 241
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
242
if [ "$?" != "0" ]; then
49 beyerle@PS 243
    echo "Partition $INSTALL_PART not found! See 'fdisk -l'."
244
    echo "Or you have to reboot first to make the partition table active." 
245
    echo
21 beyerle@PS 246
    exit_now 1
15 beyerle@PS 247
fi
248
 
16 beyerle@PS 249
 
30 beyerle@PS 250
### test if $INSTALL_PART is a Linux partition
16 beyerle@PS 251
### -----------------------------------------------------------
30 beyerle@PS 252
fdisk -l | grep "Linux$" | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
253
if [ "$?" != "0" ]; then
49 beyerle@PS 254
    echo "Partition $INSTALL_PART is not a Linux partition! (see 'fdisk -l')."
30 beyerle@PS 255
    echo "Use fdisk and/or qtparted to create a Linux partition!"
49 beyerle@PS 256
    echo "You have to reboot first to make the partition table active."
257
    echo
30 beyerle@PS 258
    exit_now 1
259
fi
15 beyerle@PS 260
 
261
 
30 beyerle@PS 262
### test if $SWAP_PART exists and is a Linux Swap partition
16 beyerle@PS 263
### -----------------------------------------------------------
15 beyerle@PS 264
if [ $SWAP_PART ]; then
265
    fdisk -l | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
266
    if [ "$?" != "0" ]; then
49 beyerle@PS 267
	echo "Swap partition $SWAP_PART not found! (see 'fdisk -l')."
268
	echo "Or you have to reboot first to make the partition table active."
269
	echo
21 beyerle@PS 270
	exit_now 1
15 beyerle@PS 271
    fi
44 beyerle@PS 272
    fdisk -l | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
15 beyerle@PS 273
    if [ "$?" != "0" ]; then
49 beyerle@PS 274
	echo "Partition $SWAP_PART is not a Linux swap partition! (see 'fdisk -l')."
275
	echo "Use fdisk and/or qtparted to create a Linux Swap partition !"
276
	echo "You have to reboot first to make the partition table active."
277
	echo
21 beyerle@PS 278
	exit_now 1
15 beyerle@PS 279
    fi
280
fi
281
 
282
 
30 beyerle@PS 283
### set $INSTALL_DEV (eg. /dev/sda)
16 beyerle@PS 284
### -----------------------------------------------------------
30 beyerle@PS 285
INSTALL_DEV=$( echo "$INSTALL_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
286
INSTALL_PART_NR=$( echo "$INSTALL_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
287
 
288
 
289
### print warning
290
### -----------------------------------------------------------
26 beyerle@PS 291
echo                     "------------------------------------------------------------"
292
echo                     "   LiveCD will be installed on partition $INSTALL_PART"
15 beyerle@PS 293
[ "$SWAP_PART" ] && echo " Partition $SWAP_PART will be used as swap partition."
26 beyerle@PS 294
[ ! $NOGRUB ]    && echo " GRUB will be installed in Master Boot Record of $MBR_DEV"
295
echo                     "       !! All data on $INSTALL_PART will be lost !!"
296
echo                     "------------------------------------------------------------"
15 beyerle@PS 297
echo
16 beyerle@PS 298
 
15 beyerle@PS 299
 
26 beyerle@PS 300
### continue?
16 beyerle@PS 301
### -----------------------------------------------------------
15 beyerle@PS 302
if [ ! $YES ]; then
303
    echo -n "Continue (y/N)? "
18 beyerle@PS 304
    read key
15 beyerle@PS 305
    echo
21 beyerle@PS 306
    [ "$key" != "y" ] && exit_now 0
15 beyerle@PS 307
fi
308
 
309
 
108 beyerle@PS 310
### format $SWAP_PART (don't format swap, if already formated)
21 beyerle@PS 311
### -----------------------------------------------------------
26 beyerle@PS 312
if [ $SWAP_PART ]; then
313
    echo "Make swap on $SWAP_PART ..."
108 beyerle@PS 314
    swapoff -a >/dev/null 2>&1
315
    swapon $SWAP_PART 2>/dev/null
316
    if [ "$?" != "0" ]; then
317
	echo "Format $SWAP_PART as swap." 
318
	mkswap $SWAP_PART
319
    fi
24 beyerle@PS 320
    echo
321
fi
21 beyerle@PS 322
 
323
 
15 beyerle@PS 324
### format $INSTALL_PART
16 beyerle@PS 325
### -----------------------------------------------------------
15 beyerle@PS 326
echo -n "Format $INSTALL_PART, please wait ... " 
21 beyerle@PS 327
mkfs.ext3 -q $INSTALL_PART || exit_now 1
15 beyerle@PS 328
echo "done."; echo
329
 
330
 
331
### mount $INSTALL_PART
16 beyerle@PS 332
### -----------------------------------------------------------
15 beyerle@PS 333
echo -n "Try to mount $INSTALL_PART to $NEW ... "
334
mkdir -p $NEW
21 beyerle@PS 335
mount $INSTALL_PART $NEW || exit_now 1
15 beyerle@PS 336
echo "done."; echo
337
 
338
 
339
### copy root dirs
16 beyerle@PS 340
### -----------------------------------------------------------
26 beyerle@PS 341
echo "Copy Live System to $INSTALL_PART ..."
15 beyerle@PS 342
root_dirs=$( ls / )
343
for dir in $root_dirs; do
344
    # check if dir is not in $DIR_NOT_COPY
345
    do_not_copy=""
346
    for not_dir in $DIR_NOT_COPY; do
347
	if [ "$not_dir" = "/$dir" ]; then 
348
	    do_not_copy="yes"
349
	    break
350
	fi
351
    done
352
    # do not copy links
353
    [ -L /$dir ] && do_not_copy="yes"
354
 
21 beyerle@PS 355
    fail=""
15 beyerle@PS 356
    if [ ! $do_not_copy ]; then
357
	echo -n "  * Copy  /$dir ... "
21 beyerle@PS 358
	cp -a /$dir $NEW || fail=true
15 beyerle@PS 359
	echo "done."
360
    fi
361
done
362
echo
21 beyerle@PS 363
if [ $fail ]; then
364
    echo "ERROR: Not everything was copied to $INSTALL_PART"
365
    exit_now 1
366
fi
15 beyerle@PS 367
 
368
 
16 beyerle@PS 369
### move /usr/opt back to /opt
370
### -----------------------------------------------------------
15 beyerle@PS 371
if [ -d $NEW/usr/opt ]; then
372
    echo -n "Move /opt back ... "
373
    mv $NEW/usr/opt $NEW/
374
    echo "done."; echo
375
fi
376
 
377
 
378
### create dirs which were not copied
16 beyerle@PS 379
### -----------------------------------------------------------
15 beyerle@PS 380
for dir in $DIR_NOT_COPY; do
381
    mkdir $NEW/$dir
382
done
26 beyerle@PS 383
# we do not need this directories
384
rmdir $NEW/livecd
385
# if not yet existing, create
386
mkdir -p $NEW/srv
387
mkdir -p $NEW/selinux
15 beyerle@PS 388
 
389
 
390
### copy back original files
16 beyerle@PS 391
### -----------------------------------------------------------
15 beyerle@PS 392
echo -n "Restore original files ... " 
393
for file in $FILES_RESTORE; do
28 beyerle@PS 394
    [ -r $NEW/${file}.ori ] && mv -f $NEW/${file}.ori $NEW/${file} 
15 beyerle@PS 395
done
396
echo "done."; echo
397
 
398
 
16 beyerle@PS 399
### define kernel version
400
### -----------------------------------------------------------
401
rpm --quiet -q kernel     && UP_installed=true
402
rpm --quiet -q kernel-smp && SMP_installed=true
403
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
404
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
405
if [ ! $KERNEL_VERSION ]; then
406
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
21 beyerle@PS 407
    exit_now 1
16 beyerle@PS 408
fi    
15 beyerle@PS 409
 
18 beyerle@PS 410
 
22 beyerle@PS 411
 
24 beyerle@PS 412
if [ ! $NOGRUB ]; then
15 beyerle@PS 413
 
26 beyerle@PS 414
    ### Backup Master Boot Record MBR
415
    ### -----------------------------------------------------------
416
    if [ ! $NOGRUB ]; then
417
	# do we have already a backup?
418
	MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"
419
	if [ ! -e /tmp/$MBR_FILENAME ]; then
420
	    echo "Backup Master Boot Record (MBR) of $MBR_DEV ..."
421
	    dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1
422
	fi
423
	cp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAME
424
	echo "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
425
	echo
426
    fi
427
 
428
 
24 beyerle@PS 429
    ### install grub
430
    ### -----------------------------------------------------------
26 beyerle@PS 431
    echo "Run grub-install ... "
24 beyerle@PS 432
    mkdir -p $NEW/boot/grub
433
    if [ $FLOPPY ]; then
434
	grub-install --root-directory=$NEW $MBR_DEV
435
    else
436
	grub-install --no-floppy --root-directory=$NEW $MBR_DEV
437
    fi
438
    echo "done."; echo
15 beyerle@PS 439
 
440
 
24 beyerle@PS 441
    ### check for device.map file 
442
    ### -----------------------------------------------------------
443
    DEVICE_MAP=$NEW/boot/grub/device.map
444
    if [ ! -e $NEW/boot/grub/device.map ]; then
445
	echo "ERROR: $NEW/boot/grub/device.map not found"
446
	exit_now 1
447
    fi
15 beyerle@PS 448
 
22 beyerle@PS 449
 
24 beyerle@PS 450
    ### convert dev syntax to grub syntax
451
    ### -----------------------------------------------------------
452
    GRUB_INSTALL_DEV=$( grep $INSTALL_DEV $DEVICE_MAP | awk '{ print $1 }' )
453
    GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
22 beyerle@PS 454
 
15 beyerle@PS 455
 
24 beyerle@PS 456
    ### find active Windows partition
457
    ### -----------------------------------------------------------
458
    if [ ! $WIN_PART ]; then
459
        # try to find active Windows partition
460
	WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
461
    fi
462
 
463
    if [ $WIN_PART ]; then
464
	WIN_installed=true
465
	WIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
466
	WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
467
        # convert dev syntax to grub syntax
468
	GRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )
469
	GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )
470
 
471
        # $GRUB_WIN_PART should be something like (hd0,0)
472
	echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
473
	echo "Will add entry for Windows in GRUB."
474
	echo
475
    fi
476
 
477
 
478
    ### create grub.conf file
479
    ### -----------------------------------------------------------
26 beyerle@PS 480
    echo "Create grub.conf ..."
24 beyerle@PS 481
 
28 beyerle@PS 482
    TITLE="Linux"
91 beyerle@PS 483
    [ -e $NEW/etc/redhat-release ] && TITLE=$( cat $NEW/etc/redhat-release )
28 beyerle@PS 484
 
50 beyerle@PS 485
    DEFAULT=0
486
    # set default=1, if smp kernel is running
487
    uname -r | grep -q smp
488
    [ "$?" = "0" ] && DEFAULT=1
489
 
24 beyerle@PS 490
    cat > $NEW/boot/grub/grub.conf <<EOF
15 beyerle@PS 491
# grub.conf generated by $SCRIPTNAME
50 beyerle@PS 492
default=$DEFAULT
15 beyerle@PS 493
timeout=5
494
splashimage=$GRUB_ROOT_PART/boot/grub/splash.xpm.gz
495
#hiddenmenu
16 beyerle@PS 496
EOF
497
 
24 beyerle@PS 498
    if [ $UP_installed ]; then
26 beyerle@PS 499
	echo "Add entry for UP kernel into grub.conf"
24 beyerle@PS 500
	cat >> $NEW/boot/grub/grub.conf <<EOF
28 beyerle@PS 501
title $TITLE (${KERNEL_VERSION})
15 beyerle@PS 502
        root $GRUB_ROOT_PART
503
	kernel /boot/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PART
504
	initrd /boot/initrd-$KERNEL_VERSION.img
16 beyerle@PS 505
EOF
24 beyerle@PS 506
    fi
16 beyerle@PS 507
 
24 beyerle@PS 508
    if [ $SMP_installed ]; then
26 beyerle@PS 509
	echo "Add entry for SMP kernel into grub.conf"
24 beyerle@PS 510
	cat >> $NEW/boot/grub/grub.conf <<EOF
28 beyerle@PS 511
title $TITLE (${KERNEL_VERSION}smp)
16 beyerle@PS 512
        root $GRUB_ROOT_PART
513
	kernel /boot/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PART
514
	initrd /boot/initrd-${KERNEL_VERSION}smp.img
515
EOF
24 beyerle@PS 516
    fi
16 beyerle@PS 517
 
24 beyerle@PS 518
    if [ $WIN_installed ]; then
26 beyerle@PS 519
	echo "Add entry for Windows into grub.conf"
24 beyerle@PS 520
	cat >> $NEW/boot/grub/grub.conf <<EOF
15 beyerle@PS 521
title Windows
522
        rootnoverify $GRUB_WIN_PART
523
        chainloader +1
524
EOF
24 beyerle@PS 525
    fi
526
 
527
    chmod 600 $NEW/boot/grub/grub.conf
528
    ln -s ../boot/grub/grub.conf $NEW/etc/grub.conf
529
    ln -s ./grub.conf $NEW/boot/grub/menu.lst
530
    echo "done."; echo
531
 
63 beyerle@PS 532
 
533
    ### create /etc/sysconfig/grub file
534
    ### -----------------------------------------------------------
535
    cat > $NEW/etc/sysconfig/grub <<EOF    
536
boot=$MBR_DEV
537
forcelba=0
538
EOF
539
 
540
 
16 beyerle@PS 541
fi
15 beyerle@PS 542
 
543
 
27 beyerle@PS 544
### install kernel and other files into /boot
16 beyerle@PS 545
### -----------------------------------------------------------
21 beyerle@PS 546
echo "Install kernel(s) ..."
15 beyerle@PS 547
 
16 beyerle@PS 548
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
549
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
15 beyerle@PS 550
 
16 beyerle@PS 551
if [ ! $BOOT_DIR ]; then
552
    echo "ERROR: No kernel found - installation failed"; echo
21 beyerle@PS 553
    exit_now 1
16 beyerle@PS 554
fi
555
 
556
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
557
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
558
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
559
cp -a $BOOT_DIR/config-*           $NEW/boot/
26 beyerle@PS 560
cp -a $BOOT_DIR/symvers-*.gz       $NEW/boot/        2>/dev/null
91 beyerle@PS 561
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/   2>/dev/null
26 beyerle@PS 562
cp -a $BOOT_DIR/message.ja         $NEW/boot/        2>/dev/null
563
cp -a $BOOT_DIR/message            $NEW/boot/        2>/dev/null
564
 
16 beyerle@PS 565
echo "done."; echo
566
 
567
 
63 beyerle@PS 568
### create /etc/sysconfig/kernel file
569
### -----------------------------------------------------------
570
cat > $NEW/etc/sysconfig/kernel <<EOF    
571
# UPDATEDEFAULT specifies if new-kernel-pkg should make
572
# new kernels the default
573
UPDATEDEFAULT=yes
574
 
575
# DEFAULTKERNEL specifies the default kernel package type
576
DEFAULTKERNEL=kernel
577
EOF
578
 
579
 
21 beyerle@PS 580
### create /etc/fstab
16 beyerle@PS 581
### -----------------------------------------------------------
21 beyerle@PS 582
cat > $NEW/etc/fstab <<EOF
583
$INSTALL_PART         /                    ext3    defaults        1 1
584
devpts            /dev/pts             devpts  gid=5,mode=620  0 0
585
tmpfs             /dev/shm             tmpfs   defaults        0 0
586
proc              /proc                proc    defaults        0 0
587
sysfs             /sys                 sysfs   defaults        0 0
588
EOF
589
if [ $SWAP_PART ]; then
590
    echo "$SWAP_PART         swap                 swap    defaults        0 0" >> $NEW/etc/fstab
591
fi
592
 
593
 
594
### make initrd 
595
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
596
### -----------------------------------------------------------
597
echo "Create initrd(s) ..."
22 beyerle@PS 598
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
599
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
600
 
16 beyerle@PS 601
if [ $UP_installed ]; then
21 beyerle@PS 602
    depmod -a ${KERNEL_VERSION}
22 beyerle@PS 603
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
21 beyerle@PS 604
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
18 beyerle@PS 605
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
606
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
21 beyerle@PS 607
	exit_now 1
18 beyerle@PS 608
    fi
16 beyerle@PS 609
fi
610
if [ $SMP_installed ]; then
21 beyerle@PS 611
    depmod -a ${KERNEL_VERSION}smp
22 beyerle@PS 612
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
21 beyerle@PS 613
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
18 beyerle@PS 614
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
615
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
21 beyerle@PS 616
	exit_now 1
18 beyerle@PS 617
    fi
16 beyerle@PS 618
fi
619
echo "done."; echo
620
 
621
 
15 beyerle@PS 622
### remove LiveCD init.d scripts
16 beyerle@PS 623
### -----------------------------------------------------------
624
for file in $LIVECD_INIT_SCRIPTS; do
33 beyerle@PS 625
    rm -f $NEW/etc/rc.d/init.d/$file
16 beyerle@PS 626
    for n in 0 1 2 3 4 5 6; do
627
	rm -f $NEW/etc/rc.d/rc${n}.d/*$file
628
    done
15 beyerle@PS 629
done
630
 
16 beyerle@PS 631
 
632
### restore cronjobs
633
### -----------------------------------------------------------
125 beyerle@PS 634
mv $NEW/etc/cron_backup/sysstat       $NEW/etc/cron.d/ 2>/dev/null
635
mv $NEW/etc/cron_backup/cfengine      $NEW/etc/cron.d/ 2>/dev/null
636
mv $NEW/etc/cron_backup/psi-cronjobs  $NEW/etc/cron.d/ 2>/dev/null
26 beyerle@PS 637
mv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/null
125 beyerle@PS 638
mv $NEW/etc/cron_backup/*             $NEW/etc/cron.daily/ 2>/dev/null
16 beyerle@PS 639
 
640
 
29 beyerle@PS 641
### prepare chroot to $NEW
642
### -----------------------------------------------------------
643
mount --bind /dev $NEW/dev
644
mount --bind /sys $NEW/sys
645
mount -t proc proc $NEW/proc
646
 
647
 
18 beyerle@PS 648
### turn on kudzu again
649
### -----------------------------------------------------------
26 beyerle@PS 650
chroot $NEW chkconfig kudzu on
18 beyerle@PS 651
 
652
 
125 beyerle@PS 653
### turn on check_update again (only at PSI)
654
### -----------------------------------------------------------
655
chroot $NEW chkconfig check_update on 2>/dev/null
656
 
657
 
137 beyerle@PS 658
### fix some services which were disabled 
659
### because of diskless NFS client
660
### -----------------------------------------------------------
661
if [ -e /$MOUNTDIR/service.on ]; then
662
    cat /$MOUNTDIR/service.on | while read $serv; do
663
	chroot $NEW chkconfig $serv on
664
    done
665
fi
666
 
667
 
65 beyerle@PS 668
### remove some files
669
### -----------------------------------------------------------
670
rm -rf $NEW/usr/share/applications/livecd-install-gui.desktop
671
rm -rf $NEW/usr/share/applications/save-localdata.desktop
672
 
673
 
29 beyerle@PS 674
### remove RPMs that can break future updates  
675
### -----------------------------------------------------------
676
if [ ! $NORPMREMOVE ]; then
677
    echo "Remove RPMs that may break future updates ..."
678
    chroot $NEW rpm -qa 2>/dev/null > /tmp/rpmlist
679
 
680
    # Scientific Linux RPMs
681
    RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_SL"
682
 
683
    # PSI Scientific Linux RPMs
138 beyerle@PS 684
    if [ -e /etc/sysconfig/psi ]; then
29 beyerle@PS 685
	RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_PSI"
686
    fi
687
 
688
    for rpm in $RPMSTOREMOVE; do
689
	rpms_remove=$( cat /tmp/rpmlist | grep "^$rpm" )
690
	for rpm_remove in $rpms_remove; do	
47 beyerle@PS 691
	    chroot $NEW rpm -e --nodeps $rpm_remove >/dev/null 2>&1
46 beyerle@PS 692
	    [ "$?" = "0" ] && echo " removing $rpm_remove"
29 beyerle@PS 693
	done
694
    done
695
    echo "done."; echo
696
fi
697
 
698
 
43 beyerle@PS 699
### disable nvidia driver 
700
### -----------------------------------------------------------
701
# not in case of a PSI installation
125 beyerle@PS 702
if [ ! -e /etc/sysconfig/psi ]; then
47 beyerle@PS 703
    if [ -e $NEW/etc/X11/xorg.conf.nv_SAVED ]; then
51 beyerle@PS 704
	echo "Remove nvidia driver and correct xorg.conf ..."
50 beyerle@PS 705
        # correct xorg.conf
706
	sed -i "s/#nv_SAVED //" $NEW/etc/X11/xorg.conf
707
	sed -i "/.*Driver.*nvidia.*/d" $NEW/etc/X11/xorg.conf
708
        # disable nvidia libs (if not yet done by rpm -e)
43 beyerle@PS 709
	LIB=lib
710
	[ $( arch ) = "x86_64" ] && LIB=lib64
47 beyerle@PS 711
	mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia \
49 beyerle@PS 712
              $NEW/usr/X11R6/$LIB/modules/extensions/libGLcore.a 2>/dev/null
47 beyerle@PS 713
	mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia \
49 beyerle@PS 714
              $NEW/usr/X11R6/$LIB/modules/extensions/libglx.a 2>/dev/null
47 beyerle@PS 715
	rm -f $NEW/usr/X11R6/$LIB/modules/extensions/libglx.so
716
	rm -f $NEW/usr/X11R6/$LIB/libGL.so*
717
	rm -f $NEW/usr/$LIB/libGLcore.so
51 beyerle@PS 718
	echo "done."; echo
43 beyerle@PS 719
    fi
720
fi
721
 
722
 
15 beyerle@PS 723
### umount $INSTALL_PART
16 beyerle@PS 724
### -----------------------------------------------------------
29 beyerle@PS 725
umount $NEW/dev
726
umount $NEW/sys
727
umount $NEW/proc
16 beyerle@PS 728
umount $INSTALL_PART
15 beyerle@PS 729
 
22 beyerle@PS 730
 
731
### print summary
732
### -----------------------------------------------------------
26 beyerle@PS 733
echo                     "--------------------------------------------------------------"
734
echo                     "  LiveCD installed on partition $INSTALL_PART"
735
[ "$SWAP_PART" ] && echo "  Partition $SWAP_PART will be used as swap partition"
22 beyerle@PS 736
echo
28 beyerle@PS 737
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record (MBR) of $MBR_DEV"
738
[ ! $NOGRUB ]    && echo "  MBR saved as $MBR_FILENAME on $INSTALL_PART and in /tmp"
26 beyerle@PS 739
[ ! $NOGRUB ]    && echo "  If you have to restore MBR, execute under Linux:"
740
[ ! $NOGRUB ]    && echo "  # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"
741
echo 
742
[ $WIN_PART ]    && echo "  Entry created in grub.conf for Windows partition $WIN_PART"
743
echo                     "--------------------------------------------------------------"
744
echo                     "End of $SCRIPTNAME"
745
echo