Subversion Repositories livecd

Rev

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

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