slitaz-tools view tinyutils/bootfloppybox @ rev 656

tazinst: showurl+check commands added
author Dominique Corbex <domcox@slitaz.org>
date Mon Jul 25 12:03:18 2011 +0200 (2011-07-25)
parents 4a255568f7fa
children 6e43ed33b6ed
line source
1 #! /bin/sh
2 #
3 # Gtkdialog box for the mount command. Part of SliTaz tools.
4 #
5 VERSION=20100701
7 # Check if user is root.
8 check_root()
9 {
10 if test $(id -u) != 0 ; then
11 echo -e "
12 You must be root to run `basename $0`. Please type 'su' and
13 root password to become super-user.\n"
14 exit 0
15 fi
16 }
18 # This function is used after each screen to continue or abort install.
19 check_retval()
20 {
21 case $retval in
22 1)
23 rm -f /tmp/floppybox.grub.menu
24 echo -e "\nVoluntary exit.\n" && exit 0 ;;
25 255)
26 rm -f /tmp/floppybox.grub.menu
27 echo -e "ESC pressed.\n" && exit 0 ;;
28 esac
29 }
31 # Trigger floppy driver to update /sys/devices/platform/
32 dd if=/dev/fd0 bs=1k count=1 > /dev/null 2>&1
34 # check or list floppy devices.
35 list_floppy()
36 {
37 local list
38 list=""
39 for i in /sys/devices/platform/floppy.*/block/*; do
40 [ -d $i ] || continue
41 list="$list $(basename $i)"
42 done
43 [ -n "$1" ] || echo $list
44 [ -n "$list" ]
45 }
47 # dialog to select the floppy device
48 select_floppy()
49 {
50 DEVICE="$DIALOG --title \" Floppy device \" --backtitle \"Boot Floppy Creation\" --clear --extra-button --extra-label \"Format\" --colors --radiolist \"
51 Select boot device
52 \" 18 70 50"
53 on=on
54 for i in $(list_floppy); do
55 DEVICE="$DEVICE /dev/$i 'Floppy in $i' $on"
56 on=off
57 done
58 DEVICE="$DEVICE floppy \"floppy image file boot.fd\" $on"
59 DEVICE="$DEVICE cdrom \"cdrom image file boot.iso\" off 2>&1 1>&3"
60 exec 3>&1
61 DEVICE=`eval $DEVICE`
62 retval=$?
63 exec 3>&-
64 check_retval
65 if [ "$retval" = "3" ]; then
66 case "$DEVICE" in
67 /dev/*) fdformat -n $DEVICE;;
68 esac
69 fi
70 }
72 # Build menu for grub or grub4dos
73 mkmenu()
74 {
75 if [ "$1" = "grub4dos" ]; then
76 SAVEDEFAULT="save default"
77 cat > /tmp/floppybox.grub.menu <<EOT
78 # grub4dos menu
79 default /default
80 EOT
81 else
82 SAVEDEFAULT="savedefault"
83 cat > /tmp/floppybox.grub.menu <<EOT
84 # grub menu
85 default saved
86 EOT
87 fi
88 cat >> /tmp/floppybox.grub.menu <<EOT
89 timeout 8
90 color yellow/brown light-green/black
92 EOT
93 entry=0
94 [ -f /boot/gpxe ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
95 title gPXE (Boot from the Web, PXE/iSCSI/AoE support)
96 kernel /boot/gpxe $(dd if=/boot/gpxe bs=1 skip=519 count=255 2>/dev/null | strings)
98 EOT
99 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ] \
100 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
101 title Smart Boot Manager (text - boot floppy, hard disk or CD/DVD)
102 kernel /boot/memdisk floppy c=80 h=2 s=18
103 initrd /boot/btmgr.gz
105 EOT
106 http://mirror.slitaz.org/boot/plpbt.bin
107 [ -f /usr/share/boot/plpbt.bin ] \
108 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
109 title Plop Boot Manager (graphic - boot floppy, hard disk, CD/DVD or USB)
110 kernel /boot/plpbt.bin
112 EOT
113 [ -f /usr/share/boot/etherboot ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
114 title Etherboot (LAN boot, PXE or NBI)
115 kernel /boot/etherboot
117 EOT
118 [ -f /usr/share/boot/memtest.lzma -a -f /usr/share/boot/memdisk.lzma ] \
119 && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
120 title Memtest86+ (Test system memory)
121 kernel /boot/memdisk floppy c=80 h=2 s=18
122 initrd /boot/memtest.gz
124 EOT
125 [ "$1" = "grub4dos" ] && entry=$(($entry + 3)) && cat >> /tmp/floppybox.grub.menu <<EOT
126 title Windows (scan ntldr)
127 fallback $(($entry -3 + 1))
128 find --set-root /ntldr
129 chainloader /ntldr
130 $SAVEDEFAULT --wait=2
132 title Windows (scan cmldr)
133 fallback $(($entry -3 + 2))
134 find --set-root /cmldr
135 chainloader /cmldr
136 $SAVEDEFAULT --wait=2
138 title Windows (scan io.sys)
139 fallback $(($entry -3 + 3))
140 find --set-root /io.sys
141 chainloader /io.sys
142 $SAVEDEFAULT --wait=2
144 EOT
145 entry=$(($entry + 3)) && cat >> /tmp/floppybox.grub.menu <<EOT
146 title Windows (example on /dev/hda1)
147 rootnoverify (hd0,0)
148 chainloader +1
149 $SAVEDEFAULT
151 title Slitaz Frugal (example on /dev/hda1)
152 root (hd0,0)
153 kernel /boot/bzImage rw root=/dev/null vga=normal
154 initrd /boot/rootfs.gz
155 $SAVEDEFAULT
157 title Slitaz Installed (example on /dev/hda2)
158 root (hd0,1)
159 kernel /boot/bzImage ro root=/dev/hda2 vga=normal
160 $SAVEDEFAULT
162 EOT
163 [ "$1" = "grub4dos" ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
164 title Slitaz cdrom image (example on /dev/hda1, DEFRAGMENTED)
165 map (hd0,0)/boot/slitaz-cooking.iso (hd1)
166 map --hook
167 kernel (hd1)/boot/bzImage rw root=/dev/null vga=normal
168 initrd (hd1)/boot/rootfs.gz
169 $SAVEDEFAULT
171 EOT
172 false && [ -f /usr/share/boot/grub.exe.lzma ] && entry=$(($entry + 1)) && cat >> /tmp/floppybox.grub.menu <<EOT
173 title Grub4Dos
174 kernel /boot/grub/grub.exe --config-file="configfile (fd0)/boot/grub/menu4dos.lst"
176 EOT
177 }
179 # Install grub or grub4dos on floppy
180 install_grub()
181 {
182 LOOP=""
183 GRUB_DEV=${DEVICE#/dev/}
184 GRUB_DEV=${GRUB_DEV%% *}
185 case "$DEVICE" in
186 floppy*)
187 LOOP="-o loop"
188 GRUB_DEV=fd0
189 DEVICE=boot.fd
190 dd if=/dev/zero of=$DEVICE bs=18k count=80;;
191 esac
192 grep -qs "^# $2 menu" /tmp/floppybox.grub.menu || mkmenu $2
193 case "$DEVICE" in
194 /dev/*|boot.fd)
195 yes y | mke2fs $DEVICE
196 mkdir /media/floppy
197 mount $LOOP $DEVICE /media/floppy
198 if [ "$2" = "grub4dos" ]; then
199 mkdir -p /media/floppy/boot
200 unlzma -c /usr/share/boot/grldr.lzma > /media/floppy/grldr
201 cp $1/boot/* /media/floppy/boot 2> /dev/null
202 cp /tmp/floppybox.grub.menu /media/floppy/menu.lst
203 umount -d /media/floppy
204 bootlace --floppy --sectors-per-track=18 --heads=2 \
205 --chs --ext2 $DEVICE
206 else
207 mkdir -p /media/floppy/boot/grub
208 cp /usr/lib/grub/i386-pc/stage? /media/floppy/boot/grub
209 cp -a $1/boot /media/floppy
210 cp /tmp/floppybox.grub.menu /media/floppy/boot/grub/menu.lst
211 grub-set-default --root-directory=/media/floppy 0
212 echo "($GRUB_DEV) $(losetup | grep $DEVICE | cut -d: -f1)" > $1/device.map
213 [ -n "$LOOP" ] && LOOP="--device-map=$1/device.map"
214 grub $LOOP --batch <<EOT
215 root ($GRUB_DEV)
216 setup ($GRUB_DEV)
217 quit
218 EOT
219 umount -d /media/floppy
220 fi ;;
221 cdrom*)
222 mkdir -p $1/boot/grub 2> /dev/null
223 cp /tmp/floppybox.grub.menu $1/boot/grub/menu.lst
224 if [ "$2" = "grub4dos" ]; then
225 unlzma -c /usr/share/boot/grldr.lzma > $1/boot/grub/grldr
226 genisoimage -R -o boot.iso -b boot/grub/grldr \
227 -c boot/boot.cat -no-emul-boot -boot-load-seg 0x1000 \
228 -hide boot/boot.cat -input-charset iso8859-1 $1
229 else
230 cp /usr/lib/grub/i386-pc/stage2_eltorito $1/boot/grub
231 genisoimage -R -o boot.iso -b boot/grub/stage2_eltorito \
232 -c boot/boot.cat -no-emul-boot -boot-load-size 4 \
233 -hide boot/boot.cat -input-charset iso8859-1 \
234 -boot-info-table $1
235 fi ;;
236 esac
237 }
239 # Build /init for floppies from iso image
240 buildinit()
241 {
242 mv $1/init $1/init.org
243 for i in /dev/tty0 /dev/[sh]d[ab]? ; do
244 [ -e $1$i ] || cp -a $i $1/dev
245 done
246 cat > $1/init <<EOTEOT
247 #!/bin/sh
249 cat_floppy()
250 {
251 tmp="\$(dd if=/dev/fd0 count=1 2> /dev/null | md5sum)"
252 echo -n "Insert floppy \$num for \$name and press Enter or Q to skip"
253 while true; do
254 echo -n ":"
255 read -t 10 answer < /dev/tty0
256 case "\$answer" in
257 Q*|q*|A*|a*) break 3;;
258 esac
259 dd if=/dev/fd0 count=1 > /tmp/bs.\$\$ 2> /dev/null
260 [ -s /tmp/bs.\$\$ ] || continue
261 [ "\$(md5sum < /tmp/bs.\$\$)" != "\$tmp" ] || continue
262 rm -f /tmp/bs.\$\$
263 break
264 done
265 dd if=/dev/fd0 of=/tmp/rootfs.\$num 2> /dev/null || continue
266 cat /tmp/rootfs.\$num >> \$1
267 rm -f /tmp/rootfs.\$num
268 num=\$((\$num+1))
269 }
271 mount -t proc proc /proc
272 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
273 # the floppy driver may not be included in kernel
274 insmod /lib/modules/*/kernel/drivers/block/floppy.ko.gz 2> /dev/null
275 # loram may put floppy.ko.gz module in /lib
276 insmod /lib/floppy.ko.gz 2> /dev/null
277 if [ ! -x /sbin/blkid ]; then
278 cat <<EOT
280 You can preinstall SliTaz in an ext3 partition with this floppy set.
282 Simply enter the device name (/dev/XXXX) to create the slitaz/install.sh or
283 leave it blank to skip :
284 EOT
285 read -t 60 device < /dev/tty0
286 [ -n "\$device" ] && mount \$device /mnt && mkdir /mnt/slitaz
287 elif blkid | grep -q 'TYPE="ext'; then
288 cat <<EOT
290 You can preinstall SliTaz in one of these ext3 partitions:
291 \$(blkid | grep 'TYPE="ext')
293 Simply enter the device name (/dev/XXXX) to create the slitaz/install.sh or
294 leave it blank to skip :
295 EOT
296 read -t 60 device < /dev/tty0
297 [ -n "\$device" ] && mount \$device /mnt && mkdir /mnt/slitaz
298 else
299 cat <<EOT
301 You can preinstall SliTaz in an ext3 partition with this floppy set.
302 After the boot process is completed, create a partition with 'fdisk',
303 format it with 'mke2fs -j' and reboot from the floppies again.
305 EOT
306 fi
307 umount /proc
308 while read name min num count file md5; do
309 [ -e \$file ] && continue
310 [ \$total -lt \$min ] && break
311 while [ \$count -ne 0 ]; do
312 cat_floppy /tmp/rootfs
313 count=\$((\$count-1))
314 done
315 echo "\$md5 /tmp/rootfs" | md5sum -c || break
316 cpio -idmu < /tmp/rootfs > /dev/null 2>&1 ||
317 ( zcat /tmp/rootfs 2> /dev/null || unlzma -c /tmp/rootfs ) | cpio -idmu
318 if [ -d /mnt/slitaz ]; then
319 cp /tmp/rootfs /mnt/slitaz/rootfs.\$num ||
320 mv -f /mnt/slitaz /mnt/slitaz-aborted
321 fi
322 rootfslist="\$rootfslist \$num"
323 rm -f /tmp/rootfs*
324 done <<EOT
325 $(while read line; do echo $line; done)
326 EOT
327 if [ -d /mnt/slitaz ]; then
328 cat > /mnt/slitaz/install.sh <<EOT
329 #!/bin/sh
331 if [ -z "\\\$1" ]; then
332 echo "Usage: \\\$0 target-directory"
333 exit 1
334 fi
335 dir=\\\$(cd \\\$(dirname \\\$0); pwd)
336 cd \\\$1
337 for i in 0 \$rootfslist ; do
338 [ -s \\\$dir/rootfs.\\\$i ] || continue
339 cpio -idmu < \\\$dir/rootfs.\\\$i > /dev/null 2>&1 ||
340 ( zcat \\\$dir/rootfs.\\\$i 2> /dev/null || unlzma -c \\\$dir/rootfs.\\\$i ) | cpio -idmu
341 done
342 if ! mv -f init.org init 2> /dev/null; then
343 for i in \\\$(ls rootfs*gz | sed '1!G;h;\\\$!d'); do
344 mount -o loop,ro \\\$i /media/cdrom && rm -f \\\$i
345 cp -a /media/cdrom/. .
346 umount -d /media/cdrom
347 done
348 fi
349 mkdir boot && cp \\\$dir/bzImage boot
350 cp -a /usr/lib/grub/i386-pc boot/grub
351 cat > boot/grub/menu.lst<<EOF
352 # /boot/grub/menu.lst: GRUB boot loader configuration.
353 #
355 # By default, boot the first entry.
356 default 0
358 # Boot automatically after 8 secs.
359 timeout 8
361 # Change the colors.
362 color yellow/brown light-green/black
364 title SliTaz GNU/Linux
365 kernel /boot/bzImage root=\$device
367 EOF
368 grub-install --no-floppy --root-directory=\\\$PWD \${device%[1-9]*}
369 cd -
370 EOT
371 chmod +x /mnt/slitaz/install.sh
372 num=1
373 name="the Linux kernel"
374 dd count=0 of=/mnt/slitaz/bzImage.fd > /dev/null 2>&1
375 fullsize=1
376 while [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$fullsize ]; do
377 cat_floppy /mnt/slitaz/bzImage.fd
378 setup=\$(dd if=/mnt/slitaz/bzImage.fd skip=497 bs=1 count=1 2> /dev/null | hexdump -e '"" 1/1 "%d" "\n"')
379 syssize=\$(dd if=/mnt/slitaz/bzImage.fd skip=500 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
380 cmdline=\$(dd if=/mnt/slitaz/bzImage.fd skip=552 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
381 initrd=\$(dd if=/mnt/slitaz/bzImage.fd skip=540 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
382 [ \$cmdline -eq 0 ] || cmdline=512
383 size=\$((512 + \$setup * 512 + \$cmdline + \$syssize * 16))
384 [ -s /etc/slitaz-release ] || initrd=0
385 fullsize=\$((\$size + \$initrd + 512))
386 [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$size ] ||
387 name="the first initramfs"
388 done
389 [ -s /etc/slitaz-release ] &&
390 dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512+(31+\$syssize)/32)) > /mnt/slitaz/rootfs.0 &&
391 dd bs=1 seek=\$initrd count=0 of=/mnt/slitaz/rootfs.0
392 dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=4 seek=552
393 dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=8 seek=536
394 dd if=/mnt/slitaz/bzImage.fd bs=512 count=\$((\$setup+1)) > /mnt/slitaz/bzImage
395 dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512)) >> /mnt/slitaz/bzImage
396 rm -f /mnt/slitaz/bzImage.fd
397 size=\$((512 + \$setup * 512 + \$syssize * 16))
398 dd bs=1 seek=\$size count=0 of=/mnt/slitaz/bzImage > /dev/null 2>&1
399 [ \$(stat -c %s /mnt/slitaz/bzImage) -eq \$size ] ||
400 mv -f /mnt/slitaz /mnt/slitaz-aborted
401 fi
402 mv -f /init.org /init || sh
403 exec /init
404 EOTEOT
405 chmod +x $1/init
406 }
408 # write a 32 bits data
409 # usage: storelong offset data32 file
410 storelong()
411 {
412 printf "00000 %02X %02X %02X %02X \n" \
413 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \
414 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
415 hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null
416 }
418 # read a 32 bits data
419 # usage: getlong offset file
420 getlong()
421 {
422 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \
423 hexdump -e '"" 1/4 "%d" "\n"'
424 }
426 # output floppy images set
427 floppysetcat()
428 {
429 KERNEL="$1"
430 INITRD="$2"
431 shift 2
432 CMDLINE="$@"
434 # bzImage offsets
435 SetupSzOfs=497
436 SyssizeOfs=500
437 CodeAdrOfs=0x214
438 RamfsAdrOfs=0x218
439 RamfsLenOfs=0x21C
440 ArgPtrOfs=0x228
442 # boot+setup address
443 SetupBase=0x90000
445 stacktop=0x9E00
447 bs=/tmp/bs$$
449 # Get and patch boot sector
450 dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null
451 uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null
452 begin-base64 644 -
453 /L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF
454 +D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl
455 ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc
456 sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW
457 6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b
458 AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB
459 xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC
460 ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0
461 /sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ
462 1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s
463 BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A
464 AA==
465 ====
466 EOT
468 # Get setup
469 setupsz=$(getlong $SetupSzOfs $bs)
470 setupszb=$(( $setupsz & 255 ))
471 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs
473 # Store cmdline after setup
474 if [ -n "$CMDLINE" ]; then
475 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs
476 storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs
477 fi
479 # Compute initramfs size
480 initrdlen=0
481 padding=0
482 for i in $( echo $INITRD | sed 's/,/ /' ); do
483 [ -s "$i" ] || continue
484 initrdlen=$(( $initrdlen + $padding ))
485 padding=$(stat -c %s $i)
486 initrdlen=$(( $initrdlen + $padding ))
487 padding=$(( 4096 - ($padding & 4095) ))
488 [ $padding -eq 4096 ] && padding=0
489 done
490 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 ))
491 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize ))
492 if [ $initrdlen -ne 0 ]; then
493 Kbase=$(getlong $CodeAdrOfs $bs)
494 storelong $RamfsAdrOfs \
495 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs
496 storelong $RamfsLenOfs $initrdlen $bs
497 fi
499 # Output boot sector + setup + cmdline
500 dd if=$bs 2> /dev/null
502 # Output kernel code
503 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null
505 # Pad to next sector
506 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) ))
507 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null
509 # Output initramfs
510 padding=0
511 for i in $( echo $INITRD | sed 's/,/ /' ); do
512 [ -s "$i" ] || continue
513 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding
514 dd if=$i 2> /dev/null
515 padding=$(( 4096 - ($(stat -c %s $i) & 4095) ))
516 [ $padding -eq 4096 ] && padding=0
517 done
519 # Cleanup
520 rm -f $bs
521 }
523 # Create boot floppy set from kernel, initrd & cmdline
524 floppyset()
525 {
526 floppysetcat "$@" | split -b 1440k /dev/stdin floppy$$
527 i=1
528 ls floppy$$* | while read file ; do
529 output=$(printf "fd%03d.img" $i)
530 cat $file /dev/zero | dd bs=1k count=1440 of=$output conv=sync 2> /dev/null
531 rm -f $file
532 i=$(( $i + 1 ))
533 done
534 }
536 # Create boot floppy set from a SliTaz ISO image
537 floppysetfromiso()
538 {
539 mkdir /tmp/iso$$
540 mount -o loop,ro $1 /tmp/iso$$
541 rootfs="$(ls /tmp/iso$$/boot/rootfs*z 2> /dev/null | tail -1)"
542 bzimage=/tmp/iso$$/boot/bzImage
543 if [ -z "$rootfs" -o ! -s $bzimage ]; then
544 umount -d /tmp/iso$$
545 rm -rf /tmp/iso$$
546 echo "Not a SliTaz ISO image !"
547 return 1
548 fi
549 mkdir -p /tmp/rootfs$$/fs
550 n=1
551 for i in $(ls /tmp/iso$$/boot/rootfs*z | sort -r); do
552 mkdir /tmp/rootfs$$/$n
553 ln -s $i /tmp/rootfs$$/$n
554 n=$(($n + 1))
555 done
556 echo "Unpacking rootfs..."
557 ( zcat $rootfs 2> /dev/null | unlzma -c $rootfs ) | \
558 ( cd /tmp/rootfs$$/fs ; cpio -idm > /dev/null )
559 if [ $(unlzma -c $rootfs 2> /dev/null| wc -c) -gt $(stat -c %s $rootfs) ]; then
560 if [ $(du -ck $rootfs $bzimage | awk 'END { print $1 }') -gt 15296 ]; then
561 # The rootfs.gz file is too big, extract a minimum bootfs with busybox stuff
562 echo "Extracting bootfs..."
563 mv /tmp/rootfs$$/fs /tmp/rootfs$$/fs0
564 for i in lib bin sbin usr/bin usr/sbin ; do
565 mkdir -p /tmp/rootfs$$/fs/$i
566 done
567 cd /tmp/rootfs$$/fs0
568 dir=$(echo lib/modules/*/kernel/drivers/block)
569 [ -d $dir ] && mkdir -p ../fs/$dir
570 [ -f $dir/floppy.ko.gz ] && mv $dir/floppy.ko.gz ../fs/$dir
571 for i in dev init mnt proc sys tmp ; do
572 mv $i ../fs
573 done
574 mv lib/ld-* ../fs/lib
575 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so bin/busybox | \
576 awk '/\/lib\/lib/ { print $3 }' | while read lib ; do
577 while [ -L .$lib ]; do
578 local target
579 target="$(readlink ".$lib")"
580 case "$target" in
581 /*) ;;
582 *) target="$(dirname $lib)/$target" ;;
583 esac
584 mv ".$lib" ../fs/lib
585 lib="$target"
586 done
587 mv ".$lib" ../fs/lib
588 done
589 for i in $(bin/busybox | awk '{ if (s) printf "%s",$0 }
590 /Currently/ { s=1 }' | sed 's/,//g'); do
591 for j in bin sbin usr/bin usr/sbin ; do
592 [ -e $j/$i ] && mv $j/$i ../fs/$j/$i
593 done
594 done
595 mv bin/busybox ../fs/bin
596 [ -e ../fs/bin/cpio ] || mv bin/cpio ../fs/bin
597 rm -f ../1/*
598 find | cpio -o -H newc | lzma e ../1/rootfs.gz -si
599 cd - > /dev/null
600 rm -rf /tmp/rootfs$$/fs0
601 else
602 # The rootfs.gz file fits in 15MB, no need to split it.
603 rm -rf /tmp/rootfs$$/1
604 fi
605 else
606 # This is a loram rootfs.gz, extract loram bootstrap
607 echo "Splitting loram rootfs..."
608 offset=$(awk '/07070100/ { o+=index($0,"07070100"); print o/4 ; exit } { o+=1+length() }' < $rootfs)
609 dd if=$rootfs skip=$(($offset / 1024)) bs=4k count=1 2> /dev/null | \
610 dd skip=$(($offset % 1024)) bs=4 of=/tmp/rootfs$$/1/root 2> /dev/null
611 dd if=$rootfs skip=$((1 + ($offset / 1024) )) bs=4k \
612 >> /tmp/rootfs$$/1/root 2> /dev/null
613 rm -f /tmp/rootfs$$/1/rootfs*
614 fi
615 # Create extra rootfs floppies
616 for i in /tmp/rootfs$$/[1-9]*/root* ; do
617 [ -f $i ] || continue
618 echo "Creating floppies for rootfs $(basename $(dirname $i) )..."
619 case "$(dd if=$i bs=1 count=4 2> /dev/null)" in
620 0707) cat $i ;;
621 *) zcat $i 2> /dev/null || unlzma -c $i ;;
622 esac | cpio -t > $(dirname $i)/files.list
623 sed -i '/ blocks$/d' $(dirname $i)/files.list
624 x=$(readlink $i)
625 [ -n "$x" ] || x=$i
626 pad=$(( $(stat -c %s $x ) % 1474560 ))
627 [ $pad -ne 0 ] && pad=$(( 1474560 - $pad ))
628 dd if=/dev/zero bs=1 count=$pad 2> /dev/null | cat $i - | \
629 split -b 1440k /dev/stdin $(dirname $i)/floppy
630 done
631 selection="$(grep -s append /tmp/iso$$/boot/isolinux/common.cfg | sed 's/.*append //')"
632 [ -n "$selection" ] || selection="0 slitaz"
633 set -- $selection
634 selection=""
635 while [ -n "$2" ]; do
636 [ ! -d /tmp/rootfs$$/1 -a -z "$4" ] && break
637 case "$1" in
638 *G) selection="$2 $(( ${1%G} * 1024 * 1024 )) $selection" ;;
639 *M) selection="$2 $(( ${1%M} * 1024 )) $selection" ;;
640 *) selection="$2 $1 $selection" ;;
641 esac
642 shift 2
643 done
644 echo "Creating /init ..."
645 base=100
646 set -- $selection
647 for i in /tmp/rootfs$$/[1-9]* ; do
648 [ -d $i ] || continue
649 while read file; do
650 [ -e $i/../fs/$file ] && continue
651 [ $(grep -- "$file" $i/../*/files.list | wc -l) -eq 1 ] &&
652 break
653 done < $i/files.list
654 printf "%s %s %03d %d %s %s\n" \
655 $1 $2 $base $(ls $i/floppy* | wc -l) $file \
656 $(cat $i/floppy* | md5sum - | awk '{print $1}')
657 base=$(($base + 100))
658 shift 2
659 done | buildinit /tmp/rootfs$$/fs
660 cmdline="$(grep append /tmp/iso$$/boot/isolinux/isolinux.cfg | tail -n 1 | sed 's/.*gz //')"
661 ( cd /tmp/rootfs$$/fs ; find | cpio -o -H newc ) | lzma e /tmp/rootfs$$/rootfs -si
662 echo "Creating first stage boot floppies..."
663 floppyset $bzimage /tmp/rootfs$$/rootfs "$cmdline"
664 base=100
665 for i in /tmp/rootfs$$/[1-9]* ; do
666 [ -d $i ] || continue
667 j=0
668 for f in $i/floppy* ; do
669 mv $f $(printf "fd%03d.img" $(( $base + $j )) )
670 j=$(($j + 1))
671 done
672 base=$(($base + 100))
673 done
674 rm -rf /tmp/rootfs$$
675 umount -d /tmp/iso$$
676 rm -rf /tmp/iso$$
677 }
679 # Show new boot floppy set
680 dialogwritefloppyset()
681 {
682 if ! list_floppy check; then
683 du -h fd???.img
684 return
685 fi
686 while true; do
687 exec 3>&1
688 IMAGE=`$DIALOG --title " Write floppy image " \
689 --backtitle "Boot floppy set creation on $DEVICE" --clear \
690 --colors --radiolist "
691 Insert a blank floppy in drive and
692 select the floppy image you want to write.
693 " 18 46 46 \
694 $(on="on"; for i in fd???.img; do echo "$i $(du -h $i | cut -f1) $on "; on="off"; done) 2>&1 1>&3`
695 retval=$?
696 exec 3>&-
697 check_retval
698 dd if=$IMAGE of=$DEVICE
699 done
700 }
702 dialognofloppyset()
703 {
704 cat << EOT
705 The boot loader can't load the kernel and the initramfs in the first 16MB
706 of RAM. The total size exceeds 15MB. No floppy image is created.
707 EOT
708 }
710 # Check for iso 9660 image
711 isiso()
712 {
713 mkdir /tmp/iso$$
714 mount -o loop,ro $1 /tmp/iso$$ 2> /dev/null
715 status=$?
716 umount -d /tmp/iso$$ 2> /dev/null
717 rm -rf /tmp/iso$$
718 return $status
719 }
721 dialogfloppyset()
722 {
723 : ${DIALOG=dialog}
724 while true; do
725 exec 3>&1
726 KERNEL=`$DIALOG --title " Select a Linux kernel or a SliTaz iso " \
727 --backtitle "Boot floppy set creation on $DEVICE" --clear \
728 --colors --fselect "$PWD" 10 70 \
729 2>&1 1>&3`
730 retval=$?
731 exec 3>&-
732 check_retval
733 [ -f $KERNEL ] && break
734 done
735 if isiso $KERNEL ; then
736 bootfloppybox call mkisofloppies $KERNEL
737 dialogwritefloppyset
738 return
739 fi
740 exec 3>&1
741 INITRD=`$DIALOG --title " Select an Initramfs " \
742 --backtitle "Boot floppy set creation on $DEVICE" --clear \
743 --colors --fselect "$PWD" 10 70 \
744 2>&1 1>&3`
745 retval=$?
746 exec 3>&-
747 check_retval
748 [ -f "$INITRD" ] || INITRD=""
749 exec 3>&1
750 CMDLINE=`$DIALOG --title " Enter boot command line " \
751 --backtitle "Boot floppy set creation on $DEVICE" --clear \
752 --colors --inputbox "Kernel command line" 10 70 "rw root=/dev/null autologin" \
753 2>&1 1>&3`
754 retval=$?
755 exec 3>&-
756 check_retval
757 bootfloppybox call mkfloppies "$KERNEL" "$INITRD" "$CMDLINE" &&
758 dialogwritefloppyset ||
759 dialognofloppyset
760 }
762 #
763 # Create floppy image set
764 #
765 export IMAGE_SET='
766 <window title="Image set generator" icon-name="gtk-floppy">
767 <vbox>
768 <text use-markup="true">
769 <label>
770 "
771 <b>Create a boot floppy set</b>
772 "
773 </label>
774 </text>
775 <notebook labels="Slitaz only|Any Linux">
776 <frame Slitaz only (no size limit)>
777 <vbox>
778 <text wrap="false" width-chars="44" use-markup="true">
779 <label>
780 "
781 Slitaz uses a floppy boot flavor as a first
782 stage boot to break the tiny loader 15MB limit.
783 "
784 </label>
785 </text>
786 <hbox>
787 <text use-markup="true">
788 <label>"<b>Slitaz ISO : </b>"</label>
789 </text>
790 <entry accept="filename">
791 <label>Select a Slitaz ISO image</label>
792 <variable>ISO</variable>
793 </entry>
794 <button>
795 <input file stock="gtk-open"></input>
796 <action type="fileselect">ISO</action>
797 </button>
798 </hbox>
799 <hbox>
800 <text use-markup="true">
801 <label>"<b>Output directory : </b>"</label>
802 </text>
803 <entry accept="directory">
804 <label>Select output directory</label>
805 <variable>FILE_DIRECTORY</variable>
806 <default>/tmp</default>
807 </entry>
808 <button>
809 <input file stock="gtk-open"></input>
810 <action type="fileselect">FILE_DIRECTORY</action>
811 </button>
812 </hbox>
813 <hbox>
814 <button>
815 <input file icon="forward"></input>
816 <label>Create image set from ISO boot</label>
817 <action>cd $FILE_DIRECTORY; bootfloppybox call mkisofloppiesxterm $ISO</action>
818 <action type="closewindow">IMAGE_SET</action>
819 </button>
820 </hbox>
821 </vbox>
822 </frame>
823 <frame Any Linux distribution (max total size 14-15MB)>
824 <vbox>
825 <text wrap="false" width-chars="44" use-markup="true">
826 <label>
827 "
828 The total size of the kernel and the initramfs must be
829 lower than 14-15MB due to the tiny boot loader design.
830 "
831 </label>
832 </text>
833 <hbox>
834 <text use-markup="true">
835 <label>"<b>Kernel : </b>"</label>
836 </text>
837 <entry accept="filename">
838 <label>Select a linux kernel</label>
839 <variable>KERNEL</variable>
840 </entry>
841 <button>
842 <input file stock="gtk-open"></input>
843 <action type="fileselect">KERNEL</action>
844 </button>
845 </hbox>
846 <hbox>
847 <text use-markup="true">
848 <label>"<b>Initramfs : </b>"</label>
849 </text>
850 <entry accept="filename">
851 <label>Select an initramfs/initrd file</label>
852 <variable>INITRD</variable>
853 </entry>
854 <button>
855 <input file stock="gtk-open"></input>
856 <action type="fileselect">INITRD</action>
857 </button>
858 </hbox>
859 <hbox>
860 <text use-markup="true">
861 <label>"<b>Cmdline : </b>"</label>
862 </text>
863 <entry>
864 <label>Enter kernel arguments</label>
865 <variable>CMDLINE</variable>
866 <default>rw root=/dev/null autologin</default>
867 </entry>
868 </hbox>
869 <hbox>
870 <text use-markup="true">
871 <label>"<b>Output directory : </b>"</label>
872 </text>
873 <entry accept="directory">
874 <label>Select output directory</label>
875 <variable>OUTPUT_DIRECTORY</variable>
876 <default>/tmp</default>
877 </entry>
878 <button>
879 <input file stock="gtk-open"></input>
880 <action type="fileselect">OUTPUT_DIRECTORY</action>
881 </button>
882 </hbox>
883 <hbox>
884 <button>
885 <input file icon="forward"></input>
886 <label>Create image set</label>
887 <action>cd $OUTPUT_DIRECTORY; bootfloppybox call mkfloppies "$KERNEL" "$INITRD" "$CMDLINE"</action>
888 <action type="closewindow">IMAGE_SET</action>
889 </button>
890 </hbox>
891 </vbox>
892 </frame>
893 </notebook>
894 <hbox>
895 <button>
896 <input file icon="gtk-close"></input>
897 <action type="closewindow">IMAGE_SET</action>
898 </button>
899 </hbox>
900 </vbox>
901 </window>
902 '
904 #
905 # Read/write floppy images
906 #
907 export FLOPPY_IMAGE='
908 <window title="Floppy image manager" icon-name="gtk-floppy">
909 <vbox>
910 <frame Floppy disk drive>
911 <hbox>
912 <text use-markup="true">
913 <label>"<b>Device : </b>"</label>
914 </text>
915 <combobox>
916 <variable>DEVICE</variable>'
917 FLOPPY_DEV=""
918 for i in $(list_floppy); do
919 FLOPPY_DEV="$FLOPPY_DEV
920 <item>/dev/$i</item>"
921 done
922 FLOPPY_IMAGE="$FLOPPY_IMAGE$FLOPPY_DEV
923 </combobox>
924 <button>
925 <label>Format floppy</label>
926 <input file icon=\"media-floppy\"></input>
927 <action>fdformat -n $DEVICE</action>
928 </button>
929 </hbox>
930 </frame>
931 <frame Floppy image file>
932 <hbox>
933 <text use-markup=\"true\">
934 <label>\"<b>File : </b>\"</label>
935 </text>
936 <entry accept=\"filename\">
937 <label>Select a floppy image</label>
938 <variable>IMAGE</variable>
939 </entry>
940 <button>
941 <input file stock=\"gtk-open\"></input>
942 <action type=\"fileselect\">IMAGE</action>
943 </button>
944 </hbox>
945 </frame>
946 <hbox>
947 <button>
948 <input file icon=\"reload\"></input>
949 <label>Create image set</label>
950 <action type=\"launch\">IMAGE_SET</action>
951 </button>
952 <button>
953 <input file icon=\"go-jump\"></input>
954 <label>Write image to floppy</label>
955 <action>dd if=\$IMAGE of=\$DEVICE</action>
956 </button>
957 <button>
958 <input file icon=\"undo\"></input>
959 <label>Get floppy image</label>
960 <action>dd if=\$DEVICE of=\$IMAGE</action>
961 </button>
962 <button>
963 <input file icon=\"gtk-close\"></input>
964 <action type=\"closewindow\">FLOPPY_IMAGE</action>
965 </button>
966 </hbox>
967 </vbox>
968 </window>
969 "
971 gtkdialogshowfloppyset()
972 {
973 #
974 # Show floppy image set
975 #
976 IMAGE_SHOW='
977 <window title="Image set" icon-name="gtk-floppy">
978 <vbox>
979 <text use-markup="true">
980 <label>
981 "
982 <b>Boot floppy images</b>
983 "
984 </label>
985 </text>
986 <tree>
987 <width>50</width><height>140</height>
988 <label>Size|File</label>
989 <input>du -h fd???.img | sed "s/\t/|/" </input>
990 </tree>
991 <hbox>
992 '
993 [ 0$1 -gt $((15 * 1024 * 1024)) ] && IMAGE_SHOW="$IMAGE_SHOW
994 <frame WARNING>
995 <text>
996 <label>
997 \"This floppy set breaks the 15MB limit ($1 bytes).
998 It may not be able to complete the boot process.\"
999 </label>
1000 </text>
1001 </frame>
1002 </hbox>
1003 <hbox>
1005 list_floppy check && IMAGE_SHOW="$IMAGE_SHOW
1006 <button>
1007 <input file icon=\"media-floppy\"></input>
1008 <label>Manage images</label>
1009 <action type=\"launch\">FLOPPY_IMAGE</action>
1010 </button>
1012 IMAGE_SHOW="$IMAGE_SHOW
1013 <button>
1014 <input file icon=\"gtk-close\"></input>
1015 <action type=\"closewindow\">IMAGE_SET</action>
1016 </button>
1017 </hbox>
1018 </vbox>
1019 </window>
1021 export IMAGE_SHOW
1022 gtkdialog --program=IMAGE_SHOW
1025 while true; do
1027 if [ "$1" == "call" ]; then
1028 case "$2" in
1029 mkmenu) mkmenu $3;;
1030 mkisofloppiesxterm)
1031 shift 2
1032 xterm -geometry 80x16 -title "Build boot floppies from ISO" \
1033 -e "$0 call mkisofloppies $@ ; echo -e \"----\nENTER to continue...\" && read close"
1034 gtkdialogshowfloppyset
1035 ;;
1036 mkisofloppies)
1037 shift 2
1038 floppysetfromiso $@
1039 ;;
1040 mkfloppies)
1041 shift 2
1042 floppyset "$@"
1043 sz=$(cat fd???.img | wc -c)
1044 if [ -n "$XAUTHORITY" ]; then
1045 gtkdialogshowfloppyset $sz
1046 else
1047 if [ $sz -gt $((15 * 1024 * 1024)) ]; then
1048 cat <<EOT
1049 This floppy set breaks the 15MB limit ($sz bytes).
1050 It may not be able to complete the boot process.
1051 EOT
1052 fi
1053 fi
1054 ;;
1055 install)
1056 DIR=/tmp/mkbootfloppy$$
1057 mkdir -p $DIR
1058 DEVICE=$4
1059 file=$5
1060 case "$3" in
1061 dialog*)
1062 shift 2
1063 $@
1064 ;;
1065 grub*)
1066 mkdir -p $DIR/boot/grub
1067 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ] \
1068 && cat /usr/share/boot/btmgr /dev/zero | \
1069 dd bs=18k count=80 | gzip -9 > \
1070 $DIR/boot/btmgr.gz \
1071 && unlzma -c /usr/share/boot/memdisk.lzma > \
1072 $DIR/boot/memdisk
1073 [ -f /usr/share/boot/plpbt.bin ] \
1074 && cp /usr/share/boot/plpbt.bin $DIR/boot
1075 [ -f /usr/share/boot/etherboot ] \
1076 && cp /usr/share/boot/etherboot $DIR/boot
1077 [ -f /boot/gpxe ]\
1078 && cp /boot/gpxe $DIR/boot
1079 [ -f /usr/share/boot/memtest.lzma -a \
1080 -f /usr/share/boot/memdisk.lzma ] \
1081 && unlzma -c /usr/share/boot/memtest.lzma | \
1082 cat - /dev/zero | dd bs=18k count=80 | \
1083 gzip -9 > $DIR/boot/memtest.gz \
1084 && unlzma -c /usr/share/boot/memdisk.lzma > \
1085 $DIR/boot/memdisk
1086 install_grub $DIR $3
1087 ;;
1088 *)
1089 case "$file" in
1090 *.lzma) action="unlzma -c";;
1091 *.gz) action="zcat";;
1092 *) action="cat";;
1093 esac
1094 case "$DEVICE" in
1095 /dev/*) $action $file > $DEVICE;;
1096 flopp*) $action $file | cat - /dev/zero | \
1097 dd bs=18k count=80 > boot.fd;;
1098 cdrom*)
1099 mkdir -p $DIR/boot/grub
1100 case "$3" in
1101 btmgr|memtest)
1102 $action $file | cat - /dev/zero | \
1103 dd bs=18k count=80 | \
1104 gzip -9 > $DIR/boot/$3.gz
1105 unlzma -c /usr/share/boot/memdisk.lzma \
1106 > $DIR/boot/memdisk
1107 cat > /tmp/floppybox.grub.menu << EOT
1108 # grub menu
1109 timeout 0
1110 title $3
1111 kernel /boot/memdisk floppy c=80 h=2 s=18
1112 initrd /boot/$3.gz
1113 EOT
1114 ;;
1115 *) $action $file > $DIR/boot/$3
1116 cat > /tmp/floppybox.grub.menu << EOT
1117 # grub menu
1118 timeout 0
1119 title $3
1120 kernel /boot/$3
1121 EOT
1122 ;;
1123 esac
1124 install_grub $DIR grub
1125 ;;
1126 esac
1127 ;;
1128 esac
1129 rm -rf $DIR
1130 ;;
1131 get-plop)
1132 mkdir -p /tmp/get-plop$$
1133 PLOP_URL=http://mirror.slitaz.org/boot/plpbt.bin
1134 wget -O - $PLOP_URL > /tmp/get-plop$$/plpbt.bin
1135 VERSION="$(strings /tmp/get-plop$$/plpbt.bin \
1136 | grep 'Boot Manager v' | sed 's/.* v\([0-9\.]*\) .*/\1/')"
1137 mkdir -p $(dirname /tmp/get-plop$$/plop-$VERSION/fs/$3)
1138 mv /tmp/get-plop$$/plpbt.bin \
1139 /tmp/get-plop$$/plop-$VERSION/fs/$3
1140 if [ -s /tmp/get-plop$$/plop-$VERSION/fs/$3 ]; then
1141 cat > /tmp/get-plop$$/plop-$VERSION/receipt <<EOT
1142 PACKAGE="plop"
1143 VERSION="$VERSION"
1144 CATEGORY="non-free"
1145 SHORT_DESC="Plop boot manager."
1146 WEB_SITE="http://www.plop.at/en/bootmanager.html"
1147 EOT
1148 ( cd /tmp/get-plop$$ ; tazpkg pack plop-$VERSION )
1149 tazpkg install /tmp/get-plop$$/plop-$VERSION.tazpkg
1150 fi
1151 rm -rf /tmp/get-plop$$
1152 ;;
1153 *) echo "Invalid command $0 $@" 1>&2
1154 exit 1;;
1155 esac
1156 exit 0
1157 fi
1159 if [ -z "$XAUTHORITY" ]; then
1161 : ${DIALOG=dialog}
1163 DEVICE=/dev/fd0
1164 list_floppy check || DEVICE="floppy"
1165 while true; do
1166 exec 3>&1
1167 ID_SOURCE=`$DIALOG --title " Choose a boot floppy " \
1168 --backtitle "Boot Floppy Creation on $DEVICE" --clear \
1169 --extra-button --extra-label "Change floppy" \
1170 --colors --radiolist "
1171 Create a floppy or a cdrom to boot a LiveCD in a PXE network...
1172 May need a floppy disk in drive. Erase the whole floppy disk.
1173 " 18 70 50\
1174 FloppySet "Boot Slitaz with floppies only." on \
1175 SmartBtmgr "Boot any partition or ATAPI CD-ROM." off \
1176 Plop "Boot USB harddisk floppy or CD/DVD." off \
1177 Etherboot "Replacement for proprietary PXE ROMs." off \
1178 gPXE "Boot from http://boot.slitaz.org/" off \
1179 Memtest86+ "Memory failures detection tool." off \
1180 Grub4DOS "Enhanced grub version supporting NTFS." off \
1181 Grub "Boot loader with command shell." off \
1182 2>&1 1>&3`
1183 retval=$?
1184 exec 3>&-
1185 check_retval
1186 if [ "$retval" = "3" ]; then
1187 select_floppy
1188 continue;
1189 fi
1190 while read key file pkg; do
1191 [ "$key" = "$ID_SOURCE" ] || continue
1192 if [ ! -f "$file" ]; then
1193 $DIALOG --title " Install package " --colors \
1194 --backtitle "Boot Floppy Creation" --clear \
1195 --yes-label "Install" \
1196 --no-label "Quit" \
1197 --yesno "The package $pkg is not yet installed. Install it ?" 18 70
1198 retval=$?
1199 if [ "$pkg" = "plop" ]; then
1200 bootfloppybox call get-plop $file
1201 else
1202 tazpkg get-install $pkg
1203 fi
1204 fi
1205 bootfloppybox call install "$pkg" "$DEVICE" "$file"
1206 exit 0
1207 done <<EOT
1208 FloppySet /bin/dd dialogfloppyset
1209 SmartBtmgr /usr/share/boot/btmgr btmgr
1210 Plop /usr/share/boot/plpbt.bin plop
1211 Etherboot /usr/share/boot/etherboot etherboot
1212 gPXE /boot/gpxe gpxe
1213 Memtest86+ /usr/share/boot/memtest.lzma memtest
1214 Grub4DOS /usr/share/boot/grldr.lzma grub4dos
1215 Grub /usr/sbin/grub grub
1216 EOT
1217 done
1218 fi
1220 # Describe gPXE arguments.
1222 export HELP='
1223 <window title="gPXE forced url" icon-name="gtk-floppy">
1224 <vbox>
1225 <text use-markup="true">
1226 <label>"
1227 <b>Web boot parameters</b>"
1228 </label>
1229 </text>
1230 <frame>
1231 <text wrap="true" width-chars="58" use-markup="true">
1232 <label>
1233 "Without parameters (i.e. with an empty Boot URL) gPXE will perform a normal PXE boot: IP configuration with DHCP and download the DHCP bootfile with TFTP.
1235 You can override the DHCP bootfile with a Boot URL such as <i>tftp://192.168.0.1/pxe/pxeloader</i>, <i>http://mirror.slitaz.org/pxe/pxelinux.0</i>, or <i>x-tftm://192.168.0.201//lts/vmlinuz.ltsp</i>.
1237 You can override the IP configuration too (useful without a DHCP server), example: <i>ip=192.168.0.10/24 gw=192.168.0.1 dns=192.168.0.1 nodhcp url=http://mirror.slitaz.org/pxe/pxelinux.0</i>
1239 The <i>nodhcp</i> keyword avoids dhcp timeouts and the <i>url=</i> keyword is optional when the url is the only one argument.
1241 Comma separated URL lists are supported. The PXE client will try to load the first URL. If the load fails, it will try the next URL, and so on.
1243 </label>
1244 </text>
1245 </frame>
1246 </vbox>
1247 </window>
1250 # Write bootfloppy image to floppy device.
1252 BOOT_DIALOG='
1253 <window title="bootfloppybox" icon-name="gtk-floppy">
1254 <vbox>
1256 <text use-markup="true">
1257 <label>
1259 <b>SliTaz - Bootfloppybox</b>"
1260 </label>
1261 </text>
1262 <text wrap="false" width-chars="44" use-markup="true">
1263 <label>
1265 Create a floppy or a cdrom to boot a LiveCD in a PXE network or the WEB...
1266 May need a floppy disk in drive. Erase the whole floppy disk.
1268 </label>
1269 </text>
1271 <frame Floppy disk drive>
1272 <hbox>
1273 <text use-markup="true">
1274 <label>"<b>Device : </b>"</label>
1275 </text>
1276 <combobox>
1277 <variable>DEVICE</variable>'
1278 FLOPPY_DEV=""
1279 for i in $(list_floppy); do
1280 FLOPPY_DEV="$FLOPPY_DEV
1281 <item>/dev/$i</item>"
1282 done
1283 BOOT_DIALOG="$BOOT_DIALOG$FLOPPY_DEV
1284 <item>floppy image (boot.fd)</item>
1285 <item>cdrom image (boot.iso)</item>
1286 </combobox>"
1287 if [ -n "$FLOPPY_DEV" ]; then
1288 tmp='
1289 <button>
1290 <label>Format floppy</label>
1291 <input file icon="media-floppy"></input>
1292 <action>case "$DEVICE" in /dev/*) fdformat -n $DEVICE;; esac</action>
1293 </button>'
1294 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1295 fi
1296 tmp='
1297 </hbox>
1298 </frame>
1299 <notebook labels="Set|LiveCD|USB|PXE Network|WEB Network|Memory Test|Windows|Expert">
1300 <frame Boot floppy set (many floppies)>
1301 <vbox>
1302 <hbox>
1303 <text wrap="true" width-chars="58" use-markup="true">
1304 <label>
1306 Only people without a CD-ROM, USB and Network should use a floppy set.
1307 The images are built from an ISO boot or from a Linux kernel, an initramfs
1308 and a boot command line. Non Slitaz boot floppy sets are limited to 15MB.
1310 </label>
1311 </text>
1312 </hbox>
1313 <hbox>
1314 <button>
1315 <label>Create image set</label>
1316 <input file icon="forward"></input>
1317 <action type="launch">IMAGE_SET</action>
1318 </button>
1319 </hbox>
1320 </vbox>
1321 </frame>
1323 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1324 while read name file pkg desc; do
1325 tmp="<frame $name (single floppy)>
1326 <hbox>
1327 <text wrap=\"true\" width-chars=\"58\" use-markup=\"true\">
1328 <label>
1329 \"
1330 $(echo -e $desc)
1331 \"
1332 </label>
1333 </text>
1334 </hbox>
1335 <hbox>
1337 if [ -f $file ]; then
1338 if [ "$pkg" = "grub" -o "$pkg" = "grub4dos" ]; then
1339 tmp="$tmp
1340 <button>
1341 <label>Grub menu</label>
1342 <input file icon=\"accessories-text-editor\"></input>
1343 <action>bootfloppybox call mkmenu $pkg</action>
1344 <action type=\"lauch\">leafpad /tmp/floppybox.grub.menu</action>
1345 </button>
1347 elif [ "$pkg" = "etherboot" ]; then
1348 tmp="$tmp
1349 <button>
1350 <input file icon=\"browser\"></input>
1351 <label>Wiki</label>
1352 <action>browser http://doc.slitaz.org/en:guides:pxe &</action>
1353 </button>
1355 elif [ "$pkg" = "gpxe" ]; then
1356 tmp="$tmp
1357 <text wrap=\"true\" use-markup=\"true\">
1358 <label> \"<b>Boot URL:</b>\" </label>
1359 </text>
1360 <entry>
1361 <default>$(dd if=$file bs=1 skip=519 count=255 2>/dev/null | strings)</default>
1362 <variable>URL</variable>
1363 </entry>
1364 </hbox>
1365 <hbox>
1366 <button>
1367 <input file icon=\"browser\"></input>
1368 <label>Wiki</label>
1369 <action>browser http://doc.slitaz.org/en:guides:pxe &</action>
1370 </button>
1371 <button help>
1372 <action type=\"launch\">HELP</action>
1373 </button>
1374 <button>
1375 <label>Update</label>
1376 <input file icon=\"reload\"></input>
1377 <action>echo -n \"\$URL\" | cat - /dev/zero | dd conv=notrunc bs=1 count=255 seek=519 of=$file 2>/dev/null</action>
1378 </button>
1380 fi
1381 receipt=/var/lib/tazpkg/installed/$pkg/receipt
1382 if [ -f $receipt ]; then
1383 . $receipt
1384 tmp="$tmp
1385 <button>
1386 <input file icon=\"browser\"></input>
1387 <label>Web</label>
1388 <action>browser $WEB_SITE &</action>
1389 </button>
1391 fi
1392 tmp="$tmp
1393 <button>
1394 <label>Write floppy</label>
1395 <input file icon=\"forward\"></input>
1396 <action>bootfloppybox call install \"$pkg\" \"\$DEVICE\" \"$file\"</action>
1397 </button>
1398 </hbox>
1399 </frame>
1401 else
1402 tmp2="tazpkg get-install $pkg --forced"
1403 [ "$pkg" = "plop" ] && tmp2="bootfloppybox call get-plop $file"
1404 tmp="$tmp
1405 <text wrap=\"true\" width-chars=\"34\" use-markup=\"true\">
1406 <label>
1407 \"<i>The package <b>$pkg</b> is not yet installed</i>\"
1408 </label>
1409 </text>
1410 <button>
1411 <input file icon=\"go-jump\"></input>
1412 <label>Install</label>
1413 <action>[ -f /var/lib/tazpkg/packages.list ] || tazpkg recharge</action>
1414 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title \"$pkg install\" -e \"$tmp2 ; sleep 2\"</action>
1415 <action type=\"exit\">restart</action>
1416 </button>
1417 </hbox>
1418 </frame>
1420 fi
1421 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1422 done <<EOT
1423 SmartBtmgr /usr/share/boot/btmgr btmgr This OS independent Smart Boot Manager can boot \\\\nany partition or ATAPI CD-ROM.
1424 Plop /usr/share/boot/plpbt.bin plop This non free Boot Manager can boot a floppy disk, hardisk, USB or \\\\nCD/DVD. Hit Ctrl-ESC for text mode.
1425 Etherboot /usr/share/boot/etherboot etherboot This network bootloader provides a replacement \\\\nfor proprietary PXE or NBI ROMs.
1426 gPXE /boot/gpxe gpxe PXE / iSCSI / AoE network bootloader.
1427 Memtest86+ /usr/share/boot/memtest.lzma memtest Memory failures detection tool.
1428 Grub4DOS /usr/share/boot/grldr.lzma grub4dos Enhanced grub version supporting NTFS.
1429 Grub /usr/sbin/grub grub General purpose boot loader with command shell.
1430 EOT
1431 tmp='
1432 </notebook>
1433 <hbox>
1435 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1436 if [ -e /dev/cdrom ]; then
1437 tmp='
1438 <button>
1439 <input file icon="media-cdrom"></input>
1440 <label>Burn cdrom image</label>
1441 <action>burnbox</action>
1442 </button>
1444 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1445 fi
1446 if list_floppy check; then
1447 tmp='
1448 <button>
1449 <input file icon="media-floppy"></input>
1450 <label>Manage floppy image</label>
1451 <action type="launch">FLOPPY_IMAGE</action>
1452 </button>
1454 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1455 fi
1456 tmp='
1457 <button>
1458 <input file icon="exit"></input>
1459 <label>Exit</label>
1460 <action type="exit">Exit</action>
1461 </button>
1462 </hbox>
1464 </vbox>
1465 </window>
1467 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1468 export BOOT_DIALOG
1470 # Only root can create floppy.
1471 check_root
1472 gtkdialog --program=BOOT_DIALOG | grep -q 'EXIT="restart"' && continue
1473 rm -f /tmp/floppybox.grub.menu
1474 exit 0
1475 done