Subversion Repositories livecd

Rev

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