Subversion Repositories livecd

Rev

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

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