Subversion Repositories livecd

Rev

Details | Last modification | View Log | RSS feed

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