Subversion Repositories livecd

Rev

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

Rev 21 Rev 22
Line 61... Line 61...
61
   ## Usage
61
   ## Usage
62
   # ----------------------------------------------------------
62
   # ----------------------------------------------------------
63
 
63
 
64
   cat <<EOF
64
   cat <<EOF
65
   
65
   
66
  $SCRIPTNAME [OPTIONS] -mbr [DEVICE] [PARTITION]
66
  $SCRIPTNAME [OPTIONS] -mbr=[DEVICE] [PARTITION]
67
 
67
 
68
    Installes LiveCD on PARTITION and the boot loader grub
68
    Installes LiveCD on PARTITION and the boot loader grub
69
    into the Master Boot Record (MBR) of DEVICE.
69
    into the Master Boot Record (MBR) of DEVICE.
70
 
70
 
71
  OPTIONS:
71
  OPTIONS:
72
 
72
 
73
    -h   --help         print this screen
73
    -h   --help         print this screen
74
    -swap [partition]   use [partition] as swap
74
    -swap=[partition]   use [partition] as swap
-
 
75
    -win=[partition]    your active Windows partition. If not given, 
-
 
76
                        $SCRIPTNAME tries to find it
75
    -nogrub             do not install grub (leave MBR untouched) 
77
    -nogrub             do not install grub (leave MBR untouched) 
76
    -floppy             needed, if grub should be installed on floppy
78
    -floppy             needed, if grub should be installed on floppy
77
    -y                  answer all questions with yes
79
    -y                  answer all questions with yes
78
 
80
 
79
 
81
 
80
  Example:
82
  Example:
81
 
83
 
82
  $SCRIPTNAME -swap /dev/sda3 -mbr /dev/sda /dev/sda2
84
  $SCRIPTNAME -swap=/dev/sda3 -mbr=/dev/sda /dev/sda2
83
 
85
 
84
    Will install LiveCD on /dev/sda2 (= second partition on 
86
    Will install LiveCD on /dev/sda2 (= second partition on 
85
    first SATA disk). All data on /dev/sda2 will be deleted.
87
    first SATA disk). All data on /dev/sda2 will be deleted.
86
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
88
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
87
    installed in the MBR of /dev/sda (= first SATA disk).
89
    installed in the MBR of /dev/sda (= first SATA disk).
Line 104... Line 106...
104
###############################################################
106
###############################################################
105
 
107
 
106
### are we root?
108
### are we root?
107
### -----------------------------------------------------------
109
### -----------------------------------------------------------
108
if [ "$( whoami )" != "root" ]; then
110
if [ "$( whoami )" != "root" ]; then
109
    echo "Please run this script as root."
111
    echo "Please run this script as roo/home/l_beyerle/svn-livecd/livecd/trunkt."
110
    exit_now 1
112
    exit_now 1
111
fi
113
fi
112
 
114
 
113
 
115
 
114
### read options from command-line
116
### read options from command-line
Line 116... Line 118...
116
while [ $# -gt 0 ]; do
118
while [ $# -gt 0 ]; do
117
 
119
 
118
    case "$1" in
120
    case "$1" in
119
       -h)
121
       -h)
120
            usage; exit_now;;
122
            usage; exit_now;;
-
 
123
 
121
       --help)
124
       --help)
122
            usage; exit_now;;
125
            usage; exit_now;;
-
 
126
 
123
       -swap)
127
       -swap)
-
 
128
           if echo $1 | grep -q '=' ; then
-
 
129
	       SWAP_PART=$( echo $1 | sed 's/^-swap=//' )
-
 
130
	   else
-
 
131
	       shift
124
            shift; SWAP_PART=$1; shift; continue;;
132
               SWAP_PART=$2
-
 
133
	   fi
-
 
134
	   shift; continue;;
-
 
135
 
125
       -mbr)
136
       -mbr)
-
 
137
           if echo $1 | grep -q '=' ; then
-
 
138
	       MBR_DEV=$( echo $1 | sed 's/^-mbr=//' )
-
 
139
	   else
-
 
140
	       shift
126
            shift; MBR_DEV=$1; shift; continue;;
141
               MBR_DEV=$2
-
 
142
	   fi
-
 
143
	   shift; continue;;
-
 
144
 
-
 
145
       -win)
-
 
146
           if echo $1 | grep -q '=' ; then
-
 
147
	       WIN_PART=$( echo $1 | sed 's/^-win=//' )
-
 
148
	   else
-
 
149
	       shift
-
 
150
               WIN_PART=$2
-
 
151
	   fi
-
 
152
	   shift; continue;;
-
 
153
 
127
       -nogrub)
154
       -nogrub)
128
            NOGRUB=$1; shift; continue;;
155
            NOGRUB=$1; shift; continue;;
-
 
156
 
129
       -floppy)
157
       -floppy)
130
            FLOPPY=$1; shift; continue;;
158
            FLOPPY=$1; shift; continue;;
-
 
159
 
131
       -y)
160
       -y)
132
            YES=$1; shift; continue;;
161
            YES=$1; shift; continue;;
133
 
162
 
134
       *)
163
       *)
135
            INSTALL_PART=$1; break;;
164
            INSTALL_PART=$1; break;;
Line 137... Line 166...
137
 
166
 
138
done
167
done
139
echo
168
echo
140
 
169
 
141
 
170
 
142
### test if MBR_DEV is given
171
### test if $INSTALL_PART is defined and exists
143
### -----------------------------------------------------------
172
### -----------------------------------------------------------
144
if [ ! $NOGRUB ]; then
173
if [ ! $INSTALL_PART ]; then
145
    if [ ! $MBR_DEV ]; then
-
 
146
	echo "No MBR device defined."
174
    echo "No partition defined for installation"
147
	echo "Please see '$SCRIPTNAME -h'."; echo
175
    echo "Please see '$SCRIPTNAME -h'."; echo
148
	exit_now 1
176
    exit_now 1
149
    fi
177
fi
150
fi
-
 
151
 
178
 
152
 
179
 
153
### test if $INSTALL_PART is defined and exists
180
### test if MBR_DEV is given
154
### -----------------------------------------------------------
181
### -----------------------------------------------------------
155
if [ ! $INSTALL_PART ]; then
182
if [ ! $NOGRUB ]; then
-
 
183
    if [ ! $MBR_DEV ]; then
156
    echo "No partition defined for installation"
184
	echo "No MBR device defined."
157
    echo "Please see '$SCRIPTNAME -h'."; echo
185
	echo "Please see '$SCRIPTNAME -h'."; echo
158
    exit_now 1
186
	exit_now 1
159
fi
187
    fi
-
 
188
fi
160
 
189
 
161
 
190
 
162
### test if $INSTALL_PART exists
191
### test if $INSTALL_PART exists
163
### -----------------------------------------------------------
192
### -----------------------------------------------------------
164
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
193
fdisk -l | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
Line 321... Line 350...
321
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
350
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
322
    exit_now 1
351
    exit_now 1
323
fi    
352
fi    
324
 
353
 
325
 
354
 
-
 
355
### check for device.map file 
-
 
356
### -----------------------------------------------------------
-
 
357
DEVICE_MAP=$NEW/boot/grub/device.map
-
 
358
if [ ! -e $NEW/boot/grub/device.map ]; then
-
 
359
    echo "ERROR: $NEW/boot/grub/device.map not found"
-
 
360
    exit_now 1
-
 
361
fi
-
 
362
 
-
 
363
 
326
### convert dev syntax to grub syntax
364
### convert dev syntax to grub syntax
327
### -----------------------------------------------------------
365
### -----------------------------------------------------------
328
device_map=$NEW/boot/grub/device.map
-
 
329
GRUB_INSTALL_DEV=$( grep $INSTALL_DEV $device_map | awk '{ print $1 }' )
366
GRUB_INSTALL_DEV=$( grep $INSTALL_DEV $DEVICE_MAP | awk '{ print $1 }' )
330
GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
367
GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
331
 
368
 
332
 
369
 
333
### define active Windows partition -  to be fixed  !!!
370
### find active Windows partition
334
### -----------------------------------------------------------
371
### -----------------------------------------------------------
-
 
372
if [ ! $WIN_PART ]; then
-
 
373
    # try to find active Windows partition
-
 
374
    WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
-
 
375
fi
-
 
376
 
-
 
377
if [ $WIN_PART ]; then
335
WIN_installed=true
378
    WIN_installed=true
-
 
379
    WIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
-
 
380
    WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
-
 
381
    # convert dev syntax to grub syntax
-
 
382
    GRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )
-
 
383
    GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )
-
 
384
 
336
GRUB_WIN_PART=(hd0,0)
385
    # $GRUB_WIN_PART should be something like (hd0,0)
-
 
386
    echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
-
 
387
    echo "Will add entry for Windows in GRUB."
-
 
388
    echo
-
 
389
fi
337
 
390
 
338
 
391
 
339
### create grub.conf file
392
### create grub.conf file
340
### -----------------------------------------------------------
393
### -----------------------------------------------------------
341
echo "Create grub.conf:"
394
echo "Create grub.conf:"
Line 419... Line 472...
419
 
472
 
420
### make initrd 
473
### make initrd 
421
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
474
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
422
### -----------------------------------------------------------
475
### -----------------------------------------------------------
423
echo "Create initrd(s) ..."
476
echo "Create initrd(s) ..."
-
 
477
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
-
 
478
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
-
 
479
 
424
if [ $UP_installed ]; then
480
if [ $UP_installed ]; then
425
    depmod -a ${KERNEL_VERSION}
481
    depmod -a ${KERNEL_VERSION}
426
    livecd-mkinitrd --fstab=$NEW/etc/fstab \
482
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
427
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
483
                    $NEW//boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
428
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
484
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
429
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
485
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
430
	exit_now 1
486
	exit_now 1
431
    fi
487
    fi
432
fi
488
fi
433
if [ $SMP_installed ]; then
489
if [ $SMP_installed ]; then
434
    depmod -a ${KERNEL_VERSION}smp
490
    depmod -a ${KERNEL_VERSION}smp
435
    livecd-mkinitrd --fstab=$NEW/etc/fstab \
491
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
436
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
492
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
437
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
493
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
438
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
494
	echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
439
	exit_now 1
495
	exit_now 1
440
    fi
496
    fi
Line 466... Line 522...
466
 
522
 
467
### umount $INSTALL_PART
523
### umount $INSTALL_PART
468
### -----------------------------------------------------------
524
### -----------------------------------------------------------
469
umount $INSTALL_PART
525
umount $INSTALL_PART
470
 
526
 
-
 
527
 
-
 
528
### print summary
-
 
529
### -----------------------------------------------------------
-
 
530
echo "-----------------------------------------------------------"
-
 
531
echo "  LiveCD installed on partition $INSTALL_PART."
-
 
532
[ "$SWAP_PART" ] && echo "  Partition $SWAP_PART will be used as swap partition."
-
 
533
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record of $MBR_DEV."
-
 
534
[ $WIN_PART ]    && echo "  Entry in grub.conf for Windows partition on $WIN_PART."
-
 
535
echo "-----------------------------------------------------------"
-
 
536
echo "End of $SCRIPTNAME."
-
 
537
echo