Subversion Repositories livecd

Rev

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