Subversion Repositories livecd

Rev

Rev 18 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18 Rev 21
Line 44... Line 44...
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
SCRIPTNAME=$( basename $0 )
50
SCRIPTNAME=$( basename $0 )
50
 
51
 
51
 
52
 
52
 
53
 
-
 
54
 
53
###############################################################
55
###############################################################
54
# Functions
56
# Functions
55
###############################################################
57
###############################################################
56
 
58
 
57
function usage() {
59
function usage() {
Line 66... Line 68...
66
   Installes LiveCD on PARTITION and the boot loader grub
68
    Installes LiveCD on PARTITION and the boot loader grub
67
   into the Master Boot Record (MBR) of DEVICE.
69
    into the Master Boot Record (MBR) of DEVICE.
68
 
70
 
69
   OPTIONS:
71
  OPTIONS:
70
 
72
 
71
    -h                  print this screen
73
    -h   --help         print this screen
72
    -swap [partition]  	use [partition] as swap
74
    -swap [partition]   use [partition] as swap
73
    -nogrub             do not install grub (leave MBR untouched) 
75
    -nogrub             do not install grub (leave MBR untouched) 
74
    -floppy             need, if grub should be isntalled on a floopy
76
    -floppy             needed, if grub should be installed on floppy
75
    -y                  answer all questions with yes
77
    -y                  answer all questions with yes
76
 
78
 
-
 
79
 
-
 
80
  Example:
-
 
81
 
-
 
82
  $SCRIPTNAME -swap /dev/sda3 -mbr /dev/sda /dev/sda2
-
 
83
 
-
 
84
    Will install LiveCD on /dev/sda2 (= second partition on 
-
 
85
    first SATA disk). All data on /dev/sda2 will be deleted.
-
 
86
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
-
 
87
    installed in the MBR of /dev/sda (= first SATA disk).
-
 
88
   
77
EOF
89
EOF
78
}
90
}
79
 
91
 
80
 
92
 
-
 
93
function exit_now() {
-
 
94
 
-
 
95
    local exitcode=$1
-
 
96
    umount $INSTALL_PART 2>/dev/null
-
 
97
    exit $exitcode
-
 
98
}
-
 
99
 
-
 
100
 
-
 
101
 
81
###############################################################
102
###############################################################
82
# Main
103
# Main
83
###############################################################
104
###############################################################
84
 
105
 
85
### are we root?
106
### are we root?
86
### -----------------------------------------------------------
107
### -----------------------------------------------------------
87
if [ "$( whoami )" != "root" ]; then
108
if [ "$( whoami )" != "root" ]; then
88
    echo "Please run this script as root."
109
    echo "Please run this script as root."
89
    # exit 1
110
    exit_now 1
90
fi
111
fi
91
 
112
 
92
 
113
 
93
### read options from command-line
114
### read options from command-line
94
### -----------------------------------------------------------
115
### -----------------------------------------------------------
95
while [ $# -gt 0 ]; do
116
while [ $# -gt 0 ]; do
96
 
117
 
97
    case "$1" in
118
    case "$1" in
98
       -h)
119
       -h)
-
 
120
            usage; exit_now;;
-
 
121
       --help)
99
            usage; exit;;
122
            usage; exit_now;;
100
       -swap)
123
       -swap)
101
            shift; SWAP_PART=$1; shift; continue;;
124
            shift; SWAP_PART=$1; shift; continue;;
102
       -mbr)
125
       -mbr)
103
            shift; MBR_DEV=$1; shift; continue;;
126
            shift; MBR_DEV=$1; shift; continue;;
104
       -nogrub)
127
       -nogrub)
Line 120... Line 143...
120
### -----------------------------------------------------------
143
### -----------------------------------------------------------
121
if [ ! $NOGRUB ]; then
144
if [ ! $NOGRUB ]; then
122
    if [ ! $MBR_DEV ]; then
145
    if [ ! $MBR_DEV ]; then
123
	echo "No MBR device defined."
146
	echo "No MBR device defined."
124
	echo "Please see '$SCRIPTNAME -h'."; echo
147
	echo "Please see '$SCRIPTNAME -h'."; echo
125
	exit 1
148
	exit_now 1
126
    fi
149
    fi
127
fi
150
fi
128
 
151
 
129
 
152
 
130
### test if $INSTALL_PART defined and exists
153
### test if $INSTALL_PART is defined and exists
131
### -----------------------------------------------------------
154
### -----------------------------------------------------------
132
if [ ! $INSTALL_PART ]; then
155
if [ ! $INSTALL_PART ]; then
133
    echo "No partition defined for installation"
156
    echo "No partition defined for installation"
134
    echo "Please see '$SCRIPTNAME -h'."; echo
157
    echo "Please see '$SCRIPTNAME -h'."; echo
135
    exit 1
158
    exit_now 1
136
fi
159
fi
137
 
160
 
138
 
161
 
139
### test if $INSTALL_PART exists
162
### test if $INSTALL_PART exists
140
### -----------------------------------------------------------
163
### -----------------------------------------------------------
141
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
164
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
142
if [ "$?" != "0" ]; then
165
if [ "$?" != "0" ]; then
143
    echo "Partition $INSTALL_PART not found! (see 'disk -l')"; echo
166
    echo "Partition $INSTALL_PART not found! (see 'disk -l')"; echo
144
    exit 1
167
    exit_now 1
145
fi
168
fi
146
 
169
 
147
 
170
 
148
### set $INSTALL_DEV (eg. /dev/sda)
171
### set $INSTALL_DEV (eg. /dev/sda)
149
### -----------------------------------------------------------
172
### -----------------------------------------------------------
Line 155... Line 178...
155
### -----------------------------------------------------------
178
### -----------------------------------------------------------
156
if [ $SWAP_PART ]; then
179
if [ $SWAP_PART ]; then
157
    fdisk -l | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
180
    fdisk -l | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
158
    if [ "$?" != "0" ]; then
181
    if [ "$?" != "0" ]; then
159
	echo "Swap partition $SWAP_PART not found! (see 'disk -l')"; echo
182
	echo "Swap partition $SWAP_PART not found! (see 'disk -l')"; echo
160
	exit 1
183
	exit_now 1
161
    fi
184
    fi
162
    fdisk -l | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
185
    fdisk -l | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PART}$"
163
    if [ "$?" != "0" ]; then
186
    if [ "$?" != "0" ]; then
164
	echo "Partition $SWAP_PART is not a Linux swap partition! (see 'disk -l')"; echo
187
	echo "Partition $SWAP_PART is not a Linux swap partition! (see 'disk -l')"; echo
165
	exit 1
188
	exit_now 1
166
    fi
189
    fi
167
fi
190
fi
168
 
191
 
169
 
192
 
170
### print warning
193
### print warning
Line 185... Line 208...
185
### -----------------------------------------------------------
208
### -----------------------------------------------------------
186
if [ ! $YES ]; then
209
if [ ! $YES ]; then
187
    echo -n "Continue (y/N)? "
210
    echo -n "Continue (y/N)? "
188
    read key
211
    read key
189
    echo
212
    echo
190
    [ "$key" != "y" ] && exit 0
213
    [ "$key" != "y" ] && exit_now 0
191
fi
214
fi
192
echo
215
echo
193
 
216
 
194
 
217
 
-
 
218
### Backup MBR
-
 
219
### -----------------------------------------------------------
-
 
220
### to do !!!!!!!!!!
-
 
221
###
-
 
222
 
-
 
223
 
195
### format $INSTALL_PART
224
### format $INSTALL_PART
196
### -----------------------------------------------------------
225
### -----------------------------------------------------------
197
echo -n "Format $INSTALL_PART, please wait ... " 
226
echo -n "Format $INSTALL_PART, please wait ... " 
198
mkfs.ext3 -q $INSTALL_PART || exit 1
227
mkfs.ext3 -q $INSTALL_PART || exit_now 1
199
echo "done."; echo
228
echo "done."; echo
200
 
229
 
201
 
230
 
202
### mount $INSTALL_PART
231
### mount $INSTALL_PART
203
### -----------------------------------------------------------
232
### -----------------------------------------------------------
204
echo -n "Try to mount $INSTALL_PART to $NEW ... "
233
echo -n "Try to mount $INSTALL_PART to $NEW ... "
205
mkdir -p $NEW
234
mkdir -p $NEW
206
mount $INSTALL_PART $NEW || exit 1
235
mount $INSTALL_PART $NEW || exit_now 1
207
echo "done."; echo
236
echo "done."; echo
208
 
237
 
209
 
238
 
210
### copy root dirs
239
### copy root dirs
211
### -----------------------------------------------------------
240
### -----------------------------------------------------------
Line 221... Line 250...
221
	fi
250
	fi
222
    done
251
    done
223
    # do not copy links
252
    # do not copy links
224
    [ -L /$dir ] && do_not_copy="yes"
253
    [ -L /$dir ] && do_not_copy="yes"
225
 
254
 
-
 
255
    fail=""
226
    if [ ! $do_not_copy ]; then
256
    if [ ! $do_not_copy ]; then
227
	echo -n "  * Copy  /$dir ... "
257
	echo -n "  * Copy  /$dir ... "
228
	cp -a /$dir $NEW
258
	cp -a /$dir $NEW || fail=true
229
	echo "done."
259
	echo "done."
230
    fi
260
    fi
231
done
261
done
232
echo
262
echo
-
 
263
if [ $fail ]; then
-
 
264
    echo "ERROR: Not everything was copied to $INSTALL_PART"
-
 
265
    exit_now 1
-
 
266
fi
233
 
267
 
234
 
268
 
235
### move /usr/opt back to /opt
269
### move /usr/opt back to /opt
236
### -----------------------------------------------------------
270
### -----------------------------------------------------------
237
if [ -d $NEW/usr/opt ]; then
271
if [ -d $NEW/usr/opt ]; then
Line 256... Line 290...
256
    [ -r $NEW/${file}.ori ] && cp -a $NEW/${file}.ori $NEW/${file} 
290
    [ -r $NEW/${file}.ori ] && cp -a $NEW/${file}.ori $NEW/${file} 
257
done
291
done
258
echo "done."; echo
292
echo "done."; echo
259
 
293
 
260
 
294
 
261
### do some mounts for chroot $NEW
295
### do some mounts for chroot $NEW (no more needed)
262
### -----------------------------------------------------------
296
### -----------------------------------------------------------
263
mount --bind /dev $NEW/dev
297
# mount --bind /dev $NEW/dev
264
mount --bind /sys $NEW/sys 
298
# mount --bind /sys $NEW/sys 
265
mount -t proc proc $NEW/proc
299
# mount -t proc proc $NEW/proc
266
 
300
 
267
 
301
 
268
### install grub
302
### install grub
269
### -----------------------------------------------------------
303
### -----------------------------------------------------------
270
echo "Run grub-install: "; echo
304
echo "Run grub-install: "; echo
Line 283... Line 317...
283
rpm --quiet -q kernel-smp && SMP_installed=true
317
rpm --quiet -q kernel-smp && SMP_installed=true
284
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
318
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
285
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
319
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
286
if [ ! $KERNEL_VERSION ]; then
320
if [ ! $KERNEL_VERSION ]; then
287
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
321
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
288
    exit 1
322
    exit_now 1
289
fi    
323
fi    
290
[ $UP_installed ]   && echo "UP kernel found."
-
 
291
[ $SMP_installed ]  && echo "SMP kernel found."
-
 
292
echo
-
 
293
 
324
 
294
 
325
 
295
### convert dev syntax to grub syntax
326
### convert dev syntax to grub syntax
296
### -----------------------------------------------------------
327
### -----------------------------------------------------------
297
device_map=$NEW/boot/grub/device.map
328
device_map=$NEW/boot/grub/device.map
Line 305... Line 336...
305
GRUB_WIN_PART=(hd0,0)
336
GRUB_WIN_PART=(hd0,0)
306
 
337
 
307
 
338
 
308
### create grub.conf file
339
### create grub.conf file
309
### -----------------------------------------------------------
340
### -----------------------------------------------------------
310
echo "Create grub.conf"
341
echo "Create grub.conf:"
311
 
342
 
312
cat > $NEW/boot/grub/grub.conf <<EOF
343
cat > $NEW/boot/grub/grub.conf <<EOF
313
# grub.conf generated by $SCRIPTNAME
344
# grub.conf generated by $SCRIPTNAME
314
default=0
345
default=0
315
timeout=5
346
timeout=5
Line 352... Line 383...
352
echo "done."; echo
383
echo "done."; echo
353
 
384
 
354
 
385
 
355
### install kernel into /boot
386
### install kernel into /boot
356
### -----------------------------------------------------------
387
### -----------------------------------------------------------
357
echo "Install kernel(s)"
388
echo "Install kernel(s) ..."
358
 
389
 
359
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
390
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
360
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
391
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
361
 
392
 
362
if [ ! $BOOT_DIR ]; then
393
if [ ! $BOOT_DIR ]; then
363
    echo "ERROR: No kernel found - installation failed"; echo
394
    echo "ERROR: No kernel found - installation failed"; echo
364
    exit 1
395
    exit_now 1
365
fi
396
fi
366
 
397
 
367
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
398
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
368
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
399
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
369
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
400
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
370
cp -a $BOOT_DIR/config-*           $NEW/boot/
401
cp -a $BOOT_DIR/config-*           $NEW/boot/
371
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/
402
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/
372
echo "done."; echo
403
echo "done."; echo
373
 
404
 
374
 
405
 
-
 
406
### create /etc/fstab
-
 
407
### -----------------------------------------------------------
-
 
408
cat > $NEW/etc/fstab <<EOF
-
 
409
$INSTALL_PART         /                    ext3    defaults        1 1
-
 
410
devpts            /dev/pts             devpts  gid=5,mode=620  0 0
-
 
411
tmpfs             /dev/shm             tmpfs   defaults        0 0
-
 
412
proc              /proc                proc    defaults        0 0
-
 
413
sysfs             /sys                 sysfs   defaults        0 0
-
 
414
EOF
-
 
415
if [ $SWAP_PART ]; then
-
 
416
    echo "$SWAP_PART         swap                 swap    defaults        0 0" >> $NEW/etc/fstab
-
 
417
fi
-
 
418
 
-
 
419
 
375
### make initrd
420
### make initrd 
-
 
421
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
376
### -----------------------------------------------------------
422
### -----------------------------------------------------------
377
echo "Create initrd(s)"
423
echo "Create initrd(s) ..."
378
if [ $UP_installed ]; then
424
if [ $UP_installed ]; then
379
    chroot $NEW depmod -a
425
    depmod -a ${KERNEL_VERSION}
380
    chroot $NEW \
426
    livecd-mkinitrd --fstab=$NEW/etc/fstab \
381
    livecd-mkinitrd $NEW/boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
427
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
382
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
428
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
383
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
429
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
384
	exit 1
430
	exit_now 1
385
    fi
431
    fi
386
fi
432
fi
387
if [ $SMP_installed ]; then
433
if [ $SMP_installed ]; then
388
    chroot $NEW depmod -a
434
    depmod -a ${KERNEL_VERSION}smp
389
    chroot $NEW \
435
    livecd-mkinitrd --fstab=$NEW/etc/fstab \
390
    livecd-mkinitrd $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
436
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
391
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
437
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
392
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
438
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
393
	exit 1
439
	exit_now 1
394
    fi
440
    fi
395
fi
441
fi
396
echo "done."; echo
442
echo "done."; echo
397
 
443
 
398
 
444
 
399
### create /etc/fstab
-
 
400
### -----------------------------------------------------------
-
 
401
cat > $NEW/etc/fstab <<EOF
-
 
402
$INSTALL_PART         /                    ext3    defaults        1 1
-
 
403
devpts            /dev/pts             devpts  gid=5,mode=620  0 0
-
 
404
tmpfs             /dev/shm             tmpfs   defaults        0 0
-
 
405
proc              /proc                proc    defaults        0 0
-
 
406
sysfs             /sys                 sysfs   defaults        0 0
-
 
407
EOF
-
 
408
 
-
 
409
if [ $SWAP_PART ]; then
-
 
410
    echo "$SWAP_PART         swap                 swap    defaults        0 0" >> $NEW/etc/fstab
-
 
411
fi
-
 
412
 
-
 
413
 
-
 
414
### remove LiveCD init.d scripts
445
### remove LiveCD init.d scripts
415
### -----------------------------------------------------------
446
### -----------------------------------------------------------
416
for file in $LIVECD_INIT_SCRIPTS; do
447
for file in $LIVECD_INIT_SCRIPTS; do
417
    rm -f $NEW/etc/init.d/$file
448
    rm -f $NEW/etc/init.d/$file
418
    for n in 0 1 2 3 4 5 6; do
449
    for n in 0 1 2 3 4 5 6; do
Line 433... Line 464...
433
chkconfig kudzu on
464
chkconfig kudzu on
434
 
465
 
435
 
466
 
436
### umount $INSTALL_PART
467
### umount $INSTALL_PART
437
### -----------------------------------------------------------
468
### -----------------------------------------------------------
438
umount $NEW/dev
-
 
439
umount $NEW/sys 
-
 
440
umount $NEW/proc
-
 
441
 
-
 
442
umount $INSTALL_PART
469
umount $INSTALL_PART
443
 
470