wok view syslinux/stuff/iso2exe/taziso @ rev 17929

syslinux/taziso: install grub
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 11 18:26:44 2015 +0200 (2015-04-11)
parents 7034b53ca07c
children 4c62635505df
line source
1 #!/bin/sh
3 [ $(id -u) -eq 0 ] || exec su -c "$0 $@"
5 DIALOG=dialog
7 ddq()
8 {
9 dd $@ 2> /dev/null
10 }
12 get()
13 {
14 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
15 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2
16 }
18 bytes2bin()
19 {
20 for i in $@ ; do
21 printf '\\\\x%02X' $(($i&255))
22 done | xargs echo -en
23 }
25 words2bin()
26 {
27 for i in $@ ; do
28 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255))
29 done | xargs echo -en
30 }
32 gettazboot()
33 {
34 echo "Creating $(basename $1) ..."
35 if [ $(get 0 $ISO) -eq 23117 ]; then
36 O=$(($(get 64 $ISO) - 0xC0))
37 L=$(($(get 20 $ISO) - 0xC0 - $(get 24 $ISO) - $O))
38 S=$((32+$L))
39 P=$((($S+511)/512))
40 E=$((4096-(32*$P)))
41 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
42 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
43 ddq bs=1 count=$L skip=$(echo $O) if=$ISO >> $1
44 else
45 wget -O $1 http://mirror.slitaz.org/boot/tazboot.exe
46 fi
47 }
49 uncpio()
50 {
51 [ -s "$1" ] || return
52 echo -en "\n Extracting $(basename $1) ..."
53 case $(get 0 $1) in
54 *35615) ( zcat || gunzip ) ;;
55 *14333) unxz ;;
56 *\ 93) unlzma ;;
57 *) cat ;;
58 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
59 }
61 dotwait()
62 {
63 echo -n "${1:-Install filesystem}.."
64 touch /tmp/wait
65 while [ -e /tmp/wait ]; do
66 echo -n "." > /dev/tty
67 sleep 1
68 done &
69 }
71 getuuid()
72 {
73 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
74 [ "$dev" ] &&
75 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
76 echo "/dev/hda1"
77 }
79 tazusbinitfs()
80 {
81 PAD=$(($(stat -c %s $1) % 4))
82 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
83 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
84 cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
85 cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null
86 cat > /tmp/fs$$/init1 <<EOT
87 #!/bin/sh
88 sed -i 's|sbin/init|init2|' /init
89 exec /init
90 EOT
91 cat > /tmp/fs$$/init2 <<EOT
92 #!/bin/sh
94 mount -t proc /proc /proc
95 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
96 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
97 mount / -o remount,rw
98 mkdir /mnt/dos
99 rm -f /cmdline 2> /dev/null
100 mount / -o remount,ro
101 mnt=/mnt/dos/\${v#*/}
102 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
103 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
104 mount \$dev /mnt/dos
105 if [ ! -d /mnt/dos/slitaz ]; then
106 umount /mnt/dos 2> /dev/null
107 (blkid /dev/[sh]d* || blkid) | while read dev line; do
108 case "\$line" in
109 *ntfs*|*vfat*|*msdos*) ;;
110 *) continue ;;
111 esac
112 mount \${dev%:} /mnt/dos
113 [ -d /mnt/dos/slitaz ] && break
114 umount /mnt/dos
115 done
116 fi
117 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
118 mount --bind \$mnt /home
119 umount /proc
120 exec /sbin/init
121 EOT
122 chmod 755 /tmp/fs$$/init?
123 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
124 rm -rf /tmp/fs$$
125 }
127 mkinitrd()
128 {
129 echo -en "\nCreating $(basename $1) "
130 fs=/tmp/fs$$
131 for i in bin lib dev proc tmp mnt etc ; do
132 mkdir -p $fs/$i
133 done
134 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
135 /dev/fuse /dev/hd* /dev/sd* ; do
136 cp -a $2$i $fs/dev/
137 done
138 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
139 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
140 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
141 cp $i $fs/bin
142 done
143 cp -a /lib/ld-* $fs/lib
144 for i in $(busybox | sed '/Current/,$!d'); do
145 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
146 done
147 ln -s /proc/mounts $fs/etc/mtab
148 sed 's/ .*//' /proc/modules | while read mod ; do
149 find /lib/modules/ | grep $mod.ko | \
150 sed 's|.*|cp & $fs/lib|' | sh
151 done
152 cat > $fs/init <<EOT
153 #!/bin/sh
155 arg()
156 {
157 grep -q \$1 /proc/cmdline &&
158 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
159 echo "\$2 \$val"
160 }
162 mount -t proc /proc /proc
163 arg debug "shell" && debug=true && set -x
164 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
165 arg mount "Mount device"
166 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
167 arg subroot "Change root to directory"
168 if [ -d /mnt/\$val ]; then
169 umount /mnt 2> /dev/null
170 (blkid /dev/[sh]d* || blkid) | while read dev line; do
171 case "\$line" in
172 *ntfs*|*vfat*|*msdos*) ;;
173 *) continue ;;
174 esac
175 mount \${dev%:} /mnt
176 [ -d /mnt/\$val ] && break
177 umount /mnt
178 done
179 fi
180 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
181 mount --bind /mnt /mnt/\$val/mnt/dos
182 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
183 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
184 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
185 [ "$debug" = "true" ] && sh
186 umount /proc
187 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
188 EOT
189 chmod +x $fs/init
190 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
191 rm -rf $fs /tmp/wait
192 }
194 ls_r()
195 {
196 ls -r $@ 2> /dev/null || ls $@
197 }
199 doinstall()
200 {
201 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
202 if ! mount.posixovl -F $mnt/slitaz -- \
203 -oallow_other -odefault_permissions -osuid; then
204 echo "Can't install SliTaz. Abort."
205 sleep 5
206 return 1
207 fi
208 dotwait "Install root filesystem in /slitaz.."
209 if [ "$1" ]; then
210 ls_r /media/cdrom/boot/rootfs*gz | \
211 xargs cat > $mnt/slitaz/boot/rootfs.gz
212 tazusbinitfs $mnt/slitaz/boot/rootfs.gz
213 initrd=rootfs.gz
214 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
215 else
216 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
217 uncpio $i $mnt/slitaz
218 done
219 for i in $packages_list; do
220 tazpkg get-install $i --root=$mnt/slitaz
221 done
222 for i in $packages_dir/*.tazpkg; do
223 [ -s "$i" ] &&
224 tazpkg install $i --root=$mnt/slitaz
225 done
226 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
227 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
228 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz
229 initrd=initrd
230 extraargs="mount=$(getuuid) subroot=slitaz"
231 fi
232 echo -en "\nInstall boot files..."
233 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
234 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
235 /media/cdrom/README /media/cdrom/boot/memtest* ; do
236 [ -s $i ] && cp $i $mnt/slitaz/boot
237 done
238 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
239 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
240 mv $i $i.exe
241 done
242 gettazboot $mnt/slitaz/boot/tazboot.exe
243 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
244 kernel=/slitaz/boot/bzimage
245 initrd=/slitaz/boot/$initrd
246 rw root=/dev/null $extraargs autologin
247 EOT
248 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
249 $mnt/slitaz/boot/README
250 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
251 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
252 if grep -qs " $mnt " /proc/mounts && [ ! -d $mnt/boot/grub ]; then
253 mkdir -p $mnt/boot/grub
254 cp -a /usr/lib/grub/*/* $mnt/boot/grub
255 cat > $mnt/boot/grub/menu.lst <<EOT
256 # /boot/grub/menu.lst: GRUB boot loader configuration.
258 # By default, boot the first entry.
259 default 0
261 # Boot automatically after 8 secs.
262 timeout 8
264 title Microsoft Windows
265 chainloader +1
267 title SliTaz GNU/Linux $(cat $mnt/slitaz/etc/slitaz-release)
268 kernel /slitaz/boot/bzimage rw root=/dev/null $extraargs autologin
269 initrd /slitaz/boot/$initrd
271 EOT
272 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
273 base=${dev//[0-9]/}
274 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
275 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
276 #!/bin/sh
278 [ -s /boot/grub/$(basename $base) ] &&
279 dd if=/boot/grub/$(basename $base) of=$base
280 EOT
281 grub-install --no-floppy --root-directory=$mnt $base
282 fi
283 rm -f /tmp/wait
284 umount $mnt/slitaz
285 return 0
286 }
288 windev()
289 {
290 if [ -b "$1" ]; then
291 device=$1
292 elif [ "$1" ]; then
293 echo "Invalid Windows partition"
294 return 1
295 else
296 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')"
297 [ "$DEV" ] || return
298 cat > /tmp/dialog$$ <<EOT
299 $DIALOG --clear \
300 --title " Select your Windows partition " \
301 --menu "\nPlease select the Windows partition according to its known size.
302 The data will be kept untouched.\n" \
303 17 70 8 \
304 $(for i in $DEV ; do
305 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
306 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
307 done)
308 EOT
309 exec 3>&1
310 [ $? -eq 0 ] || return
311 device=$(. /tmp/dialog$$ 2>&1 1>&3)
312 exec 3>&-
313 rm -f /tmp/dialog$$
314 fi
315 mnt=/tmp/mnt$$
316 mkdir -p $mnt && mount $device $mnt
317 }
319 extra_packages()
320 {
321 packages_list=
322 packages_dir=
323 $DIALOG --clear \
324 --title " Extra packages " \
325 --defaultno --yesno \
326 "
327 Do you want to add extra packages ?
328 " 7 70
329 [ $? -eq 0 ] || return
330 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
331 if [ -s /media/cdrom/boot/vmlinuz-$(uname -r) ]; then
332 cat > /tmp/dialog$$ <<EOT
333 $DIALOG --clear \
334 --title " Select the packages " \
335 --separate-output \
336 --cancel-label "Skip" \
337 --checklist "Please select the packages you want to install. Try with the first letter." \
338 23 78 20 \\
339 EOT
340 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
341 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
342 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
343 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
344 fi
345 cat > /tmp/dialog$$ <<EOT
346 $DIALOG --clear \
347 --title "Please select the directory with every custom package to install." \
348 --cancel-label "Skip" \
349 --dselect $PWD 13 78
350 EOT
351 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
352 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
353 rm -f /tmp/dialog$$ /tmp/dialog.out$$
354 }
356 _install()
357 {
358 extra_packages
359 $DIALOG --clear \
360 --title " SliTaz UMSDOS way installation " \
361 --yes-label "Install" --yesno \
362 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
363 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
364 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
365 To uninstall SliTaz, you have only to remove this directory.
366 The file \\boot.ini or \\config.sys may be modified too.\n\n
367 SliTaz may run slowly on 'UMSDOS way' installation due to the
368 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
369 To do a traditional installation with disk partitioning,
370 start SliTaz Live with 'SliTaz RAM boot' menu.\n
371 " 19 70
372 [ $? -eq 0 ] || return
373 doinstall
374 }
376 readtazbootconf()
377 {
378 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
379 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
380 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
381 }
383 bootinstalled()
384 {
385 [ "$(which kexec)" ] || return
386 [ -x $mnt/slitaz$1 ] || return
387 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
388 readtazbootconf
389 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
390 umount $mnt
391 rm -rf $mnt
392 umount -d /media/cdrom
393 kexec -e
394 }
396 mkzip()
397 {
398 device=
399 packages_list=
400 packages_dir=
401 mnt=/tmp/mnt$$
402 mkdir -p $mnt
403 $1 || return
404 wget -O $mnt/slitaz/boot/grldr http://mirror.slitaz.org/boot/grldr
405 readtazbootconf
406 cat > $mnt/slitaz/boot/menu.lst <<EOT
407 title SliTaz
408 kernel $kernel $cmdline
409 initrd $initrd
411 EOT
412 while read file title; do
413 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
414 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
415 title $title
416 kernel ${file#$mnt}
418 EOT
419 done <<EOT
420 memtest MemTest
421 pxe Web boot
422 EOT
423 unix2dos $mnt/slitaz/boot/menu.lst
424 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
425 For DOS users (real mode only):
427 Start SliTaz with \\slitaz\\boot\\tazboot.exe
430 For NT/2000/XP users:
432 1- Move the files grldr and menu.lst into the root directory
434 C:\\> copy \\slitaz\\boot\\grldr \\
435 C:\\> copy \\slitaz\\boot\\menu.lst \\
437 2- Remove boot.ini attributes
439 C:\\> attrib -r -h -s boot.ini
441 3- Append the following line to boot.init
443 C:\\grldr="slitaz"
445 4- Restore boot.ini attributes
447 C:\\> attrib +r +h +s boot.ini
449 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
450 EOT
451 ( cd $mnt ; zip -r9 $(basename $ISO .iso).zip slitaz )
452 [ "$(which advzip)" ] && advzip -z4 $mnt/*.zip
453 mv $mnt/*.zip .
454 umount $mnt
455 rm -rf $mnt
456 }
458 install()
459 {
460 windev $1 || return
461 packages_list=
462 packages_dir=
463 if [ "$1" ]; then
464 doinstall
465 else
466 _install && bootinstalled /sbin/init
467 fi
468 umount $mnt
469 rm -rf $mnt
470 }
472 inst2zip()
473 {
474 if [ "$1" ]; then
475 doinstall
476 else
477 mkzip _install
478 fi
479 }
481 _installtaz()
482 {
483 $DIALOG --clear \
484 --title " SliTaz TAZUSB way installation " \
485 --yes-label "Install" --yesno \
486 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
487 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
488 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
489 To uninstall SliTaz, you have only to remove this directory.
490 The file \\boot.ini or \\config.sys may be modified too.\n\n
491 The filesystem is loaded entirely into memory upon boot to
492 increase responsiveness. Only /home lands on hard disk.\n\n
493 To do a traditional installation with disk partitioning,
494 start SliTaz Live with 'SliTaz RAM boot' menu.\n
495 " 19 70
496 [ $? -eq 0 ] || return
497 doinstall tazusblike
498 }
500 installtaz()
501 {
502 windev $1 || return
503 packages_list=
504 packages_dir=
505 if [ "$1" ]; then
506 doinstall tazusblike
507 else
508 _installtaz && bootinstalled /boot/bzimage
509 fi
510 umount $mnt
511 rm -rf $mnt
512 }
514 insttaz2zip()
515 {
516 if [ "$1" ]; then
517 doinstall tazusblike
518 else
519 mkzip _installtaz
520 fi
521 }
523 bootiso()
524 {
525 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
526 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
527 cat $i
528 n=$((4 - ($(stat -c %s $i) % 4)))
529 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
530 done > /tmp/initrd$$
531 kernel=/media/cdrom/boot/bzImage
532 grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64
533 . /etc/locale.conf
534 kexec -l $kernel --initrd /tmp/initrd$$ --command-line \
535 "root=/dev/null autologin lang=$LANG kmap=$(cat /etc/keymap.conf)" &&
536 umount -d /media/cdrom
537 rm -f /tmp/initrd$$
538 kexec -e
539 }
541 tazboot()
542 {
543 if [ -z "$1" ]; then
544 $DIALOG --clear \
545 --title " SliTaz bootloader for DOS " \
546 --yes-label "Install" --yesno \
547 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
548 any linux kernel, multiple initramfs, a kernel command line and
549 an ISO image file loopback (retrieves files from an ISO file).\n\n
550 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
551 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
552 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
553 Examples for tazboot.cmd:\n\n\
554 bootfrom=\\isos\\slitaz-4.0.iso\n\
555 kernel=boot/bzImage\n\
556 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
557 rw root=/dev/null autologin\n\n\
558 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
559 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
560 " 24 78
561 [ $? -eq 0 ] || return
562 fi
563 gettazboot tazboot.exe
564 }
566 md5()
567 {
568 dotwait "Checking files"
569 ( cd /media/cdrom ; ${md5sum:-md5sum -c md5sum*} ) > /tmp/data
570 unset md5sum
571 rm -f /tmp/wait
572 if [ "$1" ]; then
573 cat /tmp/data
574 else
575 $DIALOG --clear \
576 --title " Checked files " \
577 --textbox /tmp/data 24 78
578 fi
579 rm -f /tmp/data
580 }
582 gotcdfile()
583 {
584 for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \
585 "/media/cdrom/*/isolinux/$1" ; do
586 file=$(ls $i 2> /dev/null | sed q)
587 [ -s "$file" ] && break
588 done
589 }
591 sha()
592 {
593 gotcdfile 'sha*sum*'
594 sha=$(basename $file)
595 md5sum="${sha%sum*}sum -c ${file#/media/cdrom/}"
596 md5 $@
597 }
599 readme()
600 {
601 gotcdfile 'README*'
602 if [ "$1" ]; then
603 cat $file
604 else
605 $DIALOG --clear \
606 --title " Readme " \
607 --textbox $file 24 78
608 fi
609 }
611 bzimage()
612 {
613 if [ -z "$1" ]; then
614 $DIALOG --clear \
615 --title " Create linux.exe ? " \
616 --yes-label "Install" --yesno \
617 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
618 The cmdline arguments are supported except initrd=,
619 vga= (you can try 'rdev -v') and mem= (partially).
620 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
621 " 12 70
622 [ $? -eq 0 ] || return
623 fi
624 cp /media/cdrom/boot/bzImage linux.exe
625 }
627 memtest()
628 {
629 if [ -z "$1" ]; then
630 $DIALOG --clear \
631 --title " Create memtest.exe ? " \
632 --yes-label "Install" --yesno \
633 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
634 computers. BIOS based memory tests are a quick, cursory check and often
635 miss many of the failures that are detected by Memtest86.\n
636 " 12 70
637 [ $? -eq 0 ] || return
638 fi
639 gotcdfile 'memtest*' && cp $file memtest.exe
640 }
642 mkfat12()
643 {
644 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
645 J=$(($(get 3 $1 1) + 0x02))
646 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
647 [ $R -lt 2500 ] || return
648 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
649 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
650 G="18 0 2 0 0 0 0 0"
651 [ $J -gt 25 ] || G=""
652 F=0
653 for i in 1 2 3; do
654 F=$((((2880-$R-$F-$F)*3+1023)/1024))
655 done
656 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
657 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
658 $G | ddq bs=1 of=/dev/fd0
659 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
660 for i in $R $(($R+$F)) ; do
661 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
662 done
663 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
664 }
666 mkfloppy()
667 {
668 dotwait "Create a $(basename $1) boot floppy"
669 ddq if=$1 of=/dev/fd0
670 mkfat12 $1
671 rm -f /tmp/wait
672 }
674 fdmemtest()
675 {
676 if [ -z "$1" ]; then
677 $DIALOG --clear \
678 --title " Create a Memtest86 boot floppy " \
679 --yes-label "Create floppy" --yesno \
680 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
681 computers. BIOS based memory tests are a quick, cursory check and often
682 miss many of the failures that are detected by Memtest86.\n\n
683 Please insert a blank disk in floppy drive.\n
684 " 12 70
685 [ $? -eq 0 ] || return
686 fi
687 gotcdfile 'memtest*' && mkfloppy $file
688 }
690 pxe()
691 {
692 gotcdfile '?pxe'
693 if [ -z "$1" ]; then
694 $DIALOG --clear \
695 --title " Create $(basename $file).exe ? " \
696 --yes-label "Install" --yesno \
697 "\nBoot your operating system from the internet and enjoy a full system
698 working entirely in RAM with speed and stability in mind. The Linux Kernel
699 and the complete SliTaz compressed root filesystem will be loaded into RAM
700 from the Web using PXE and HTTP protocols.\n
701 " 12 70
702 [ $? -eq 0 ] || return
703 fi
704 cp $file $(basename $file).exe
705 }
707 fdpxe()
708 {
709 if [ -z "$1" ]; then
710 $DIALOG --clear \
711 --title " Create a SliTaz Web boot floppy " \
712 --yes-label "Create floppy" --yesno \
713 "\nBoot your operating system from the internet and enjoy a full system
714 working entirely in RAM with speed and stability in mind. The Linux Kernel
715 and the complete SliTaz compressed root filesystem will be loaded into RAM
716 from the Web using PXE and HTTP protocols.\n\n
717 Please insert a blank disk in floppy drive.\n
718 " 12 70
719 [ $? -eq 0 ] || return
720 fi
721 gotcdfile '?pxe' && mkfloppy $file
722 }
724 menuitem()
725 {
726 [ "$3" ] && shift
727 echo -en "\"$1\" \"$2\""
728 }
730 gotposixovl()
731 {
732 mount.posixovl 2>&1 | grep -qi usage && menuitem "$@"
733 }
735 gotposixovlzip()
736 {
737 [ "$(which zip)" ] && gotposixovl "$1" "$2"
738 }
740 xfile()
741 {
742 [ "$(which $1)" ] && menuitem "$@"
743 }
745 cdfile()
746 {
747 gotcdfile "$1" && menuitem "$@"
748 }
750 isbzImage()
751 {
752 [ $(get 514 $file 4) -eq 1400005704 ] &&
753 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
754 }
756 cdfilex()
757 {
758 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
759 }
761 cdfilef()
762 {
763 [ -e /sys/block/fd0 ] && cdfile "$@"
764 }
766 cdexe()
767 {
768 gotcdfile "$1" &&
769 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
770 menuitem "$@"
771 }
773 misspkg()
774 {
775 for i in zip kexec-tools posixovl ; do
776 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
777 [ "$1" != "install" ] && menuitem "$@" && return
778 tazpkg get-install $i
779 done
780 }
782 missing()
783 {
784 misspkg install
785 }
787 ishybrid()
788 {
789 C=$((2048*$(get $(((17*2048) + 71)) $ISO 4)))
790 [ $(get $C $ISO 4) -eq 1 ] || return
791 [ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return
792 C=$((2048*$(get $(($C+40)) $ISO 4)))
793 [ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && menuitem "$@"
794 }
796 isiso()
797 {
798 [ $(get 32769 $ISO 4) -eq 808469571 ] && menuitem "$@"
799 }
801 gotisomd5()
802 {
803 [ "$(which md5sum 2> /dev/null)" ] &&
804 [ $(get 0 $ISO) -eq 23117 ] &&
805 [ $(get 18 $ISO) -ne 0 ] && menuitem "$@"
806 }
808 isomd5()
809 {
810 dotwait "Checking iso image"
811 [ "$(ddq if=$ISO bs=2k skip=16 \
812 count=$(echo $(get 32848 $ISO 4)) | md5sum)" == \
813 "$(ddq if=$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
814 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
815 echo -en "\rChecking iso hybrid boot..."
816 n=$(($(get 2 $ISO)-1+($(get 4 $ISO)-1)*512))
817 if [ $n -lt 40000 -a $n -gt 32768 ]; then
818 s=$(get 0 $ISO 2 $n | awk '{ i+= $0 } END { print i }')
819 [ $(((1+$s+$(get $(($n+1)) $ISO 1)) % 65536)) -eq 0 ] &&
820 echo "OK" || echo "ERROR"
821 fi
822 rm -f /tmp/wait
823 [ "$1" ] && return 0
824 echo -e "\rPress RETURN to continue."
825 read n
826 }
828 usbdev()
829 {
830 dotwait "Wait 5 seconds for USB devices"
831 sleep 5
832 rm -f /tmp/wait
833 DEV="$(grep -l 1 /sys/block/*/removable | \
834 sed 's|/sys/block/\(.*\)/removable|\1|')"
835 grep -qs 1 /sys/block/$DEV/ro && return
836 [ "$DEV" ] || return
837 cat > /tmp/dialog$$ <<EOT
838 $DIALOG --clear \
839 --title " Select your USB key " \
840 --menu "\nPlease select the USB key according to its known size.\n\n" \
841 14 70 4 \
842 $(for i in $DEV ; do
843 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
844 done) \
846 EOT
847 exec 3>&1
848 device=$(. /tmp/dialog$$ 2>&1 1>&3)
849 rm -f /tmp/dialog$$
850 retval=$?
851 exec 3>&-
852 rm -f /tmp/dialog$$
853 [ $retval -eq 0 ]
854 }
856 tazusbmsg()
857 {
858 [ "$(which tazusb 2> /dev/null)" ] || return
859 echo "You should choose 'USB key read/write installation' to be
860 able to save the package updates or your own configuration and data files.\n\n"
861 }
863 usbbootkey()
864 {
865 if [ -b "$1" ]; then
866 device=$1
867 elif [ "$1" ]; then
868 echo "Invalid USB key device"
869 return 1
870 else
871 $DIALOG --clear \
872 --title " Create a USB boot key " \
873 --yes-label "Continue" --yesno \
874 "\nThe USB key will be used like a CD-ROM. You will not be able to write
875 any data on the boot partition.\n\n
876 An extra FAT32 partition will be created with the remaining free space.\n\n
877 $(tazusbmsg)Please plug your USB stick in now.\n
878 " 16 70
879 [ $? -eq 0 ] || return
880 usbdev || return
882 # perform dd in progress bar
883 max=$(($(stat -c %s $ISO)/2048))
884 i=0; ddq if=$ISO bs=1024k | (
885 while ddq bs=1024k count=1 ; do
886 i=$(($i + 1))
887 [ $i -gt $max ] && break
888 echo $((($i*100)/$max)) | dialog --gauge \
889 " The ISO image transfer can be long. Please wait..." \
890 6 70 0 > /dev/tty 2>&1
891 done ) > $device
892 fi
894 # partition + fat32 format for the remaining space
895 for p in 0 16; do
896 get $((450+$p)) $device 2 12 | xargs echo | {
897 read dx cx ol oh ll lh
898 [ $dx -eq $((0x3F17)) ] || continue
899 cx=$(($cx & 0xFF00))
900 ofs=$(($ll+($lh<<16)))
901 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
902 m=$(($cx+($n/8)))
903 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
904 m=$((($m & 0xFF00)+(($m>>16)<<6)))
905 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
906 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
907 ddq bs=1 seek=$((462-$p)) of=$device
908 if [ "$(which mkdosfs 2> /dev/null)" ]; then
909 losetup -o $((512*$ofs)) /dev/loop2 $device
910 mkdosfs -n "SLITAZ BOOT" /dev/loop2
911 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
912 ddq bs=1 seek=28 of=/dev/loop2
913 sync
914 losetup -d /dev/loop2
915 fi
916 }
917 done
918 }
920 usbkey()
921 {
922 $DIALOG --clear \
923 --title " Create a SliTaz USB key " \
924 --yes-label "Continue" --yesno \
925 "\nUnlike a hard drive install, the filesystem is kept in a compressed
926 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
927 This should increase responsiveness, protect the filesystem against
928 accidental corruption and reduce read/writes to the USB drive.
929 Once setup, the tazusb utility can rewrite the root filesystem
930 with any changes you have made since booting up,
931 giving the effective benefits of a hard drive install.\n\n
932 /home is mounted on boot using the UUID of your particular flash drive.
933 Unlike a device name, the UUID has the benefit of never changing from machine
934 to machine.\n\n
935 Please plug your USB stick in now.\n
936 " 19 70
937 [ $? -eq 0 ] || return
938 usbdev || return
939 exec 3>&1
940 format=`$DIALOG --clear \
941 --title " Select the filesystem " \
942 --radiolist "\nPlease select the filesystem type to create.\n\n\
943 The filesystem creation will erase all the data \
944 in the USB key." 14 70 4 \
945 "none" "Do not erase the USB key" on \
946 "ext3" "Ext3 journaling filesystem" off \
947 "ext2" "Ext2 filesystem" off \
948 "fat32" "Windows FAT32 filesystem" off \
949 2>&1 1>&3`
950 retval=$?
951 exec 3>&-
952 [ $retval -eq 0 ] || return
953 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
954 tazusb gen-iso2usb $ISO $device
955 }
957 dokexec()
958 {
959 kexec -l $file || return
960 umount -d /media/cdrom
961 kexec -e
962 }
964 runmemtest()
965 {
966 gotcdfile 'memtest*' && dokexec
967 }
969 runpxe()
970 {
971 gotcdfile '?pxe' && dokexec
972 }
974 quit()
975 {
976 umount -d /media/cdrom
977 exit
978 }
980 ISO="$1"
981 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
982 mount -o loop,ro $ISO /media/cdrom
984 if [ "$2" == "list" ]; then
985 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
986 eval $line
987 echo
988 done | sed '/^$/d;/"usbkey"/d'
989 quit
990 fi
991 if grep -q "^$2()" $0; then
992 exe=$2
993 shift 2
994 if [ "$(eval $(grep "\"$exe\"" $0 | \
995 sed '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
996 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
997 $exe "$@"
998 fi
999 quit
1000 fi
1002 while true; do
1003 cat > /tmp/dialog$$ <<EOT
1004 $DIALOG --clear \
1005 --title " SliTaz ISO tool " \
1006 --menu "" 23 70 17 \
1007 $(cdfile 'README*' "readme" "Show the README file") \
1008 $(gotisomd5 "isomd5" "Check the ISO image") \
1009 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1010 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1011 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
1012 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1013 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1014 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1015 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1016 $(xfile tazusb "usbkey" "USB key read/write installation") \
1017 $(ishybrid "usbbootkey" "USB boot key (read only)") \
1018 $(menuitem "tazboot" "Get tazboot.exe Linux loader") \
1019 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
1020 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1021 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1022 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
1023 $(cdexe '?pxe' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1024 $(cdfilef '?pxe' "fdpxe" "Create a SliTaz Web boot floppy") \
1025 $(cdfilex '?pxe' "runpxe" "Start the SliTaz Web boot utility") \
1026 $(misspkg "missing" "Install packages to get more options") \
1027 $(menuitem "quit" "Quit this utility")
1028 EOT
1029 exec 3>&1
1030 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1031 retval=$?
1032 exec 3>&-
1033 rm -f /tmp/dialog$$
1034 [ $retval -eq 0 ] || continue
1035 $value
1036 done