summaryrefslogtreecommitdiffstats
path: root/source/a/pkgtools/scripts/makebootdisk
blob: 5fbe27e25d01896ebd6c950c8cb713d19f7583ff (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!/bin/bash
# Copyright 1995, 1998, 2002, 2005  Patrick Volkerding, Moorhead, Minnesota USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

if [ ! "$UID" = "0" ]; then
    echo "You need to be root to run this script."
    exit 1
fi

# Was a kernel specified on the command line?
if [ -r "$1" ]; then
  KERNEL=$1
  KMSG="Using kernel $KERNEL"
else
  KMSG="No kernel selected yet"
fi

# Make sure there's a proper temp directory:
TMP=/var/lib/pkgtools/setup/tmp
# If the $TMP directory doesn't exist, create it:
if [ ! -d $TMP ]; then
  mkdir -p $TMP
  chmod 700 $TMP # no need to leave it open
fi

ROOT_DEVICE="`mount | grep ' on / ' | cut -f 1 -d ' '`"

if mount | grep ' on / ' | grep umsdos 1> /dev/null 2> /dev/null ; then
 MOUNT="read-write"
else
 MOUNT="read-only"
fi

make_root_device() {
# Make a device:
makedev() {
  if [ ! -b $1 ]; then
    mknod $1 b $2 $3
    chown root.disk $1
    chmod 640 $1
  fi  
}

# Make ide device
# make ide major minor hd1 hd2 (2 base devs for major)
make_ide() {
  # Handle base devices:
  if [ "$2" = "0" ]; then
    makedev $TMP/lilo/dev/$3 $1 $2
    return 0
  elif [ "$2" = "64" ]; then
    makedev $TMP/lilo/dev/$4 $1 $2
    return 0
  fi
  # Must be a partition:
  if [ "`expr $2 / 64`" = "0" ]; then
    DEV=$3
    NUM=$2
  else
    DEV=$4
    NUM=`expr $2 - 64`
  fi
  makedev $TMP/lilo/dev/$DEV$NUM $1 $2
}

# Make SCSI device
make_scsi() {
  # find drive # 0 - 15
  DRV=`expr $1 / 16`
  NUM=`expr $1 % 16`
  if [ "$NUM" = "0" ]; then
    NUM=""
  fi
  if [ "$DRV" = "0" ]; then
    makedev $TMP/lilo/dev/sda$NUM 8 $1
  elif [ "$DRV" = "1" ]; then
    makedev $TMP/lilo/dev/sdb$NUM 8 $1
  elif [ "$DRV" = "2" ]; then
    makedev $TMP/lilo/dev/sdc$NUM 8 $1
  elif [ "$DRV" = "3" ]; then
    makedev $TMP/lilo/dev/sdd$NUM 8 $1
  elif [ "$DRV" = "4" ]; then
    makedev $TMP/lilo/dev/sde$NUM 8 $1
  elif [ "$DRV" = "5" ]; then
    makedev $TMP/lilo/dev/sdf$NUM 8 $1
  elif [ "$DRV" = "6" ]; then
    makedev $TMP/lilo/dev/sdg$NUM 8 $1
  elif [ "$DRV" = "7" ]; then
    makedev $TMP/lilo/dev/sdh$NUM 8 $1
  elif [ "$DRV" = "8" ]; then
    makedev $TMP/lilo/dev/sdi$NUM 8 $1
  elif [ "$DRV" = "9" ]; then
    makedev $TMP/lilo/dev/sdj$NUM 8 $1
  elif [ "$DRV" = "10" ]; then
    makedev $TMP/lilo/dev/sdk$NUM 8 $1
  elif [ "$DRV" = "11" ]; then
    makedev $TMP/lilo/dev/sdl$NUM 8 $1
  elif [ "$DRV" = "12" ]; then
    makedev $TMP/lilo/dev/sdm$NUM 8 $1
  elif [ "$DRV" = "13" ]; then
    makedev $TMP/lilo/dev/sdn$NUM 8 $1
  elif [ "$DRV" = "14" ]; then
    makedev $TMP/lilo/dev/sdo$NUM 8 $1
  elif [ "$DRV" = "15" ]; then
    makedev $TMP/lilo/dev/sdp$NUM 8 $1
  fi
}

if cat /proc/partitions | grep / 1> /dev/null 2> /dev/null ; then # new
  cat /proc/partitions | grep / | while read line ; do
    SMASHED_LINE=$line
    MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
    MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
    if [ "$MAJOR" = "3" ]; then
      make_ide $MAJOR $MINOR hda hdb
    elif [ "$MAJOR" = "8" ]; then
      make_scsi $MINOR
    elif [ "$MAJOR" = "22" ]; then
      make_ide $MAJOR $MINOR hdc hdd
    elif [ "$MAJOR" = "33" ]; then
      make_ide $MAJOR $MINOR hde hdf
    elif [ "$MAJOR" = "34" ]; then
      make_ide $MAJOR $MINOR hdg hdh
    elif [ "$MAJOR" = "56" ]; then
      make_ide $MAJOR $MINOR hdi hdj
    fi
  done
else # old format
  cat /proc/partitions | grep d | while read line ; do
    SMASHED_LINE=$line
    MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
    MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
    DEVNAME=`echo $SMASHED_LINE | cut -f 4 -d ' '`
    makedev $TMP/lilo/dev/$DEVNAME $MAJOR $MINOR
  done
fi
}

choose_kernel() {
while [ 0 ]; do # input loop
cat << EOF > $TMP/tmpmsg

Some possible paths to kernels are these: 

/boot/vmlinuz 
/usr/src/linux/arch/i386/boot/bzImage
/usr/src/linux/arch/i386/boot/zImage
/vmlinuz

Put the path to the kernel you want to use in the box below.

EOF

 dialog --title "CHOOSE KERNEL" --inputbox "`cat $TMP/tmpmsg`" \
 16 72 "/boot/vmlinuz" 2> $TMP/return
 if [ ! $? = 0 ]; then
  exit
 fi

 KERNEL="`cat $TMP/return`"
    
 if [ ! -r "$KERNEL" ]; then  
    dialog --title "NOT FOUND!" --msgbox "$KERNEL" 5 60
    continue
 fi
 KMSG="Using kernel $KERNEL"
break
done
}

format_disk() {
  # If anyone still uses 1.2 MB, you'll have to uncomment this.
  # It's no longer a default option.
  #FDEV=/dev/fd0h1200
  #FDEV=/dev/fd0u1400
  FDEV=/dev/fd0u1680
  if [ "$FDEV" = "/dev/fd0u1680" ]; then
   dialog --title "Formatting /dev/fd0u1680" --infobox \
   "Formatting /dev/fd0, 1.68 megabytes." 3 42
  elif [ "$FDEV" = "/dev/fd0u1400" ]; then
   dialog --title "Formatting /dev/fd0u1440" --infobox \
   "Formatting /dev/fd0, 1.44 megabytes." 3 42
  elif [ "$FDEV" = "/dev/fd0h1200" ]; then
   dialog --title "Formatting /dev/fd0h1200" --infobox \
   "Formatting /dev/fd0, 1.2 megabytes." 3 42
  fi
  fdformat $FDEV 1> /dev/null 2> /dev/null
  if [ ! $? = 0 ]; then
    dialog --title "ERROR: FLOPPY FORMAT FAILED" --msgbox "The attempt to format the floppy \
disk in /dev/fd0 has failed, probably due to bad media. Please try again with a \
different disk. If that doesn't work, perhaps the drive needs cleaning." 0 0
    return 1
  fi
}

DEFAULT_ITEM="syslinux"

while [ 0 ]; do # menu loop
 dialog --title "MAKE BOOT FLOPPY FROM KERNEL" \
--default-item $DEFAULT_ITEM \
--backtitle "$KMSG" --menu "This menu allows you to make a SYSLINUX bootdisk \
from a compiled kernel. The SYSLINUX bootloader has the advantage of \
using a FAT filesystem making it easy to replace the kernel later. \
Which option would you like?" 12 67 2 \
"syslinux" "Make a SYSLINUX bootdisk" \
"exit" "Exit this program" 2> $TMP/return
 if [ ! $? = 0 ]; then
  break;
 fi
 REPLY=`cat $TMP/return`
 rm -f $TMP/return
 if [ "$REPLY" = "simple" ]; then # make simple bootdisk
  if [ "$KERNEL" = "" ]; then
   choose_kernel
  fi
  kernel_size=`du -Lk $KERNEL | cut -f1`
  if [ "$kernel_size" -gt "1023" ]; then
cat << EOF > $TMP/tmpmsg

The kernel $KERNEL is $kernel_size K (which is
more than 1023 Kb in size), so it probably won't 
boot standalone on the floppy. Use the 'syslinux' 
method instead.
 
EOF
   dialog --title "KERNEL TOO BIG!" --msgbox "`cat $TMP/tmpmsg`" 10 60
   continue
  fi
  dialog --title "BOOT DISK CREATION" --backtitle "$KMSG" --yesno \
"\n\
Now put a formatted floppy in your boot drive. \n\
This will be made into your Linux boot disk. Use this to\n\
boot Linux until LILO has been configured to boot from\n\
the hard drive.\n\n\
Any data on the target disk will be destroyed.\n\n\
YES creates the disk, NO aborts.\n" 14 62
  if [ $? = 0 ]; then
   format_disk
   dialog --title "CREATING DISK" --infobox "Creating boot disk from $KERNEL..." 5 72
   dd if=$KERNEL of=/dev/fd0 2> /dev/null
   rdev /dev/fd0 $ROOT_DEVICE
   rdev -v /dev/fd0 -1
   if [ "$MOUNT" = "read-only" ]; then
    rdev -R /dev/fd0 1
   else
    rdev -R /dev/fd0 0
   fi
  fi
 elif [ "$REPLY" = "syslinux" ]; then # make syslinux bootdisk
  DEFAULT_ITEM="exit"
  if [ "$KERNEL" = "" ]; then
   choose_kernel
  fi
  dialog --title "CREATING SYSLINUX BOOTDISK IN /dev/fd0" --backtitle "$KMSG" --yesno "Now put a \
floppy in your boot drive. This will be made into a SYSLINUX \
bootdisk that you can use to start your Linux system. Any data on the \
target disk will be destroyed. YES creates the disk, NO aborts." 8 62
  if [ $? = 0 ]; then # make the disk
   format_disk
   if [ ! $? = 0 ]; then
    continue
   fi
   dialog --title "CREATING BOOT FLOPPY" --infobox "Creating SYSLINUX bootdisk for \
$ROOT_DEVICE in /dev/fd0." 3 64
   mkdosfs -F 12 /dev/fd0u1680 1680 1> /dev/null 2> /dev/null
   if [ ! -d $TMP/bootdisk ]; then
    mkdir $TMP/bootdisk
   fi
   mount -t vfat /dev/fd0 $TMP/bootdisk 1> /dev/null 2> /dev/null
   cp $KERNEL $TMP/bootdisk/vmlinuz
   ## This avoids a syslinux-1.72 bug, and doesn't seem to hurt anything:
   #dd if=/dev/zero bs=1k count=1 >> $TMP/bootdisk/vmlinuz 2> /dev/null
   if [ ! "$?" = "0" ]; then
     dialog --title "ERROR COPYING KERNEL TO FLOPPY" \
     --msgbox "Sorry, but there was an error copying the kernel to the \
floppy disk. Possibly the kernel is too large to fit the disk.  \
This program will now exit." 0 0
     umount /dev/fd0
     rm -rf $TMP/bootdisk
     exit 1
   fi
   cat << EOF > $TMP/bootdisk/message.txt

Welcome to the 09Slackware07 Linux custom bootdisk!

By default, this disk boots a root Linux partition on $ROOT_DEVICE when you
hit ENTER. If you'd like to boot some other partition, use a command like
this on the prompt below:

    mount root=/dev/sda1 ro

Where "/dev/sda1" is the partition you want to boot, and "ro" specifies that
the partition should be initially mounted as read-only. If you wish to mount
the partition read-write, use "rw" instead. To set the video console mode,
use the vga= parameter (press F1 to see a table). You may also add any other
kernel parameters you might need depending on your hardware, and which
drivers are included in your kernel.

EOF
   cat << EOF > $TMP/bootdisk/syslinux.cfg
default vmlinuz ramdisk_size=7000 root=$ROOT_DEVICE vga=normal ro
prompt 1
timeout 6000
display message.txt
F1 f1.txt
F2 message.txt
#F3 f3.txt
#F4 f4.txt
#F5 f5.txt
#F6 f6.txt
#F7 f7.txt
label mount
  kernel vmlinuz
  append ramdisk_size=7000 root=$ROOT_DEVICE vga=normal ro
label ramdisk
  kernel vmlinuz
  append vmlinuz ramdisk_size=7000 root=/dev/fd0u1440 vga=normal rw
EOF
   cat << EOF > $TMP/bootdisk/f1.txt
 STANDARD MODES:
 To make the kernel prompt for standard video modes use: vga=ask

 FRAMEBUFFER MODES:
 To get the kernel to start in VESA framebuffer mode, you need to pass it
 a vga= init string on the "boot:" prompt. Here's a table:

   Colors   640x480 800x600 1024x768 1280x1024 1600x1200
  --------+---------------------------------------------
  256     |   769     771      773      775       796
  32,768  |   784     787      790      793       797
  65,536  |   785     788      791      794       798
  16.8M   |   786     789      792      795       799

  ...such as this for 1024x768x64k:
   vga=791

  F2 returns to the previous page.

EOF
   umount /dev/fd0
   syslinux-nomtools -s /dev/fd0
   rm -r $TMP/bootdisk
  fi
 elif [ "$REPLY" = "lilo" ]; then # make lilo bootdisk
  DEFAULT_ITEM="exit"
  if [ ! -x "`type -path lilo`" ]; then
cat << EOF > $TMP/tmpmsg

You don't have 'lilo' installed on the system.
I guess you didn't install the lilo package.
 
EOF
   dialog --title "LILO NOT FOUND" --msgbox "`cat $TMP/tmpmsg`" 8 60
   continue
  fi
  if [ "$KERNEL" = "" ]; then
   choose_kernel
  fi
  dialog --title "CREATING LILO BOOTDISK IN /dev/fd0" --backtitle "$KMSG" --yesno "Now put a \
floppy in your boot drive. This will be made into a LILO \
bootdisk that you can use to start your Linux system. Any data on the \
target disk will be destroyed. YES creates the disk, NO aborts." 8 62
  if [ $? = 0 ]; then # make the disk
   format_disk
   DEV=/dev/fd0u1680
   mknod_fd="-m 0640 $TMP/lilo$DEV b 2 44"
   dialog --infobox "Creating LILO bootdisk from $KERNEL for $ROOT_DEVICE..." 4 60
   mke2fs -q -m 0 -i 4096 $DEV 1> /dev/null 2> /dev/null || exit 1
   if [ ! -d $TMP/lilo ]; then
    mkdir -p $TMP/lilo
   fi
   mount -t ext2 $DEV $TMP/lilo 1> /dev/null || exit 1
   rmdir $TMP/lilo/lost+found
   cp $KERNEL $TMP/lilo/vmlinuz || exit 1
   mkdir $TMP/lilo/dev
   make_root_device
   mknod -m 0640 $TMP/lilo/dev/fd0 b 2 0
   mknod -m 0640 $TMP/lilo/dev/fd1 b 2 1
   mknod $mknod_fd
   mknod -m 0666 $TMP/lilo/dev/null c 1 3
   mkdir $TMP/lilo/etc
   cat << EOF > $TMP/lilo/etc/lilo.conf
boot = $DEV
message=/boot/message
backup=/dev/null
prompt
image = /vmlinuz
        label = mount
        ramdisk = 0
        root = $ROOT_DEVICE
        vga = normal
        $MOUNT
EOF
   mkdir $TMP/lilo/boot
   cp -a /boot/chain.b $TMP/lilo/boot
   if [ -f /boot/boot-text.b ]; then
   cp -a /boot/boot-text.b $TMP/lilo/boot/boot.b
   else
   cp -a /boot/boot.b $TMP/lilo/boot
   fi   
   cat << EOF > $TMP/lilo/boot/message

Welcome to the Slackware Linux custom LILO bootdisk!  

By default, this disk boots a root Linux partition on $ROOT_DEVICE when
you hit ENTER. If you'd like to boot some other partition, use a command
like this on the LILO prompt below:

    mount root=/dev/sda1 ro

Where "/dev/sda1" is the partition you want to boot, and "ro" specifies that
the partition should be initially mounted as read-only. If you which to mount
the partition read-write, use "rw" instead. You may also add any other kernel
parameters you might need depending on your hardware, and which drivers are
included in your kernel.

EOF
   lilo -r $TMP/lilo > /dev/null
   umount $TMP/lilo
   rm -rf $TMP/lilo
  fi
 elif [ "$REPLY" = "exit" ]; then
  break;
 fi
done