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