slitaz-tools view tinyutils/bootfloppybox @ rev 649

bootfloppybox: add installer in slitaz boot floppies
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 10 21:42:10 2011 +0200 (2011-07-10)
parents 0f5e3af5a51d
children d564f29ba19e
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 cat > $1/init <<EOTEOT
244 #!/bin/sh
246 cat_floppy()
247 {
248 tmp="\$(dd if=/dev/fd0 count=1 2> /dev/null | md5sum)"
249 echo -n "Insert floppy \$num for \$name and press Enter or Q to skip"
250 while true; do
251 echo -n ":"
252 read -t 10 answer < /dev/tty0
253 case "\$answer" in
254 Q*|q*|A*|a*) break 3;;
255 esac
256 dd if=/dev/fd0 count=1 > /tmp/bs.\$\$ 2> /dev/null
257 [ -s /tmp/bs.\$\$ ] || continue
258 [ "\$(md5sum < /tmp/bs.\$\$)" != "\$tmp" ] || continue
259 rm -f /tmp/bs.\$\$
260 break
261 done
262 dd if=/dev/fd0 of=/tmp/rootfs.\$num 2> /dev/null || continue
263 cat /tmp/rootfs.\$num >> \$1
264 rm -f /tmp/rootfs.\$num
265 num=\$((\$num+1))
266 }
268 mount -t proc proc /proc
269 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
270 # the floppy driver may not be included in kernel
271 insmod /lib/modules/*/kernel/drivers/block/floppy.ko.gz 2> /dev/null
272 # loram may put floppy.ko.gz module in /lib
273 insmod /lib/floppy.ko.gz 2> /dev/null
274 if blkid | grep -q 'TYPE="ext'; then
275 cat <<EOT
277 You can preinstall SliTaz in one of these ext3 partition:
278 \$(blkid | grep 'TYPE="ext')
280 Simply enter the device name (/dev/XXXX) to create the slitaz/install.sh or
281 leave it blank to skip :
282 EOT
283 read -t 60 device < /dev/tty0
284 [ -n "\$device" ] && mount \$device /mnt && mkdir /mnt/slitaz
285 else
286 cat <<EOT
288 You can preinstall SliTaz in an ext3 partition with this floppy set.
289 After the boot process is completed, create a partition with 'fdisk',
290 format it with 'mke2fs -j' and reboot from the floppies again.
292 EOT
293 fi
294 umount /proc
295 while read name min num count file md5; do
296 [ -e \$file ] && continue
297 [ \$total -lt \$min ] && break
298 while [ \$count -ne 0 ]; do
299 cat_floppy /tmp/rootfs
300 count=\$((\$count-1))
301 done
302 echo "\$md5 /tmp/rootfs" | md5sum -c || break
303 cpio -idmu < /tmp/rootfs > /dev/null 2>&1 ||
304 ( zcat /tmp/rootfs 2> /dev/null || unlzma -c /tmp/rootfs ) | cpio -idmu
305 if [ -d /mnt/slitaz ]; then
306 cp /tmp/rootfs /mnt/slitaz/rootfs.\$num ||
307 mv -f /mnt/slitaz /mnt/slitaz-aborted
308 fi
309 rootfslist="\$rootfslist \$num"
310 rm -f /tmp/rootfs*
311 done <<EOT
312 $(while read line; do echo $line; done)
313 EOT
314 if [ -d /mnt/slitaz ]; then
315 cat > /mnt/slitaz/install.sh <<EOT
316 #!/bin/sh
318 [ -n "\\\$1" ] || set -- .
319 cd \\\$1
320 dir=\\\$(dirname \\\$0)
321 for i in 0 \$rootfslist ; do
322 [ -s \\\$dir/rootfs.\\\$i ] || continue
323 cpio -idmu < \\\$dir/rootfs.\\\$i > /dev/null 2>&1 ||
324 ( zcat \\\$dir/rootfs.\\\$i 2> /dev/null || unlzma -c \\\$dir/rootfs.\\\$i ) | cpio -idmu
325 done
326 mv -f init.org init
327 mkdir boot && cp \\\$dir/bzImage boot
328 cp -a /usr/lib/grub/i386-pc boot/grub
329 cat > boot/grub/menu.lst<<EOF
330 # /boot/grub/menu.lst: GRUB boot loader configuration.
331 #
333 # By default, boot the first entry.
334 default 0
336 # Boot automatically after 8 secs.
337 timeout 8
339 # Change the colors.
340 color yellow/brown light-green/black
342 title SliTaz GNU/Linux
343 kernel /boot/bzImage root=\$device
345 EOF
346 grub-install --no-floppy --root-directory=\\\$PWD \${device%[1-9]*}
347 cd -
348 EOT
349 chmod +x /mnt/slitaz/install.sh
350 num=1
351 name="the Linux kernel"
352 dd count=0 of=/mnt/slitaz/bzImage.fd
353 fullsize=1
354 while [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$fullsize ]; do
355 cat_floppy /mnt/slitaz/bzImage.fd
356 setup=\$(dd if=/mnt/slitaz/bzImage.fd skip=497 bs=1 count=1 2> /dev/null | hexdump -e '"" 1/1 "%d" "\n"')
357 syssize=\$(dd if=/mnt/slitaz/bzImage.fd skip=500 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
358 cmdline=\$(dd if=/mnt/slitaz/bzImage.fd skip=552 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
359 initrd=\$(dd if=/mnt/slitaz/bzImage.fd skip=540 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"')
360 [ \$cmdline -eq 0 ] || cmdline=512
361 size=\$((512 + \$setup * 512 + \$cmdline + \$syssize * 16))
362 [ -s /etc/slitaz-release ] || initrd=0
363 fullsize=\$((\$size + \$initrd + 512))
364 [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$size ] ||
365 name="the first initramfs"
366 done
367 [ -s /etc/slitaz-release ] &&
368 dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512+(31+\$syssize)/32)) > /mnt/slitaz/rootfs.0 &&
369 dd bs=1 seek=\$initrd count=0 of=/mnt/slitaz/rootfs.0
370 dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=4 seek=552
371 dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=8 seek=536
372 dd if=/mnt/slitaz/bzImage.fd bs=512 count=\$((\$setup+1)) > /mnt/slitaz/bzImage
373 dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512)) >> /mnt/slitaz/bzImage
374 rm -f /mnt/slitaz/bzImage.fd
375 size=\$((512 + \$setup * 512 + \$syssize * 16))
376 dd bs=1 seek=\$size count=0 of=/mnt/slitaz/bzImage
377 [ \$(stat -c %s /mnt/slitaz/bzImage) -eq \$size ] ||
378 mv -f /mnt/slitaz /mnt/slitaz-aborted
379 fi
380 mv -f /init.org /init || sh
381 exec /init
382 EOTEOT
383 chmod +x $1/init
384 }
386 # write a 32 bits data
387 # usage: storelong offset data32 file
388 storelong()
389 {
390 printf "00000 %02X %02X %02X %02X \n" \
391 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \
392 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
393 hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null
394 }
396 # read a 32 bits data
397 # usage: getlong offset file
398 getlong()
399 {
400 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \
401 hexdump -e '"" 1/4 "%d" "\n"'
402 }
404 # output floppy images set
405 floppysetcat()
406 {
407 KERNEL="$1"
408 INITRD="$2"
409 shift 2
410 CMDLINE="$@"
412 # bzImage offsets
413 SetupSzOfs=497
414 SyssizeOfs=500
415 CodeAdrOfs=0x214
416 RamfsAdrOfs=0x218
417 RamfsLenOfs=0x21C
418 ArgPtrOfs=0x228
420 # boot+setup address
421 SetupBase=0x90000
423 stacktop=0x9E00
425 bs=/tmp/bs$$
427 # Get and patch boot sector
428 dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null
429 uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null
430 begin-base64 644 -
431 /L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF
432 +D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl
433 ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc
434 sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW
435 6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b
436 AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB
437 xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC
438 ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0
439 /sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ
440 1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s
441 BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A
442 AA==
443 ====
444 EOT
446 # Get setup
447 setupsz=$(getlong $SetupSzOfs $bs)
448 setupszb=$(( $setupsz & 255 ))
449 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs
451 # Store cmdline after setup
452 if [ -n "$CMDLINE" ]; then
453 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs
454 storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs
455 fi
457 # Compute initramfs size
458 initrdlen=0
459 padding=0
460 for i in $( echo $INITRD | sed 's/,/ /' ); do
461 [ -s "$i" ] || continue
462 initrdlen=$(( $initrdlen + $padding ))
463 padding=$(stat -c %s $i)
464 initrdlen=$(( $initrdlen + $padding ))
465 padding=$(( 4096 - ($padding & 4095) ))
466 [ $padding -eq 4096 ] && padding=0
467 done
468 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 ))
469 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize ))
470 if [ $initrdlen -ne 0 ]; then
471 Kbase=$(getlong $CodeAdrOfs $bs)
472 storelong $RamfsAdrOfs \
473 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs
474 storelong $RamfsLenOfs $initrdlen $bs
475 fi
477 # Output boot sector + setup + cmdline
478 dd if=$bs 2> /dev/null
480 # Output kernel code
481 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null
483 # Pad to next sector
484 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) ))
485 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null
487 # Output initramfs
488 padding=0
489 for i in $( echo $INITRD | sed 's/,/ /' ); do
490 [ -s "$i" ] || continue
491 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding
492 dd if=$i 2> /dev/null
493 padding=$(( 4096 - ($(stat -c %s $i) & 4095) ))
494 [ $padding -eq 4096 ] && padding=0
495 done
497 # Cleanup
498 rm -f $bs
499 }
501 # Create boot floppy set from kernel, initrd & cmdline
502 floppyset()
503 {
504 floppysetcat "$@" | split -b 1440k /dev/stdin floppy$$
505 i=1
506 ls floppy$$* | while read file ; do
507 output=$(printf "fd%03d.img" $i)
508 cat $file /dev/zero | dd bs=1k count=1440 of=$output conv=sync 2> /dev/null
509 rm -f $file
510 i=$(( $i + 1 ))
511 done
512 }
514 # Create boot floppy set from a SliTaz ISO image
515 floppysetfromiso()
516 {
517 mkdir /tmp/iso$$
518 mount -o loop,ro $1 /tmp/iso$$
519 rootfs="$(ls /tmp/iso$$/boot/rootfs*z 2> /dev/null | tail -1)"
520 bzimage=/tmp/iso$$/boot/bzImage
521 if [ -z "$rootfs" -o ! -s $bzimage ]; then
522 umount -d /tmp/iso$$
523 rm -rf /tmp/iso$$
524 echo "Not a SliTaz ISO image !"
525 return 1
526 fi
527 mkdir -p /tmp/rootfs$$/fs
528 n=1
529 for i in $(ls /tmp/iso$$/boot/rootfs*z | sort -r); do
530 mkdir /tmp/rootfs$$/$n
531 ln -s $i /tmp/rootfs$$/$n
532 n=$(($n + 1))
533 done
534 echo "Unpacking rootfs..."
535 ( zcat $rootfs 2> /dev/null | unlzma -c $rootfs ) | \
536 ( cd /tmp/rootfs$$/fs ; cpio -idm > /dev/null )
537 if [ $(unlzma -c $rootfs 2> /dev/null| wc -c) -gt $(stat -c %s $rootfs) ]; then
538 if [ $(du -ck $rootfs $bzimage | awk 'END { print $1 }') -gt 15296 ]; then
539 # The rootfs.gz file is too big, extract a minimum bootfs with busybox stuff
540 echo "Extracting bootfs..."
541 mv /tmp/rootfs$$/fs /tmp/rootfs$$/fs0
542 for i in lib bin sbin usr/bin usr/sbin ; do
543 mkdir -p /tmp/rootfs$$/fs/$i
544 done
545 cd /tmp/rootfs$$/fs0
546 dir=$(echo lib/modules/*/kernel/drivers/block)
547 [ -d $dir ] && mkdir -p ../fs/$dir
548 [ -f $dir/floppy.ko.gz ] && mv $dir/floppy.ko.gz ../fs/$dir
549 for i in dev init mnt proc sys tmp ; do
550 mv $i ../fs
551 done
552 mv lib/ld-* ../fs/lib
553 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so bin/busybox | \
554 awk '/\/lib\/lib/ { print $3 }' | while read lib ; do
555 while [ -L .$lib ]; do
556 local target
557 target="$(readlink ".$lib")"
558 case "$target" in
559 /*) ;;
560 *) target="$(dirname $lib)/$target" ;;
561 esac
562 mv ".$lib" ../fs/lib
563 lib="$target"
564 done
565 mv ".$lib" ../fs/lib
566 done
567 for i in $(bin/busybox | awk '{ if (s) printf "%s",$0 }
568 /Currently/ { s=1 }' | sed 's/,//g'); do
569 for j in bin sbin usr/bin usr/sbin ; do
570 [ -e $j/$i ] && mv $j/$i ../fs/$j/$i
571 done
572 done
573 mv bin/busybox ../fs/bin
574 [ -e ../fs/bin/cpio ] || mv bin/cpio ../fs/bin
575 rm -f ../1/*
576 find | cpio -o -H newc | lzma e ../1/rootfs.gz -si
577 cd - > /dev/null
578 rm -rf /tmp/rootfs$$/fs0
579 else
580 # The rootfs.gz file fits in 15MB, no need to split it.
581 rm -rf /tmp/rootfs$$/1
582 fi
583 else
584 # This is a loram rootfs.gz, extract loram bootstrap
585 echo "Splitting loram rootfs..."
586 offset=$(awk '/07070100/ { o+=index($0,"07070100"); print o/4 ; exit } { o+=1+length() }' < $rootfs)
587 dd if=$rootfs skip=$(($offset / 1024)) bs=4k count=1 2> /dev/null | \
588 dd skip=$(($offset % 1024)) bs=4 of=/tmp/rootfs$$/1/root 2> /dev/null
589 dd if=$rootfs skip=$((1 + ($offset / 1024) )) bs=4k \
590 >> /tmp/rootfs$$/1/root 2> /dev/null
591 rm -f /tmp/rootfs$$/1/rootfs*
592 fi
593 # Create extra rootfs floppies
594 for i in /tmp/rootfs$$/[1-9]*/root* ; do
595 [ -f $i ] || continue
596 echo "Creating floppies for rootfs $(basename $(dirname $i) )..."
597 case "$(dd if=$i bs=1 count=4 2> /dev/null)" in
598 0707) cat $i ;;
599 *) zcat $i 2> /dev/null || unlzma -c $i ;;
600 esac | cpio -t > $(dirname $i)/files.list
601 sed -i '/ blocks$/d' $(dirname $i)/files.list
602 x=$(readlink $i)
603 [ -n "$x" ] || x=$i
604 pad=$(( $(stat -c %s $x ) % 1474560 ))
605 [ $pad -ne 0 ] && pad=$(( 1474560 - $pad ))
606 dd if=/dev/zero bs=1 count=$pad 2> /dev/null | cat $i - | \
607 split -b 1440k /dev/stdin $(dirname $i)/floppy
608 done
609 selection="$(grep -s append /tmp/iso$$/boot/isolinux/common.cfg | sed 's/.*append //')"
610 [ -n "$selection" ] || selection="0 slitaz"
611 set -- $selection
612 selection=""
613 while [ -n "$2" ]; do
614 [ ! -d /tmp/rootfs$$/1 -a -z "$4" ] && break
615 case "$1" in
616 *G) selection="$2 $(( ${1%G} * 1024 * 1024 )) $selection" ;;
617 *M) selection="$2 $(( ${1%M} * 1024 )) $selection" ;;
618 *) selection="$2 $1 $selection" ;;
619 esac
620 shift 2
621 done
622 echo "Creating /init ..."
623 base=100
624 set -- $selection
625 for i in /tmp/rootfs$$/[1-9]* ; do
626 [ -d $i ] || continue
627 while read file; do
628 [ -e $i/../fs/$file ] && continue
629 [ $(grep -- "$file" $i/../*/files.list | wc -l) -eq 1 ] &&
630 break
631 done < $i/files.list
632 printf "%s %s %03d %d %s %s\n" \
633 $1 $2 $base $(ls $i/floppy* | wc -l) $file \
634 $(cat $i/floppy* | md5sum - | awk '{print $1}')
635 base=$(($base + 100))
636 shift 2
637 done | buildinit /tmp/rootfs$$/fs
638 cmdline="$(grep append /tmp/iso$$/boot/isolinux/isolinux.cfg | tail -n 1 | sed 's/.*gz //')"
639 ( cd /tmp/rootfs$$/fs ; find | cpio -o -H newc ) | lzma e /tmp/rootfs$$/rootfs -si
640 echo "Creating first stage boot floppies..."
641 floppyset $bzimage /tmp/rootfs$$/rootfs "$cmdline"
642 base=100
643 for i in /tmp/rootfs$$/[1-9]* ; do
644 [ -d $i ] || continue
645 j=0
646 for f in $i/floppy* ; do
647 mv $f $(printf "fd%03d.img" $(( $base + $j )) )
648 j=$(($j + 1))
649 done
650 base=$(($base + 100))
651 done
652 rm -rf /tmp/rootfs$$
653 umount -d /tmp/iso$$
654 rm -rf /tmp/iso$$
655 }
657 # Show new boot floppy set
658 dialogwritefloppyset()
659 {
660 if ! list_floppy check; then
661 du -h fd???.img
662 return
663 fi
664 while true; do
665 exec 3>&1
666 IMAGE=`$DIALOG --title " Write floppy image " \
667 --backtitle "Boot floppy set creation on $DEVICE" --clear \
668 --colors --radiolist "
669 Insert a blank floppy in drive and
670 select the floppy image you want to write.
671 " 18 46 46 \
672 $(on="on"; for i in fd???.img; do echo "$i $(du -h $i | cut -f1) $on "; on="off"; done) 2>&1 1>&3`
673 retval=$?
674 exec 3>&-
675 check_retval
676 dd if=$IMAGE of=$DEVICE
677 done
678 }
680 dialognofloppyset()
681 {
682 cat << EOT
683 The boot loader can't load the kernel and the initramfs in the first 16MB
684 of RAM. The total size exceeds 15MB. No floppy image is created.
685 EOT
686 }
688 # Check for iso 9660 image
689 isiso()
690 {
691 mkdir /tmp/iso$$
692 mount -o loop,ro $1 /tmp/iso$$ 2> /dev/null
693 status=$?
694 umount -d /tmp/iso$$ 2> /dev/null
695 rm -rf /tmp/iso$$
696 return $status
697 }
699 dialogfloppyset()
700 {
701 : ${DIALOG=dialog}
702 while true; do
703 exec 3>&1
704 KERNEL=`$DIALOG --title " Select a Linux kernel or a SliTaz iso " \
705 --backtitle "Boot floppy set creation on $DEVICE" --clear \
706 --colors --fselect "$PWD" 10 70 \
707 2>&1 1>&3`
708 retval=$?
709 exec 3>&-
710 check_retval
711 [ -f $KERNEL ] && break
712 done
713 if isiso $KERNEL ; then
714 bootfloppybox call mkisofloppies $KERNEL
715 dialogwritefloppyset
716 return
717 fi
718 exec 3>&1
719 INITRD=`$DIALOG --title " Select an Initramfs " \
720 --backtitle "Boot floppy set creation on $DEVICE" --clear \
721 --colors --fselect "$PWD" 10 70 \
722 2>&1 1>&3`
723 retval=$?
724 exec 3>&-
725 check_retval
726 [ -f "$INITRD" ] || INITRD=""
727 exec 3>&1
728 CMDLINE=`$DIALOG --title " Enter boot command line " \
729 --backtitle "Boot floppy set creation on $DEVICE" --clear \
730 --colors --inputbox "Kernel command line" 10 70 "rw root=/dev/null autologin" \
731 2>&1 1>&3`
732 retval=$?
733 exec 3>&-
734 check_retval
735 bootfloppybox call mkfloppies "$KERNEL" "$INITRD" "$CMDLINE" &&
736 dialogwritefloppyset ||
737 dialognofloppyset
738 }
740 #
741 # Create floppy image set
742 #
743 export IMAGE_SET='
744 <window title="Image set generator" icon-name="gtk-floppy">
745 <vbox>
746 <text use-markup="true">
747 <label>
748 "
749 <b>Create a boot floppy set</b>
750 "
751 </label>
752 </text>
753 <notebook labels="Slitaz only|Any Linux">
754 <frame Slitaz only (no size limit)>
755 <vbox>
756 <text wrap="false" width-chars="44" use-markup="true">
757 <label>
758 "
759 Slitaz uses a floppy boot flavor as a first
760 stage boot to break the tiny loader 15MB limit.
761 "
762 </label>
763 </text>
764 <hbox>
765 <text use-markup="true">
766 <label>"<b>Slitaz ISO : </b>"</label>
767 </text>
768 <entry accept="filename">
769 <label>Select a Slitaz ISO image</label>
770 <variable>ISO</variable>
771 </entry>
772 <button>
773 <input file stock="gtk-open"></input>
774 <action type="fileselect">ISO</action>
775 </button>
776 </hbox>
777 <hbox>
778 <text use-markup="true">
779 <label>"<b>Output directory : </b>"</label>
780 </text>
781 <entry accept="directory">
782 <label>Select output directory</label>
783 <variable>FILE_DIRECTORY</variable>
784 <default>/tmp</default>
785 </entry>
786 <button>
787 <input file stock="gtk-open"></input>
788 <action type="fileselect">FILE_DIRECTORY</action>
789 </button>
790 </hbox>
791 <hbox>
792 <button>
793 <input file icon="forward"></input>
794 <label>Create image set from ISO boot</label>
795 <action>cd $FILE_DIRECTORY; bootfloppybox call mkisofloppiesxterm $ISO</action>
796 <action type="closewindow">IMAGE_SET</action>
797 </button>
798 </hbox>
799 </vbox>
800 </frame>
801 <frame Any Linux distribution (max total size 14-15MB)>
802 <vbox>
803 <text wrap="false" width-chars="44" use-markup="true">
804 <label>
805 "
806 The total size of the kernel and the initramfs must be
807 lower than 14-15MB due to the tiny boot loader design.
808 "
809 </label>
810 </text>
811 <hbox>
812 <text use-markup="true">
813 <label>"<b>Kernel : </b>"</label>
814 </text>
815 <entry accept="filename">
816 <label>Select a linux kernel</label>
817 <variable>KERNEL</variable>
818 </entry>
819 <button>
820 <input file stock="gtk-open"></input>
821 <action type="fileselect">KERNEL</action>
822 </button>
823 </hbox>
824 <hbox>
825 <text use-markup="true">
826 <label>"<b>Initramfs : </b>"</label>
827 </text>
828 <entry accept="filename">
829 <label>Select an initramfs/initrd file</label>
830 <variable>INITRD</variable>
831 </entry>
832 <button>
833 <input file stock="gtk-open"></input>
834 <action type="fileselect">INITRD</action>
835 </button>
836 </hbox>
837 <hbox>
838 <text use-markup="true">
839 <label>"<b>Cmdline : </b>"</label>
840 </text>
841 <entry>
842 <label>Enter kernel arguments</label>
843 <variable>CMDLINE</variable>
844 <default>rw root=/dev/null autologin</default>
845 </entry>
846 </hbox>
847 <hbox>
848 <text use-markup="true">
849 <label>"<b>Output directory : </b>"</label>
850 </text>
851 <entry accept="directory">
852 <label>Select output directory</label>
853 <variable>OUTPUT_DIRECTORY</variable>
854 <default>/tmp</default>
855 </entry>
856 <button>
857 <input file stock="gtk-open"></input>
858 <action type="fileselect">OUTPUT_DIRECTORY</action>
859 </button>
860 </hbox>
861 <hbox>
862 <button>
863 <input file icon="forward"></input>
864 <label>Create image set</label>
865 <action>cd $OUTPUT_DIRECTORY; bootfloppybox call mkfloppies "$KERNEL" "$INITRD" "$CMDLINE"</action>
866 <action type="closewindow">IMAGE_SET</action>
867 </button>
868 </hbox>
869 </vbox>
870 </frame>
871 </notebook>
872 <hbox>
873 <button>
874 <input file icon="gtk-close"></input>
875 <action type="closewindow">IMAGE_SET</action>
876 </button>
877 </hbox>
878 </vbox>
879 </window>
880 '
882 #
883 # Read/write floppy images
884 #
885 export FLOPPY_IMAGE='
886 <window title="Floppy image manager" icon-name="gtk-floppy">
887 <vbox>
888 <frame Floppy disk drive>
889 <hbox>
890 <text use-markup="true">
891 <label>"<b>Device : </b>"</label>
892 </text>
893 <combobox>
894 <variable>DEVICE</variable>'
895 FLOPPY_DEV=""
896 for i in $(list_floppy); do
897 FLOPPY_DEV="$FLOPPY_DEV
898 <item>/dev/$i</item>"
899 done
900 FLOPPY_IMAGE="$FLOPPY_IMAGE$FLOPPY_DEV
901 </combobox>
902 <button>
903 <label>Format floppy</label>
904 <input file icon=\"media-floppy\"></input>
905 <action>fdformat -n $DEVICE</action>
906 </button>
907 </hbox>
908 </frame>
909 <frame Floppy image file>
910 <hbox>
911 <text use-markup=\"true\">
912 <label>\"<b>File : </b>\"</label>
913 </text>
914 <entry accept=\"filename\">
915 <label>Select a floppy image</label>
916 <variable>IMAGE</variable>
917 </entry>
918 <button>
919 <input file stock=\"gtk-open\"></input>
920 <action type=\"fileselect\">IMAGE</action>
921 </button>
922 </hbox>
923 </frame>
924 <hbox>
925 <button>
926 <input file icon=\"reload\"></input>
927 <label>Create image set</label>
928 <action type=\"launch\">IMAGE_SET</action>
929 </button>
930 <button>
931 <input file icon=\"go-jump\"></input>
932 <label>Write image to floppy</label>
933 <action>dd if=\$IMAGE of=\$DEVICE</action>
934 </button>
935 <button>
936 <input file icon=\"undo\"></input>
937 <label>Get floppy image</label>
938 <action>dd if=\$DEVICE of=\$IMAGE</action>
939 </button>
940 <button>
941 <input file icon=\"gtk-close\"></input>
942 <action type=\"closewindow\">FLOPPY_IMAGE</action>
943 </button>
944 </hbox>
945 </vbox>
946 </window>
947 "
949 gtkdialogshowfloppyset()
950 {
951 #
952 # Show floppy image set
953 #
954 IMAGE_SHOW='
955 <window title="Image set" icon-name="gtk-floppy">
956 <vbox>
957 <text use-markup="true">
958 <label>
959 "
960 <b>Boot floppy images</b>
961 "
962 </label>
963 </text>
964 <tree>
965 <width>50</width><height>140</height>
966 <label>Size|File</label>
967 <input>du -h fd???.img | sed "s/\t/|/" </input>
968 </tree>
969 <hbox>
970 '
971 [ 0$1 -gt $((15 * 1024 * 1024)) ] && IMAGE_SHOW="$IMAGE_SHOW
972 <frame WARNING>
973 <text>
974 <label>
975 \"This floppy set breaks the 15MB limit ($1 bytes).
976 It may not be able to complete the boot process.\"
977 </label>
978 </text>
979 </frame>
980 </hbox>
981 <hbox>
982 "
983 list_floppy check && IMAGE_SHOW="$IMAGE_SHOW
984 <button>
985 <input file icon=\"media-floppy\"></input>
986 <label>Manage images</label>
987 <action type=\"launch\">FLOPPY_IMAGE</action>
988 </button>
989 "
990 IMAGE_SHOW="$IMAGE_SHOW
991 <button>
992 <input file icon=\"gtk-close\"></input>
993 <action type=\"closewindow\">IMAGE_SET</action>
994 </button>
995 </hbox>
996 </vbox>
997 </window>
998 "
999 export IMAGE_SHOW
1000 gtkdialog --program=IMAGE_SHOW
1003 while true; do
1005 if [ "$1" == "call" ]; then
1006 case "$2" in
1007 mkmenu) mkmenu $3;;
1008 mkisofloppiesxterm)
1009 shift 2
1010 xterm -geometry 80x16 -title "Build boot floppies from ISO" \
1011 -e "$0 call mkisofloppies $@ ; echo -e \"----\nENTER to continue...\" && read close"
1012 gtkdialogshowfloppyset
1013 ;;
1014 mkisofloppies)
1015 shift 2
1016 floppysetfromiso $@
1017 ;;
1018 mkfloppies)
1019 shift 2
1020 floppyset "$@"
1021 sz=$(cat fd???.img | wc -c)
1022 if [ -n "$XAUTHORITY" ]; then
1023 gtkdialogshowfloppyset $sz
1024 else
1025 if [ $sz -gt $((15 * 1024 * 1024)) ]; then
1026 cat <<EOT
1027 This floppy set breaks the 15MB limit ($sz bytes).
1028 It may not be able to complete the boot process.
1029 EOT
1030 fi
1031 fi
1032 ;;
1033 install)
1034 DIR=/tmp/mkbootfloppy$$
1035 mkdir -p $DIR
1036 DEVICE=$4
1037 file=$5
1038 case "$3" in
1039 dialog*)
1040 shift 2
1041 $@
1042 ;;
1043 grub*)
1044 mkdir -p $DIR/boot/grub
1045 [ -f /usr/share/boot/btmgr -a -f /usr/share/boot/memdisk.lzma ] \
1046 && cat /usr/share/boot/btmgr /dev/zero | \
1047 dd bs=18k count=80 | gzip -9 > \
1048 $DIR/boot/btmgr.gz \
1049 && unlzma -c /usr/share/boot/memdisk.lzma > \
1050 $DIR/boot/memdisk
1051 [ -f /usr/share/boot/plpbt.bin ] \
1052 && cp /usr/share/boot/plpbt.bin $DIR/boot
1053 [ -f /usr/share/boot/etherboot ] \
1054 && cp /usr/share/boot/etherboot $DIR/boot
1055 [ -f /boot/gpxe ]\
1056 && cp /boot/gpxe $DIR/boot
1057 [ -f /usr/share/boot/memtest.lzma -a \
1058 -f /usr/share/boot/memdisk.lzma ] \
1059 && unlzma -c /usr/share/boot/memtest.lzma | \
1060 cat - /dev/zero | dd bs=18k count=80 | \
1061 gzip -9 > $DIR/boot/memtest.gz \
1062 && unlzma -c /usr/share/boot/memdisk.lzma > \
1063 $DIR/boot/memdisk
1064 install_grub $DIR $3
1065 ;;
1066 *)
1067 case "$file" in
1068 *.lzma) action="unlzma -c";;
1069 *.gz) action="zcat";;
1070 *) action="cat";;
1071 esac
1072 case "$DEVICE" in
1073 /dev/*) $action $file > $DEVICE;;
1074 flopp*) $action $file | cat - /dev/zero | \
1075 dd bs=18k count=80 > boot.fd;;
1076 cdrom*)
1077 mkdir -p $DIR/boot/grub
1078 case "$3" in
1079 btmgr|memtest)
1080 $action $file | cat - /dev/zero | \
1081 dd bs=18k count=80 | \
1082 gzip -9 > $DIR/boot/$3.gz
1083 unlzma -c /usr/share/boot/memdisk.lzma \
1084 > $DIR/boot/memdisk
1085 cat > /tmp/floppybox.grub.menu << EOT
1086 # grub menu
1087 timeout 0
1088 title $3
1089 kernel /boot/memdisk floppy c=80 h=2 s=18
1090 initrd /boot/$3.gz
1091 EOT
1092 ;;
1093 *) $action $file > $DIR/boot/$3
1094 cat > /tmp/floppybox.grub.menu << EOT
1095 # grub menu
1096 timeout 0
1097 title $3
1098 kernel /boot/$3
1099 EOT
1100 ;;
1101 esac
1102 install_grub $DIR grub
1103 ;;
1104 esac
1105 ;;
1106 esac
1107 rm -rf $DIR
1108 ;;
1109 get-plop)
1110 mkdir -p /tmp/get-plop$$
1111 PLOP_URL=http://mirror.slitaz.org/boot/plpbt.bin
1112 wget -O - $PLOP_URL > /tmp/get-plop$$/plpbt.bin
1113 VERSION="$(strings /tmp/get-plop$$/plpbt.bin \
1114 | grep 'Boot Manager v' | sed 's/.* v\([0-9\.]*\) .*/\1/')"
1115 mkdir -p $(dirname /tmp/get-plop$$/plop-$VERSION/fs/$3)
1116 mv /tmp/get-plop$$/plpbt.bin \
1117 /tmp/get-plop$$/plop-$VERSION/fs/$3
1118 if [ -s /tmp/get-plop$$/plop-$VERSION/fs/$3 ]; then
1119 cat > /tmp/get-plop$$/plop-$VERSION/receipt <<EOT
1120 PACKAGE="plop"
1121 VERSION="$VERSION"
1122 CATEGORY="non-free"
1123 SHORT_DESC="Plop boot manager."
1124 WEB_SITE="http://www.plop.at/en/bootmanager.html"
1125 EOT
1126 ( cd /tmp/get-plop$$ ; tazpkg pack plop-$VERSION )
1127 tazpkg install /tmp/get-plop$$/plop-$VERSION.tazpkg
1128 fi
1129 rm -rf /tmp/get-plop$$
1130 ;;
1131 *) echo "Invalid command $0 $@" 1>&2
1132 exit 1;;
1133 esac
1134 exit 0
1135 fi
1137 if [ -z "$XAUTHORITY" ]; then
1139 : ${DIALOG=dialog}
1141 DEVICE=/dev/fd0
1142 list_floppy check || DEVICE="floppy"
1143 while true; do
1144 exec 3>&1
1145 ID_SOURCE=`$DIALOG --title " Choose a boot floppy " \
1146 --backtitle "Boot Floppy Creation on $DEVICE" --clear \
1147 --extra-button --extra-label "Change floppy" \
1148 --colors --radiolist "
1149 Create a floppy or a cdrom to boot a LiveCD in a PXE network...
1150 May need a floppy disk in drive. Erase the whole floppy disk.
1151 " 18 70 50\
1152 FloppySet "Boot Slitaz with floppies only." on \
1153 SmartBtmgr "Boot any partition or ATAPI CD-ROM." off \
1154 Plop "Boot USB harddisk floppy or CD/DVD." off \
1155 Etherboot "Replacement for proprietary PXE ROMs." off \
1156 gPXE "Boot from http://boot.slitaz.org/" off \
1157 Memtest86+ "Memory failures detection tool." off \
1158 Grub4DOS "Enhanced grub version supporting NTFS." off \
1159 Grub "Boot loader with command shell." off \
1160 2>&1 1>&3`
1161 retval=$?
1162 exec 3>&-
1163 check_retval
1164 if [ "$retval" = "3" ]; then
1165 select_floppy
1166 continue;
1167 fi
1168 while read key file pkg; do
1169 [ "$key" = "$ID_SOURCE" ] || continue
1170 if [ ! -f "$file" ]; then
1171 $DIALOG --title " Install package " --colors \
1172 --backtitle "Boot Floppy Creation" --clear \
1173 --yes-label "Install" \
1174 --no-label "Quit" \
1175 --yesno "The package $pkg is not yet installed. Install it ?" 18 70
1176 retval=$?
1177 if [ "$pkg" = "plop" ]; then
1178 bootfloppybox call get-plop $file
1179 else
1180 tazpkg get-install $pkg
1181 fi
1182 fi
1183 bootfloppybox call install "$pkg" "$DEVICE" "$file"
1184 exit 0
1185 done <<EOT
1186 FloppySet /bin/dd dialogfloppyset
1187 SmartBtmgr /usr/share/boot/btmgr btmgr
1188 Plop /usr/share/boot/plpbt.bin plop
1189 Etherboot /usr/share/boot/etherboot etherboot
1190 gPXE /boot/gpxe gpxe
1191 Memtest86+ /usr/share/boot/memtest.lzma memtest
1192 Grub4DOS /usr/share/boot/grldr.lzma grub4dos
1193 Grub /usr/sbin/grub grub
1194 EOT
1195 done
1196 fi
1198 # Describe gPXE arguments.
1200 export HELP='
1201 <window title="gPXE forced url" icon-name="gtk-floppy">
1202 <vbox>
1203 <text use-markup="true">
1204 <label>"
1205 <b>Web boot parameters</b>"
1206 </label>
1207 </text>
1208 <frame>
1209 <text wrap="true" width-chars="58" use-markup="true">
1210 <label>
1211 "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.
1213 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>.
1215 You can override 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>
1217 The <i>nodhcp</i> keyword avoids dhcp timeouts and the <i>url=</i> keyword is optional when the url is the only one argument.
1219 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.
1221 </label>
1222 </text>
1223 </frame>
1224 </vbox>
1225 </window>
1228 # Write bootfloppy image to floppy device.
1230 BOOT_DIALOG='
1231 <window title="bootfloppybox" icon-name="gtk-floppy">
1232 <vbox>
1234 <text use-markup="true">
1235 <label>
1237 <b>SliTaz - Bootfloppybox</b>"
1238 </label>
1239 </text>
1240 <text wrap="false" width-chars="44" use-markup="true">
1241 <label>
1243 Create a floppy or a cdrom to boot a LiveCD in a PXE network or the WEB...
1244 May need a floppy disk in drive. Erase the whole floppy disk.
1246 </label>
1247 </text>
1249 <frame Floppy disk drive>
1250 <hbox>
1251 <text use-markup="true">
1252 <label>"<b>Device : </b>"</label>
1253 </text>
1254 <combobox>
1255 <variable>DEVICE</variable>'
1256 FLOPPY_DEV=""
1257 for i in $(list_floppy); do
1258 FLOPPY_DEV="$FLOPPY_DEV
1259 <item>/dev/$i</item>"
1260 done
1261 BOOT_DIALOG="$BOOT_DIALOG$FLOPPY_DEV
1262 <item>floppy image (boot.fd)</item>
1263 <item>cdrom image (boot.iso)</item>
1264 </combobox>"
1265 if [ -n "$FLOPPY_DEV" ]; then
1266 tmp='
1267 <button>
1268 <label>Format floppy</label>
1269 <input file icon="media-floppy"></input>
1270 <action>case "$DEVICE" in /dev/*) fdformat -n $DEVICE;; esac</action>
1271 </button>'
1272 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1273 fi
1274 tmp='
1275 </hbox>
1276 </frame>
1277 <notebook labels="Set|LiveCD|USB|PXE Network|WEB Network|Memory Test|Windows|Expert">
1278 <frame Boot floppy set (many floppies)>
1279 <vbox>
1280 <hbox>
1281 <text wrap="true" width-chars="58" use-markup="true">
1282 <label>
1284 Only people without a CD-ROM, USB and Network should use a floppy set.
1285 The images are built from an ISO boot or from a Linux kernel, an initramfs
1286 and a boot command line. Non Slitaz boot floppy sets are limited to 15MB.
1288 </label>
1289 </text>
1290 </hbox>
1291 <hbox>
1292 <button>
1293 <label>Create image set</label>
1294 <input file icon="forward"></input>
1295 <action type="launch">IMAGE_SET</action>
1296 </button>
1297 </hbox>
1298 </vbox>
1299 </frame>
1301 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1302 while read name file pkg desc; do
1303 tmp="<frame $name (single floppy)>
1304 <hbox>
1305 <text wrap=\"true\" width-chars=\"58\" use-markup=\"true\">
1306 <label>
1307 \"
1308 $(echo -e $desc)
1309 \"
1310 </label>
1311 </text>
1312 </hbox>
1313 <hbox>
1315 if [ -f $file ]; then
1316 if [ "$pkg" = "grub" -o "$pkg" = "grub4dos" ]; then
1317 tmp="$tmp
1318 <button>
1319 <label>Grub menu</label>
1320 <input file icon=\"accessories-text-editor\"></input>
1321 <action>bootfloppybox call mkmenu $pkg</action>
1322 <action type=\"lauch\">leafpad /tmp/floppybox.grub.menu</action>
1323 </button>
1325 elif [ "$pkg" = "etherboot" ]; then
1326 tmp="$tmp
1327 <button>
1328 <input file icon=\"browser\"></input>
1329 <label>Wiki</label>
1330 <action>browser http://doc.slitaz.org/en:guides:pxe &</action>
1331 </button>
1333 elif [ "$pkg" = "gpxe" ]; then
1334 tmp="$tmp
1335 <text wrap=\"true\" use-markup=\"true\">
1336 <label> \"<b>Boot URL:</b>\" </label>
1337 </text>
1338 <entry>
1339 <default>$(dd if=$file bs=1 skip=519 count=255 2>/dev/null | strings)</default>
1340 <variable>URL</variable>
1341 </entry>
1342 </hbox>
1343 <hbox>
1344 <button>
1345 <input file icon=\"browser\"></input>
1346 <label>Wiki</label>
1347 <action>browser http://doc.slitaz.org/en:guides:pxe &</action>
1348 </button>
1349 <button help>
1350 <action type=\"launch\">HELP</action>
1351 </button>
1352 <button>
1353 <label>Update</label>
1354 <input file icon=\"reload\"></input>
1355 <action>echo -n \"\$URL\" | cat - /dev/zero | dd conv=notrunc bs=1 count=255 seek=519 of=$file 2>/dev/null</action>
1356 </button>
1358 fi
1359 receipt=/var/lib/tazpkg/installed/$pkg/receipt
1360 if [ -f $receipt ]; then
1361 . $receipt
1362 tmp="$tmp
1363 <button>
1364 <input file icon=\"browser\"></input>
1365 <label>Web</label>
1366 <action>browser $WEB_SITE &</action>
1367 </button>
1369 fi
1370 tmp="$tmp
1371 <button>
1372 <label>Write floppy</label>
1373 <input file icon=\"forward\"></input>
1374 <action>bootfloppybox call install \"$pkg\" \"\$DEVICE\" \"$file\"</action>
1375 </button>
1376 </hbox>
1377 </frame>
1379 else
1380 tmp2="tazpkg get-install $pkg --forced"
1381 [ "$pkg" = "plop" ] && tmp2="bootfloppybox call get-plop $file"
1382 tmp="$tmp
1383 <text wrap=\"true\" width-chars=\"34\" use-markup=\"true\">
1384 <label>
1385 \"<i>The package <b>$pkg</b> is not yet installed</i>\"
1386 </label>
1387 </text>
1388 <button>
1389 <input file icon=\"go-jump\"></input>
1390 <label>Install</label>
1391 <action>[ -f /var/lib/tazpkg/packages.list ] || tazpkg recharge</action>
1392 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title \"$pkg install\" -e \"$tmp2 ; sleep 2\"</action>
1393 <action type=\"exit\">restart</action>
1394 </button>
1395 </hbox>
1396 </frame>
1398 fi
1399 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1400 done <<EOT
1401 SmartBtmgr /usr/share/boot/btmgr btmgr This OS independent Smart Boot Manager can boot \\\\nany partition or ATAPI CD-ROM.
1402 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.
1403 Etherboot /usr/share/boot/etherboot etherboot This network bootloader provides a replacement \\\\nfor proprietary PXE or NBI ROMs.
1404 gPXE /boot/gpxe gpxe PXE / iSCSI / AoE network bootloader.
1405 Memtest86+ /usr/share/boot/memtest.lzma memtest Memory failures detection tool.
1406 Grub4DOS /usr/share/boot/grldr.lzma grub4dos Enhanced grub version supporting NTFS.
1407 Grub /usr/sbin/grub grub General purpose boot loader with command shell.
1408 EOT
1409 tmp='
1410 </notebook>
1411 <hbox>
1413 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1414 if [ -e /dev/cdrom ]; then
1415 tmp='
1416 <button>
1417 <input file icon="media-cdrom"></input>
1418 <label>Burn cdrom image</label>
1419 <action>burnbox</action>
1420 </button>
1422 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1423 fi
1424 if list_floppy check; then
1425 tmp='
1426 <button>
1427 <input file icon="media-floppy"></input>
1428 <label>Manage floppy image</label>
1429 <action type="launch">FLOPPY_IMAGE</action>
1430 </button>
1432 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1433 fi
1434 tmp='
1435 <button>
1436 <input file icon="exit"></input>
1437 <label>Exit</label>
1438 <action type="exit">Exit</action>
1439 </button>
1440 </hbox>
1442 </vbox>
1443 </window>
1445 BOOT_DIALOG="$BOOT_DIALOG$tmp"
1446 export BOOT_DIALOG
1448 # Only root can create floppy.
1449 check_root
1450 gtkdialog --program=BOOT_DIALOG | grep -q 'EXIT="restart"' && continue
1451 rm -f /tmp/floppybox.grub.menu
1452 exit 0
1453 done