slitaz-tools view tinyutils/bootfloppybox @ rev 266

bootfloppybox: fix floppy path
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Aug 18 09:49:16 2008 +0000 (2008-08-18)
parents b6ce1001af64
children d6cd1cfc7fe1
line source
1 #! /bin/sh
2 #
3 # Gtkdialog box for the mount command. Part of SliTaz tools.
4 #
5 VERSION=20080818
6 PLOP_URL=http://download.plop.at/plop/bootmngr/plpbt50rc12flp.zip
8 # Check if user is root.
9 check_root()
10 {
11 if test $(id -u) != 0 ; then
12 echo -e "
13 You must be root to run `basename $0`. Please type 'su' and
14 root password to become super-user.\n"
15 exit 0
16 fi
17 }
19 # This function is used after each screen to contine or abort install.
20 check_retval()
21 {
22 case $retval in
23 1)
24 rm -f /tmp/floppybox.grub.menu
25 echo -e "\nVoluntary exit.\n" && exit 0 ;;
26 255)
27 rm -f /tmp/floppybox.grub.menu
28 echo -e "ESC pressed.\n" && exit 0 ;;
29 esac
30 }
32 select_floppy()
33 {
34 DEVICE="$DIALOG --title \" Floppy device \" --backtitle \"Boot Floppy Creation\" --clear --extra-button --extra-label \"Format\" --colors --radiolist \"
35 Select boot device
36 \" 18 70 50"
37 on=on
38 for i in /sys/devices/platform/floppy.*/block:*; do
39 [ -d $i ] || continue
40 DEVICE="$DEVICE /dev/${i#*block:} 'Floppy in ${i#*block:}' $on"
41 on=off
42 done
43 DEVICE="$DEVICE cdrom \"cdrom image file boot.iso\" $on 2>&1 1>&3"
44 exec 3>&1
45 DEVICE=`eval $DEVICE`
46 retval=$?
47 exec 3>&-
48 check_retval
49 if [ "$retval" = "3" ]; then
50 case "$DEVICE" in
51 /dev/*) fdformat -n $DEVICE;;
52 esac
53 fi
54 }
56 install_grub()
57 {
58 case "$DEVICE" in
59 /dev/*)
60 mke2fs $DEVICE
61 mkdir /media/floppy
62 mount $DEVICE /media/floppy
63 mkdir -p /media/floppy/boot/grub
64 cp /usr/lib/grub/i386-pc/stage? /media/floppy/boot/grub
65 cp -a $1 /media/floppy
66 grub-set-default --root-directory=/media/floppy 0
67 umount $DEVICE
68 grub --batch <<EOT
69 root (${DEVICE#/dev/})
70 setup (${DEVICE#/dev/})
71 quit
72 EOT
73 ;;
74 cdrom*)
75 mkdir -p $1/boot/grub 2> /dev/null
76 cp /usr/lib/grub/i386-pc/stage2_eltorito $1/boot/grub
77 genisoimage -R -o boot.iso -b boot/grub/stage2_eltorito \
78 -c boot/boot.cat -no-emul-boot -boot-load-size 4 \
79 -input-charset iso8859-1 -boot-info-table $1
80 ;;
81 esac
82 }
84 while true; do
86 if [ "$1" == "call" ]; then
87 case "$2" in
88 install)
89 DIR=/tmp/mkbootfloppy$$
90 mkdir -p $DIR
91 DEVICE=$4
92 file=$5
93 case "$3" in
94 grub)
95 mkdir -p $DIR/boot/grub
96 cp /tmp/floppybox.grub.menu $DIR/boot/grub/menu.lst
97 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ]\
98 && cat /usr/share/boot/btmgr /dev/zero | \
99 dd bs=18k count=80 | gzip -9 > \
100 $DIR/boot/btmgr.gz \
101 && unlzma -c /usr/share/boot/memdisk.lzma > \
102 $DIR/boot/memdisk
103 [ -f /usr/share/boot/plop.gz -a \
104 -f /usr/share/boot/memdisk.lzma ]\
105 && zcat /usr/share/boot/plop.gz | cat - /dev/zero | \
106 dd bs=18k count=80 | gzip -9 > \
107 $DIR/boot/plop.gz \
108 && unlzma -c /usr/share/boot/memdisk.lzma > \
109 $DIR/boot/memdisk
110 [ -f /usr/share/boot/etherboot ]\
111 && cp /usr/share/boot/etherboot $DIR/boot
112 [ -f /boot/gpxe ]\
113 && cp /boot/gpxe $DIR/boot
114 [ -f /usr/share/boot/memtest.lzma ]\
115 && unlzma -c /usr/share/boot/memtest.lzma > \
116 $DIR/boot/memtest
117 [ -f /usr/share/boot/grub.exe.lzma ]\
118 && unlzma -c /usr/share/boot/grub.exe.lzma > \
119 $DIR/boot/grub.exe
120 install_grub $DIR
121 ;;
122 *)
123 case "$file" in
124 *.lzma) action="unlzma -c";;
125 *.gz) action="zcat";;
126 *) action="cat";;
127 esac
128 case "$DEVICE" in
129 /dev/*) $action $file > $DEVICE;;
130 cdrom*)
131 mkdir -p $DIR/boot/grub
132 case "$3" in
133 btmgr|plop)
134 $action $file | cat - /dev/zero | \
135 dd bs=18k count=80 | \
136 gzip -9 > $DIR/boot/$3.gz
137 unlzma -c /usr/share/boot/memdisk.lzma \
138 > $DIR/boot/memdisk
139 cat > $DIR/boot/grub/menu.lst << EOT
140 timeout 0
141 title $3
142 kernel /boot/memdisk floppy c=80 h=2 s=18
143 initrd /boot/$3.gz
144 EOT
145 ;;
146 *) $action $file > $DIR/boot/$3
147 cat > $DIR/boot/grub/menu.lst << EOT
148 timeout 0
149 title $3
150 kernel /boot/$3
151 EOT
152 ;;
153 esac
154 install_grub $DIR
155 ;;
156 esac
157 ;;
158 esac
159 rm -rf $DIR
160 ;;
161 get-plop)
162 mkdir -p /tmp/get-plop$$/plop-1.0/fs/$(dirname $3)
163 wget -O - $PLOP_URL | unzip -p /dev/stdin | dd bs=18k count=6 |\
164 gzip -9 > /tmp/get-plop$$/plop-1.0/fs/$3
165 if [ -s /tmp/get-plop$$/plop-1.0/fs/$3 ]; then
166 cat > /tmp/get-plop$$/plop-1.0/receipt <<EOT
167 PACKAGE="plop"
168 VERSION="1.0"
169 CATEGORY="non-free"
170 SHORT_DESC="Plop boot manager."
171 WEB_SITE="http://www.plop.at/en/bootmanager.html"
172 EOT
173 ( cd /tmp/get-plop$$ ; tazpkg pack plop-1.0 )
174 tazpkg install /tmp/get-plop$$/plop-1.0.tazpkg
175 fi
176 rm -rf /tmp/get-plop$$
177 ;;
178 *) echo "Invalid command $0 $@" 1>&2
179 exit 1;;
180 esac
181 exit 0
182 fi
184 cat > /tmp/floppybox.grub.menu <<EOT
185 default saved
186 timeout 8
187 color yellow/brown light-green/black
189 EOT
190 [ -f /boot/gpxe ] && cat >> /tmp/floppybox.grub.menu <<EOT
191 title gPXE (Boot from the Web, PXE/iSCSI/AoE support)
192 kernel /boot/gpxe $(dd if=/boot/gpxe bs=1 skip=519 count=255 2>/dev/null | strings)
194 EOT
195 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ]\
196 && cat >> /tmp/floppybox.grub.menu <<EOT
197 title Smart Boot Manager (text - boot floppy, hard disk or CD/DVD)
198 kernel /boot/memdisk floppy c=80 h=2 s=18
199 initrd /boot/btmgr.gz
201 EOT
202 [ -f /usr/share/boot/plop.gz -a -f /usr/share/boot/memdisk.lzma ]\
203 && cat >> /tmp/floppybox.grub.menu <<EOT
204 title Plop Boot Manager (graphic - boot floppy, hard disk, CD/DVD or USB)
205 kernel /boot/memdisk floppy c=80 h=2 s=18
206 initrd /boot/plop.gz
208 EOT
209 cat >> /tmp/floppybox.grub.menu <<EOT
210 title Windows (example on /dev/hda1)
211 rootnoverify (hd0,0)
212 chainloader +1
213 save default
215 title Slitaz Live (example on /dev/hda1)
216 root (hd0,0)
217 kernel /boot/bzImage rw root=/dev/null vga=normal
218 initrd /boot/rootfs.gz
219 save default
221 title Slitaz Installed (example on /dev/hda2)
222 root (hd0,1)
223 kernel /boot/bzImage ro root=/dev/hda2 vga=normal
224 save default
226 EOT
227 [ -f /usr/share/boot/etherboot ] && cat >> /tmp/floppybox.grub.menu <<EOT
228 title Etherboot (LAN boot, PXE or NBI)
229 kernel /boot/etherboot
231 EOT
232 [ -f /usr/share/boot/memtest.lzma ] && cat >> /tmp/floppybox.grub.menu <<EOT
233 title Memtest86+ (Test system memory)
234 kernel /boot/memtest
236 EOT
237 [ -f /usr/share/boot/grub.exe.lzma ] && cat >> /tmp/floppybox.grub.menu <<EOT
238 title Grub4Dos
239 kernel /boot/grub/grub.exe --config-file="configfile (fd0)/boot/grub/menu4dos.lst"
241 EOT
243 if [ -z "$XAUTHORITY" ]; then
245 : ${DIALOG=dialog}
247 DEVICE=/dev/fd0
248 while true; do
249 exec 3>&1
250 ID_SOURCE=`$DIALOG --title " Choose a boot floppy " \
251 --backtitle "Boot Floppy Creation on $DEVICE" --clear \
252 --extra-button --extra-label "Change floppy" \
253 --yes-label "Install" \
254 --no-label "Quit" \
255 --colors --radiolist "
256 Create a floppy or a cdrom to boot a LiveCD, in a PXE network...
257 May need a floppy disk in drive. Erase the whole floppy disk.
258 " 18 70 50\
259 SmartBtmgr "Boot any partition or ATAPI CD-ROM." on \
260 Plop "Boot harddisk floppy CD/DVD or USB." off \
261 Etherboot "Replacement for proprietary PXE ROMs." off \
262 gPXE "Boot from http://boot.slitaz.org/" off \
263 Memtest86+ "Memory failures detection tool." off \
264 Grub "Boot loader with command shell." off 2>&1 1>&3`
265 retval=$?
266 exec 3>&-
267 check_retval
268 if [ "$retval" = "3" ]; then
269 select_floppy
270 continue;
271 fi
272 while read key file pkg; do
273 [ "$key" = "$ID_SOURCE" ] || continue
274 if [ ! -f "$file" ]; then
275 $DIALOG --title " Install package " --colors \
276 --backtitle "Boot Floppy Creation" --clear \
277 --yes-label "Install" \
278 --no-label "Quit" \
279 --yesno "The package $pkg is not yet installed. Install it ?" 18 70
280 retval=$?
281 if [ "$pkg" = "plop" ]; then
282 bootfloppybox call get-plop $file
283 else
284 tazpkg get-install $pkg
285 fi
286 fi
287 bootfloppybox call install "$pkg" "$DEVICE" "$file"
288 exit 0
289 done <<EOT
290 SmartBtmgr /usr/share/boot/btmgr btmgr
291 Plop /usr/share/boot/plop.gz plop
292 Etherboot /usr/share/boot/etherboot etherboot
293 gPXE /boot/gpxe gpxe
294 Memtest86+ /usr/share/boot/memtest.lzma memtest
295 Grub /usr/sbin/grub grub
296 EOT
297 done
298 fi
299 #
300 # Describe gPXE arguments.
301 #
302 export HELP='
303 <window title="gPXE forced url" icon-name="gtk-floppy">
304 <vbox>
305 <text use-markup="true">
306 <label>"
307 <b>Web boot parameters</b>"
308 </label>
309 </text>
310 <frame>
311 <text wrap="true" width-chars="58" use-markup="true">
312 <label>
313 "Without parameters (i.e. with an empty Boot URL) gPXE will perform a normal
314 PXE boot: IP configuration with DHCP and download DHCP bootfile with TFTP.
316 You can override the DHCP bootfile with an Boot URL such as
317 <i>tftp://192.168.0.1/pxe/pxeloader</i>, <i>http://mirror.slitaz.org/pxe/pxelinux.0</i>,
318 or <i>x-tftm://192.168.0.201//lts/vmlinuz.ltsp</i>.
320 You can override IP configuration too (usefull without DHCP server), example:
321 <i>ip=192.168.0.10/24 gw=192.168.0.1 dns=192.168.0.1 nodhcp
322 url=http://mirror.slitaz.org/pxe/pxelinux.0</i>
324 The <i>nodhcp</i> keyword avoids dhcp timeouts and the <i>url=</i> keyword is
325 optionnal when the url is the only argument.
326 "
327 </label>
328 </text>
329 </frame>
330 </vbox>
331 </window>
332 '
333 #
334 # Write bootfloppy image to floppy device.
335 #
336 BOOT_DIALOG='
337 <window title="bootfloppybox" icon-name="gtk-floppy">
338 <vbox>
340 <text use-markup="true">
341 <label>
342 "
343 <b>SliTaz - Bootfloppybox</b>"
344 </label>
345 </text>
346 <text wrap="false" width-chars="44" use-markup="true">
347 <label>
348 "
349 Create a floppy or a cdrom to boot a LiveCD, in a PXE network or WEB...
350 May need a floppy disk in drive. Erase the whole floppy disk.
351 "
352 </label>
353 </text>
355 <frame Floppy disk drive>
356 <hbox>
357 <text use-markup="true">
358 <label>"<b>Device : </b>"</label>
359 </text>
360 <combobox>
361 <variable>DEVICE</variable>'
362 for i in /sys/devices/platform/floppy.*/block:*; do
363 [ -d $i ] || continue
364 BOOT_DIALOG="$BOOT_DIALOG
365 <item>/dev/${i#*block:}</item>"
366 on=off
367 done
368 tmp=' <item>cdrom image (boot.iso)</item>
369 </combobox>
370 <button>
371 <label>Format floppy</label>
372 <input file icon="forward"></input>
373 <action>case "$DEVICE" in /dev/*) fdformat -n $DEVICE;; esac</action>
374 </button>
375 </hbox>
376 </frame>
377 <notebook labels="LiveCD|USB|PXE Network|WEB Network|Memory Test|Expert">
378 '
379 BOOT_DIALOG="$BOOT_DIALOG$tmp"
380 while read name file pkg desc; do
381 tmp="<frame $name>
382 <hbox>
383 <text wrap=\"true\" width-chars=\"44\" use-markup=\"true\">
384 <label>
385 \"
386 $(echo -e $desc)
387 \"
388 </label>
389 </text>
390 </hbox>
391 <hbox>
392 "
393 if [ -f $file ]; then
394 if [ "$pkg" = "grub" ]; then
395 tmp="$tmp
396 <button>
397 <label>Grub menu</label>
398 <input file icon=\"accessories-text-editor\"></input>
399 <action type=\"lauch\">leafpad /tmp/floppybox.grub.menu</action>
400 </button>
401 "
402 elif [ "$pkg" = "gpxe" ]; then
403 tmp="$tmp
404 <text wrap=\"true\" use-markup=\"true\">
405 <label> \"<b>Boot URL:</b>\" </label>
406 </text>
407 <entry>
408 <default>$(dd if=$file bs=1 skip=519 count=255 2>/dev/null | strings)</default>
409 <variable>URL</variable>
410 </entry>
411 </hbox>
412 <hbox>
413 <button help>
414 <action type=\"launch\">HELP</action>
415 </button>
416 <button>
417 <label>Update</label>
418 <input file icon=\"reload\"></input>
419 <action>echo -n \"\$URL\" | cat - /dev/zero | dd conv=notrunc bs=1 count=255 seek=519 of=$file 2>/dev/null</action>
420 </button>
421 "
422 fi
423 tmp="$tmp
424 <button>
425 <label>Write floppy</label>
426 <input file icon=\"forward\"></input>
427 <action>bootfloppybox call install \"$pkg\" \"\$DEVICE\" \"$file\"</action>
428 </button>
429 </hbox>
430 </frame>
431 "
432 else
433 tmp2="tazpkg get-install $pkg --forced"
434 [ "$pkg" = "plop" ] && tmp2="bootfloppybox call get-plop $file"
435 tmp="$tmp
436 <text wrap=\"true\" width-chars=\"34\" use-markup=\"true\">
437 <label>
438 \"<i>The package <b>$pkg</b> is not yet installed</i>\"
439 </label>
440 </text>
441 <button>
442 <input file icon=\"go-jump\"></input>
443 <label>Install</label>
444 <action>[ -f /var/lib/tazpkg/packages.list ] || tazpkg recharge</action>
445 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title \"$pkg install\" -e \"$tmp2 ; sleep 2\"</action>
446 <action type=\"exit\">restart</action>
447 </button>
448 </hbox>
449 </frame>
450 "
451 fi
452 BOOT_DIALOG="$BOOT_DIALOG$tmp"
453 done <<EOT
454 SmartBtmgr /usr/share/boot/btmgr btmgr This OS independent Smart Boot Manager can boot any partition or ATAPI CD-ROM.
455 Plop /usr/share/boot/plop.gz plop This non free Boot Manager can boot floppy, hardisk, USB or CD/DVD. Hit Ctrl-ESC for text mode.
456 Etherboot /usr/share/boot/etherboot etherboot This network bootloader provides a replacement for proprietary PXE or NBI ROMs.
457 gPXE /boot/gpxe gpxe PXE / iSCSI / AoE network bootloader.
458 Memtest86+ /usr/share/boot/memtest.lzma memtest Memory failures detection tool.
459 Grub /usr/sbin/grub grub General purpose boot loader with command shell
460 EOT
461 tmp='
462 </notebook>
463 <hbox>
464 <button>
465 <input file icon="exit"></input>
466 <label>Exit</label>
467 <action type="exit">Exit</action>
468 </button>
469 </hbox>
471 </vbox>
472 </window>
473 '
474 BOOT_DIALOG="$BOOT_DIALOG$tmp"
475 export BOOT_DIALOG
477 # Only root can create floppy.
478 check_root
479 gtkdialog --program=BOOT_DIALOG | grep -q 'EXIT="restart"' && continue
480 rm -f /tmp/floppybox.grub.menu
481 exit 0
482 done