Subversion Repositories livecd

Rev

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

Rev 27 Rev 28
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
### display fdisk -l
-
 
173
### -----------------------------------------------------------
-
 
174
echo "Output of 'fdisk -l' ..."
-
 
175
fdisk -l
-
 
176
echo
-
 
177
 
-
 
178
 
172
### test if $INSTALL_PART is defined and exists
179
### test if $INSTALL_PART is defined and exists
173
### -----------------------------------------------------------
180
### -----------------------------------------------------------
174
if [ ! $INSTALL_PART ]; then
181
if [ ! $INSTALL_PART ]; then
175
    echo "No partition defined for installation"
182
    echo "No partition defined for installation"
176
    echo "Please see '$SCRIPTNAME -h'."; echo
183
    echo "Please see '$SCRIPTNAME -h'."; echo
177
    exit_now 1
184
    exit_now 1
178
fi
185
fi
179
 
186
 
180
 
187
 
181
### test if MBR_DEV is given
188
### test if MBR_DEV is given
182
### -----------------------------------------------------------
189
### -----------------------------------------------------------
183
if [ ! $NOGRUB ]; then
190
if [ ! $NOGRUB ]; then
184
    if [ ! $MBR_DEV ]; then
191
    if [ ! $MBR_DEV ]; then
185
	echo "No MBR device defined."
192
	echo "No MBR device defined."
186
	echo "Please see '$SCRIPTNAME -h'."; echo
193
	echo "Please see '$SCRIPTNAME -h'."; echo
187
	exit_now 1
194
	exit_now 1
188
    fi
195
    fi
189
fi
196
fi
190
 
197
 
191
 
198
 
192
### test if $INSTALL_PART exists
199
### test if $INSTALL_PART exists
193
### -----------------------------------------------------------
200
### -----------------------------------------------------------
194
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
201
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
195
if [ "$?" != "0" ]; then
202
if [ "$?" != "0" ]; then
196
    echo "Partition $INSTALL_PART not found! (see 'disk -l')"; echo
203
    echo "Partition $INSTALL_PART not found! See 'fdisk -l'"
-
 
204
    echo "or you have to reboot first to make the partition table active"; echo
197
    exit_now 1
205
    exit_now 1
198
fi
206
fi
199
 
207
 
200
 
208
 
201
### set $INSTALL_DEV (eg. /dev/sda)
209
### set $INSTALL_DEV (eg. /dev/sda)
202
### -----------------------------------------------------------
210
### -----------------------------------------------------------
203
INSTALL_DEV=$( echo "$INSTALL_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
211
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%' )
212
INSTALL_PART_NR=$( echo "$INSTALL_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
205
 
213
 
206
 
214
 
207
### test if $SWAP_PART exists
215
### test if $SWAP_PART exists
208
### -----------------------------------------------------------
216
### -----------------------------------------------------------
209
if [ $SWAP_PART ]; then
217
if [ $SWAP_PART ]; then
210
    fdisk -l | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
218
    fdisk -l | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
211
    if [ "$?" != "0" ]; then
219
    if [ "$?" != "0" ]; then
212
	echo "Swap partition $SWAP_PART not found! (see 'disk -l')"; echo
220
	echo "Swap partition $SWAP_PART not found! (see 'fdisk -l')"
-
 
221
	echo "Or you have to reboot first to make the partition table active"; echo
213
	exit_now 1
222
	exit_now 1
214
    fi
223
    fi
215
    fdisk -l | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
224
    fdisk -l | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
216
    if [ "$?" != "0" ]; then
225
    if [ "$?" != "0" ]; then
217
	echo "Partition $SWAP_PART is not a Linux swap partition! (see 'disk -l')"
226
	echo "Partition $SWAP_PART is not a Linux swap partition! (see 'fdisk -l')"
218
	echo "Use fdisk to create a Linux swap partition!"; echo
227
	echo "Use fdisk to create a Linux swap partition!"
-
 
228
	echo "You have to reboot first to make the partition table active"; echo
219
	exit_now 1
229
	exit_now 1
220
    fi
230
    fi
221
fi
231
fi
222
 
232
 
223
 
233
 
224
### print warning
234
 ### print warning
225
### -----------------------------------------------------------
235
### -----------------------------------------------------------
226
echo                     "------------------------------------------------------------"
236
echo                     "------------------------------------------------------------"
227
echo                     "   LiveCD will be installed on partition $INSTALL_PART"
237
echo                     "   LiveCD will be installed on partition $INSTALL_PART"
228
[ "$SWAP_PART" ] && echo " Partition $SWAP_PART will be used as swap partition."
238
[ "$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"
239
[ ! $NOGRUB ]    && echo " GRUB will be installed in Master Boot Record of $MBR_DEV"
230
echo                     "       !! All data on $INSTALL_PART will be lost !!"
240
echo                     "       !! All data on $INSTALL_PART will be lost !!"
231
echo                     "------------------------------------------------------------"
241
echo                     "------------------------------------------------------------"
232
echo
242
echo
233
 
243
 
234
 
244
 
235
### continue?
245
### continue?
236
### -----------------------------------------------------------
246
### -----------------------------------------------------------
237
if [ ! $YES ]; then
247
if [ ! $YES ]; then
238
    echo -n "Continue (y/N)? "
248
    echo -n "Continue (y/N)? "
239
    read key
249
    read key
240
    echo
250
    echo
241
    [ "$key" != "y" ] && exit_now 0
251
    [ "$key" != "y" ] && exit_now 0
242
fi
252
fi
243
 
253
 
244
 
254
 
245
### format $SWAP_PART
255
### format $SWAP_PART
246
### -----------------------------------------------------------
256
### -----------------------------------------------------------
247
if [ $SWAP_PART ]; then
257
if [ $SWAP_PART ]; then
248
    echo "Make swap on $SWAP_PART ..."
258
    echo "Make swap on $SWAP_PART ..."
249
    mkswap $SWAP_PART
259
    mkswap $SWAP_PART
250
    echo
260
    echo
251
fi
261
fi
252
 
262
 
253
 
263
 
254
### format $INSTALL_PART
264
### format $INSTALL_PART
255
### -----------------------------------------------------------
265
### -----------------------------------------------------------
256
echo -n "Format $INSTALL_PART, please wait ... " 
266
echo -n "Format $INSTALL_PART, please wait ... " 
257
mkfs.ext3 -q $INSTALL_PART || exit_now 1
267
mkfs.ext3 -q $INSTALL_PART || exit_now 1
258
echo "done."; echo
268
echo "done."; echo
259
 
269
 
260
 
270
 
261
### mount $INSTALL_PART
271
### mount $INSTALL_PART
262
### -----------------------------------------------------------
272
### -----------------------------------------------------------
263
echo -n "Try to mount $INSTALL_PART to $NEW ... "
273
echo -n "Try to mount $INSTALL_PART to $NEW ... "
264
mkdir -p $NEW
274
mkdir -p $NEW
265
mount $INSTALL_PART $NEW || exit_now 1
275
mount $INSTALL_PART $NEW || exit_now 1
266
echo "done."; echo
276
echo "done."; echo
267
 
277
 
268
 
278
 
269
### copy root dirs
279
### copy root dirs
270
### -----------------------------------------------------------
280
### -----------------------------------------------------------
271
echo "Copy Live System to $INSTALL_PART ..."
281
echo "Copy Live System to $INSTALL_PART ..."
272
root_dirs=$( ls / )
282
root_dirs=$( ls / )
273
for dir in $root_dirs; do
283
for dir in $root_dirs; do
274
    # check if dir is not in $DIR_NOT_COPY
284
    # check if dir is not in $DIR_NOT_COPY
275
    do_not_copy=""
285
    do_not_copy=""
276
    for not_dir in $DIR_NOT_COPY; do
286
    for not_dir in $DIR_NOT_COPY; do
277
	if [ "$not_dir" = "/$dir" ]; then 
287
	if [ "$not_dir" = "/$dir" ]; then 
278
	    do_not_copy="yes"
288
	    do_not_copy="yes"
279
	    break
289
	    break
280
	fi
290
	fi
281
    done
291
    done
282
    # do not copy links
292
    # do not copy links
283
    [ -L /$dir ] && do_not_copy="yes"
293
    [ -L /$dir ] && do_not_copy="yes"
284
 
294
 
285
    fail=""
295
    fail=""
286
    if [ ! $do_not_copy ]; then
296
    if [ ! $do_not_copy ]; then
287
	echo -n "  * Copy  /$dir ... "
297
	echo -n "  * Copy  /$dir ... "
288
	cp -a /$dir $NEW || fail=true
298
	cp -a /$dir $NEW || fail=true
289
	echo "done."
299
	echo "done."
290
    fi
300
    fi
291
done
301
done
292
echo
302
echo
293
if [ $fail ]; then
303
if [ $fail ]; then
294
    echo "ERROR: Not everything was copied to $INSTALL_PART"
304
    echo "ERROR: Not everything was copied to $INSTALL_PART"
295
    exit_now 1
305
    exit_now 1
296
fi
306
fi
297
 
307
 
298
 
308
 
299
### move /usr/opt back to /opt
309
### move /usr/opt back to /opt
300
### -----------------------------------------------------------
310
### -----------------------------------------------------------
301
if [ -d $NEW/usr/opt ]; then
311
if [ -d $NEW/usr/opt ]; then
302
    echo -n "Move /opt back ... "
312
    echo -n "Move /opt back ... "
303
    mv $NEW/usr/opt $NEW/
313
    mv $NEW/usr/opt $NEW/
304
    echo "done."; echo
314
    echo "done."; echo
305
fi
315
fi
306
 
316
 
307
 
317
 
308
### create dirs which were not copied
318
### create dirs which were not copied
309
### -----------------------------------------------------------
319
### -----------------------------------------------------------
310
for dir in $DIR_NOT_COPY; do
320
for dir in $DIR_NOT_COPY; do
311
    mkdir $NEW/$dir
321
    mkdir $NEW/$dir
312
done
322
done
313
# we do not need this directories
323
# we do not need this directories
314
rmdir $NEW/livecd
324
rmdir $NEW/livecd
315
# if not yet existing, create
325
# if not yet existing, create
316
mkdir -p $NEW/srv
326
mkdir -p $NEW/srv
317
mkdir -p $NEW/selinux
327
mkdir -p $NEW/selinux
318
 
328
 
319
 
329
 
320
### copy back original files
330
### copy back original files
321
### -----------------------------------------------------------
331
### -----------------------------------------------------------
322
echo -n "Restore original files ... " 
332
echo -n "Restore original files ... " 
323
for file in $FILES_RESTORE; do
333
for file in $FILES_RESTORE; do
324
    [ -r $NEW/${file}.ori ] && cp -a $NEW/${file}.ori $NEW/${file} 
334
    [ -r $NEW/${file}.ori ] && mv -f $NEW/${file}.ori $NEW/${file} 
325
done
335
done
326
echo "done."; echo
336
echo "done."; echo
327
 
337
 
328
 
338
 
329
### define kernel version
339
### define kernel version
330
### -----------------------------------------------------------
340
### -----------------------------------------------------------
331
rpm --quiet -q kernel     && UP_installed=true
341
rpm --quiet -q kernel     && UP_installed=true
332
rpm --quiet -q kernel-smp && SMP_installed=true
342
rpm --quiet -q kernel-smp && SMP_installed=true
333
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
343
[ $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 )
344
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
335
if [ ! $KERNEL_VERSION ]; then
345
if [ ! $KERNEL_VERSION ]; then
336
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
346
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
337
    exit_now 1
347
    exit_now 1
338
fi    
348
fi    
339
 
349
 
340
 
350
 
341
 
351
 
342
if [ ! $NOGRUB ]; then
352
if [ ! $NOGRUB ]; then
343
 
353
 
344
    ### Backup Master Boot Record MBR
354
    ### Backup Master Boot Record MBR
345
    ### -----------------------------------------------------------
355
    ### -----------------------------------------------------------
346
    if [ ! $NOGRUB ]; then
356
    if [ ! $NOGRUB ]; then
347
	# do we have already a backup?
357
	# do we have already a backup?
348
	MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"
358
	MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"
349
	if [ ! -e /tmp/$MBR_FILENAME ]; then
359
	if [ ! -e /tmp/$MBR_FILENAME ]; then
350
	    echo "Backup Master Boot Record (MBR) of $MBR_DEV ..."
360
	    echo "Backup Master Boot Record (MBR) of $MBR_DEV ..."
351
	    dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1
361
	    dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1
352
	fi
362
	fi
353
	cp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAME
363
	cp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAME
354
	echo "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
364
	echo "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
355
	echo
365
	echo
356
    fi
366
    fi
357
 
367
 
358
 
368
 
359
    ### install grub
369
    ### install grub
360
    ### -----------------------------------------------------------
370
    ### -----------------------------------------------------------
361
    echo "Run grub-install ... "
371
    echo "Run grub-install ... "
362
    mkdir -p $NEW/boot/grub
372
    mkdir -p $NEW/boot/grub
363
    if [ $FLOPPY ]; then
373
    if [ $FLOPPY ]; then
364
	grub-install --root-directory=$NEW $MBR_DEV
374
	grub-install --root-directory=$NEW $MBR_DEV
365
    else
375
    else
366
	grub-install --no-floppy --root-directory=$NEW $MBR_DEV
376
	grub-install --no-floppy --root-directory=$NEW $MBR_DEV
367
    fi
377
    fi
368
    echo "done."; echo
378
    echo "done."; echo
369
 
379
 
370
 
380
 
371
    ### check for device.map file 
381
    ### check for device.map file 
372
    ### -----------------------------------------------------------
382
    ### -----------------------------------------------------------
373
    DEVICE_MAP=$NEW/boot/grub/device.map
383
    DEVICE_MAP=$NEW/boot/grub/device.map
374
    if [ ! -e $NEW/boot/grub/device.map ]; then
384
    if [ ! -e $NEW/boot/grub/device.map ]; then
375
	echo "ERROR: $NEW/boot/grub/device.map not found"
385
	echo "ERROR: $NEW/boot/grub/device.map not found"
376
	exit_now 1
386
	exit_now 1
377
    fi
387
    fi
378
 
388
 
379
 
389
 
380
    ### convert dev syntax to grub syntax
390
    ### convert dev syntax to grub syntax
381
    ### -----------------------------------------------------------
391
    ### -----------------------------------------------------------
382
    GRUB_INSTALL_DEV=$( grep $INSTALL_DEV $DEVICE_MAP | awk '{ print $1 }' )
392
    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`)%" )
393
    GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
384
 
394
 
385
 
395
 
386
    ### find active Windows partition
396
    ### find active Windows partition
387
    ### -----------------------------------------------------------
397
    ### -----------------------------------------------------------
388
    if [ ! $WIN_PART ]; then
398
    if [ ! $WIN_PART ]; then
389
        # try to find active Windows partition
399
        # try to find active Windows partition
390
	WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
400
	WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
391
    fi
401
    fi
392
 
402
 
393
    if [ $WIN_PART ]; then
403
    if [ $WIN_PART ]; then
394
	WIN_installed=true
404
	WIN_installed=true
395
	WIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
405
	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%' )
406
	WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
397
        # convert dev syntax to grub syntax
407
        # convert dev syntax to grub syntax
398
	GRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )
408
	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`)%" )
409
	GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )
400
 
410
 
401
        # $GRUB_WIN_PART should be something like (hd0,0)
411
        # $GRUB_WIN_PART should be something like (hd0,0)
402
	echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
412
	echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
403
	echo "Will add entry for Windows in GRUB."
413
	echo "Will add entry for Windows in GRUB."
404
	echo
414
	echo
405
    fi
415
    fi
406
 
416
 
407
 
417
 
408
    ### create grub.conf file
418
    ### create grub.conf file
409
    ### -----------------------------------------------------------
419
    ### -----------------------------------------------------------
410
    echo "Create grub.conf ..."
420
    echo "Create grub.conf ..."
411
 
421
 
-
 
422
    TITLE="Linux"
-
 
423
    [ -e $NEW//etc/redhat-release ] && TITLE=$( cat $NEW/etc/redhat-release )
-
 
424
 
412
    cat > $NEW/boot/grub/grub.conf <<EOF
425
    cat > $NEW/boot/grub/grub.conf <<EOF
413
# grub.conf generated by $SCRIPTNAME
426
# grub.conf generated by $SCRIPTNAME
414
default=0
427
default=0
415
timeout=5
428
timeout=5
416
splashimage=$GRUB_ROOT_PART/boot/grub/splash.xpm.gz
429
splashimage=$GRUB_ROOT_PART/boot/grub/splash.xpm.gz
417
#hiddenmenu
430
#hiddenmenu
418
EOF
431
EOF
419
 
432
 
420
    if [ $UP_installed ]; then
433
    if [ $UP_installed ]; then
421
	echo "Add entry for UP kernel into grub.conf"
434
	echo "Add entry for UP kernel into grub.conf"
422
	cat >> $NEW/boot/grub/grub.conf <<EOF
435
	cat >> $NEW/boot/grub/grub.conf <<EOF
423
title Scientific Linux (${KERNEL_VERSION})
436
title $TITLE (${KERNEL_VERSION})
424
        root $GRUB_ROOT_PART
437
        root $GRUB_ROOT_PART
425
	kernel /boot/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PART
438
	kernel /boot/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PART
426
	initrd /boot/initrd-$KERNEL_VERSION.img
439
	initrd /boot/initrd-$KERNEL_VERSION.img
427
EOF
440
EOF
428
    fi
441
    fi
429
 
442
 
430
    if [ $SMP_installed ]; then
443
    if [ $SMP_installed ]; then
431
	echo "Add entry for SMP kernel into grub.conf"
444
	echo "Add entry for SMP kernel into grub.conf"
432
	cat >> $NEW/boot/grub/grub.conf <<EOF
445
	cat >> $NEW/boot/grub/grub.conf <<EOF
433
title Scientific Linux (${KERNEL_VERSION}smp)
446
title $TITLE (${KERNEL_VERSION}smp)
434
        root $GRUB_ROOT_PART
447
        root $GRUB_ROOT_PART
435
	kernel /boot/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PART
448
	kernel /boot/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PART
436
	initrd /boot/initrd-${KERNEL_VERSION}smp.img
449
	initrd /boot/initrd-${KERNEL_VERSION}smp.img
437
EOF
450
EOF
438
    fi
451
    fi
439
 
452
 
440
    if [ $WIN_installed ]; then
453
    if [ $WIN_installed ]; then
441
	echo "Add entry for Windows into grub.conf"
454
	echo "Add entry for Windows into grub.conf"
442
	cat >> $NEW/boot/grub/grub.conf <<EOF
455
	cat >> $NEW/boot/grub/grub.conf <<EOF
443
title Windows
456
title Windows
444
        rootnoverify $GRUB_WIN_PART
457
        rootnoverify $GRUB_WIN_PART
445
        chainloader +1
458
        chainloader +1
446
EOF
459
EOF
447
    fi
460
    fi
448
 
461
 
449
    chmod 600 $NEW/boot/grub/grub.conf
462
    chmod 600 $NEW/boot/grub/grub.conf
450
    ln -s ../boot/grub/grub.conf $NEW/etc/grub.conf
463
    ln -s ../boot/grub/grub.conf $NEW/etc/grub.conf
451
    ln -s ./grub.conf $NEW/boot/grub/menu.lst
464
    ln -s ./grub.conf $NEW/boot/grub/menu.lst
452
    echo "done."; echo
465
    echo "done."; echo
453
 
466
 
454
fi
467
fi
455
 
468
 
456
 
469
 
457
### install kernel and other files into /boot
470
### install kernel and other files into /boot
458
### -----------------------------------------------------------
471
### -----------------------------------------------------------
459
echo "Install kernel(s) ..."
472
echo "Install kernel(s) ..."
460
 
473
 
461
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
474
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
462
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
475
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
463
 
476
 
464
if [ ! $BOOT_DIR ]; then
477
if [ ! $BOOT_DIR ]; then
465
    echo "ERROR: No kernel found - installation failed"; echo
478
    echo "ERROR: No kernel found - installation failed"; echo
466
    exit_now 1
479
    exit_now 1
467
fi
480
fi
468
 
481
 
469
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
482
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
483
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
471
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
484
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
472
cp -a $BOOT_DIR/config-*           $NEW/boot/
485
cp -a $BOOT_DIR/config-*           $NEW/boot/
473
cp -a $BOOT_DIR/symvers-*.gz       $NEW/boot/        2>/dev/null
486
cp -a $BOOT_DIR/symvers-*.gz       $NEW/boot/        2>/dev/null
474
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/
487
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/
475
cp -a $BOOT_DIR/message.ja         $NEW/boot/        2>/dev/null
488
cp -a $BOOT_DIR/message.ja         $NEW/boot/        2>/dev/null
476
cp -a $BOOT_DIR/message            $NEW/boot/        2>/dev/null
489
cp -a $BOOT_DIR/message            $NEW/boot/        2>/dev/null
477
 
490
 
478
echo "done."; echo
491
echo "done."; echo
479
 
492
 
480
 
493
 
481
### create /etc/fstab
494
### create /etc/fstab
482
### -----------------------------------------------------------
495
### -----------------------------------------------------------
483
cat > $NEW/etc/fstab <<EOF
496
cat > $NEW/etc/fstab <<EOF
484
$INSTALL_PART         /                    ext3    defaults        1 1
497
$INSTALL_PART         /                    ext3    defaults        1 1
485
devpts            /dev/pts             devpts  gid=5,mode=620  0 0
498
devpts            /dev/pts             devpts  gid=5,mode=620  0 0
486
tmpfs             /dev/shm             tmpfs   defaults        0 0
499
tmpfs             /dev/shm             tmpfs   defaults        0 0
487
proc              /proc                proc    defaults        0 0
500
proc              /proc                proc    defaults        0 0
488
sysfs             /sys                 sysfs   defaults        0 0
501
sysfs             /sys                 sysfs   defaults        0 0
489
EOF
502
EOF
490
if [ $SWAP_PART ]; then
503
if [ $SWAP_PART ]; then
491
    echo "$SWAP_PART         swap                 swap    defaults        0 0" >> $NEW/etc/fstab
504
    echo "$SWAP_PART         swap                 swap    defaults        0 0" >> $NEW/etc/fstab
492
fi
505
fi
493
 
506
 
494
 
507
 
495
### make initrd 
508
### make initrd 
496
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
509
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
497
### -----------------------------------------------------------
510
### -----------------------------------------------------------
498
echo "Create initrd(s) ..."
511
echo "Create initrd(s) ..."
499
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
512
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
500
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
513
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
501
 
514
 
502
if [ $UP_installed ]; then
515
if [ $UP_installed ]; then
503
    depmod -a ${KERNEL_VERSION}
516
    depmod -a ${KERNEL_VERSION}
504
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
517
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
505
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
518
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
506
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
519
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
507
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
520
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
508
	exit_now 1
521
	exit_now 1
509
    fi
522
    fi
510
fi
523
fi
511
if [ $SMP_installed ]; then
524
if [ $SMP_installed ]; then
512
    depmod -a ${KERNEL_VERSION}smp
525
    depmod -a ${KERNEL_VERSION}smp
513
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
526
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
514
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
527
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
515
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
528
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
516
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
529
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
517
	exit_now 1
530
	exit_now 1
518
    fi
531
    fi
519
fi
532
fi
520
echo "done."; echo
533
echo "done."; echo
521
 
534
 
522
 
535
 
523
### remove LiveCD init.d scripts
536
### remove LiveCD init.d scripts
524
### -----------------------------------------------------------
537
### -----------------------------------------------------------
525
for file in $LIVECD_INIT_SCRIPTS; do
538
for file in $LIVECD_INIT_SCRIPTS; do
526
    rm -f $NEW/etc/init.d/$file
539
    rm -f $NEW/etc/init.d/$file
527
    for n in 0 1 2 3 4 5 6; do
540
    for n in 0 1 2 3 4 5 6; do
528
	rm -f $NEW/etc/rc.d/rc${n}.d/*$file
541
	rm -f $NEW/etc/rc.d/rc${n}.d/*$file
529
    done
542
    done
530
done
543
done
531
 
544
 
532
 
545
 
533
### restore cronjobs
546
### restore cronjobs
534
### -----------------------------------------------------------
547
### -----------------------------------------------------------
535
mv $NEW/etc/cron_backup/sysstat $NEW/etc/cron.d/ 2>/dev/null
548
mv $NEW/etc/cron_backup/sysstat $NEW/etc/cron.d/ 2>/dev/null
536
mv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/null
549
mv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/null
537
mv $NEW/etc/cron_backup/* $NEW/etc/cron.daily/
550
mv $NEW/etc/cron_backup/* $NEW/etc/cron.daily/
538
 
551
 
539
 
552
 
540
### turn on kudzu again
553
### turn on kudzu again
541
### -----------------------------------------------------------
554
### -----------------------------------------------------------
542
chroot $NEW chkconfig kudzu on
555
chroot $NEW chkconfig kudzu on
543
 
556
 
544
 
557
 
545
### umount $INSTALL_PART
558
### umount $INSTALL_PART
546
### -----------------------------------------------------------
559
### -----------------------------------------------------------
547
umount $INSTALL_PART
560
umount $INSTALL_PART
548
 
561
 
549
 
562
 
550
### print summary
563
### print summary
551
### -----------------------------------------------------------
564
### -----------------------------------------------------------
552
echo                     "--------------------------------------------------------------"
565
echo                     "--------------------------------------------------------------"
553
echo                     "  LiveCD installed on partition $INSTALL_PART"
566
echo                     "  LiveCD installed on partition $INSTALL_PART"
554
[ "$SWAP_PART" ] && echo "  Partition $SWAP_PART will be used as swap partition"
567
[ "$SWAP_PART" ] && echo "  Partition $SWAP_PART will be used as swap partition"
555
echo
568
echo
556
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record (MBR) of $MBR_DEV."
569
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record (MBR) of $MBR_DEV"
557
[ ! $NOGRUB ]    && echo "  MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
570
[ ! $NOGRUB ]    && echo "  MBR saved as $MBR_FILENAME on $INSTALL_PART and in /tmp"
558
[ ! $NOGRUB ]    && echo "  If you have to restore MBR, execute under Linux:"
571
[ ! $NOGRUB ]    && echo "  If you have to restore MBR, execute under Linux:"
559
[ ! $NOGRUB ]    && echo "  # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"
572
[ ! $NOGRUB ]    && echo "  # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"
560
echo 
573
echo 
561
[ $WIN_PART ]    && echo "  Entry created in grub.conf for Windows partition $WIN_PART"
574
[ $WIN_PART ]    && echo "  Entry created in grub.conf for Windows partition $WIN_PART"
562
echo                     "--------------------------------------------------------------"
575
echo                     "--------------------------------------------------------------"
563
echo                     "End of $SCRIPTNAME"
576
echo                     "End of $SCRIPTNAME"
564
echo
577
echo