Subversion Repositories livecd

Rev

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

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