Subversion Repositories livecd

Rev

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

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