Subversion Repositories livecd

Rev

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