Subversion Repositories livecd

Rev

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