Subversion Repositories livecd

Rev

Rev 28 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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