Subversion Repositories livecd

Rev

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

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