Subversion Repositories livecd

Rev

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