Subversion Repositories livecd

Rev

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

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