wok view syslinux/stuff/iso2exe/init @ rev 17476

isolinux/iso2exe: fix mkfloppy
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 29 18:24:44 2014 +0100 (2014-12-29)
parents f889c01820d0
children 054f70cb9bec
line source
1 #!/bin/sh
3 DIALOG=dialog
5 ddq()
6 {
7 dd $@ 2> /dev/null
8 }
10 get()
11 {
12 od -j $1 -N ${3:-2} -t u${3:-2} -An $2 2> /dev/null ||
13 hexdump -s $1 -n ${3:-2} -e "\"\" 1/${3:-2} \"%d\"" $2
14 }
16 getarg()
17 {
18 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
19 }
21 mount_proc()
22 {
23 mount -t proc /proc /proc
24 mount -t sysfs /sys /sys
25 udevd --daemon 2> /dev/null && udevadm trigger && sleep 5
26 }
28 umount_proc()
29 {
30 killall udevd 2> /dev/null
31 umount /sys/fs/fuse/connections 2> /dev/null
32 umount /sys
33 umount /proc
34 }
36 bytes2bin()
37 {
38 for i in $@ ; do
39 printf '\\\\x%02X' $(($i&255)) | xargs echo -en
40 done
41 }
43 words2bin()
44 {
45 for i in $@ ; do
46 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
47 xargs echo -en
48 done
49 }
51 gettazboot()
52 {
53 echo "Creating $(basename $1) ..."
54 O=$(($(get 66 /mnt/$ISO) - 0xC0))
55 L=$((0x7EE0 - $(get 24 /mnt/$ISO) - $O))
56 S=$((32+$L))
57 P=$((($S+511)/512))
58 E=$((4096-(32*$P)))
59 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
60 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
61 ddq bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1
62 }
64 checkmagic()
65 {
66 [ -s $1 ] && [ $(getarg magic) == $(get 24 $1 4) ]
67 }
69 getiso()
70 {
71 mkdir -p /media/cdrom
72 blkid | while read dev info ; do
73 mount ${dev%:} /mnt
74 if checkmagic /mnt/$ISO; then
75 mount -o loop,ro /mnt/$ISO /media/cdrom
76 echo "Found $ISO on ${dev%:}"
77 break
78 fi
79 umount /mnt
80 done
81 }
83 uncpio()
84 {
85 echo -en "\n Extracting $(basename $1) ..."
86 case $(get 0 $1) in
87 *35615) ( zcat || gunzip ) ;;
88 *14333) unxz ;;
89 *\ 93) unlzma ;;
90 *) cat ;;
91 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
92 }
94 dotwait()
95 {
96 echo -n "${1:-Install filesystem}.."
97 touch /tmp/wait
98 while [ -e /tmp/wait ]; do
99 echo -n "." > /dev/tty0
100 sleep 1
101 done &
102 }
104 getuuid()
105 {
106 dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q')
107 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/"
108 }
110 tazusbinitfs()
111 {
112 PAD=$(($(stat -c %s $1) % 4))
113 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
114 mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
115 cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
116 cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
117 sed 's/ .*//' /proc/modules | while read mod ; do
118 find /lib/modules/ | grep $mod.ko | \
119 sed 's|.*|cp & /tmp/fs/lib|' | sh
120 done
121 cat > /tmp/fs/init1 <<EOT
122 #!/bin/sh
123 sed -i 's|sbin/init|init2|' /init
124 exec /init
125 EOT
126 cat > /tmp/fs/init2 <<EOT
127 #!/bin/sh
129 mount -t proc /proc /proc
130 grep -q debug /proc/cmdline && debug=true && set -x
131 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
132 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
133 mount / -o remount,rw
134 mkdir /mnt/dos
135 rm -f /cmdline 2> /dev/null
136 mount / -o remount,ro
137 mnt=/mnt/dos/\${v#*/}
138 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
139 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
140 mount \$dev /mnt/dos
141 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
142 mount --bind \$mnt /home
143 [ "\$debug" = "true" ] && sh
144 umount /proc
145 exec /sbin/init
146 EOT
147 chmod 755 /tmp/fs/init?
148 cp -a /tmp/fs/* /
149 ( cd /tmp/fs ; find * | cpio -o -H newc ) | gzip -9 >> $1
150 }
152 mkinitrd()
153 {
154 dotwait "Creating $(basename $1) "
155 for i in bin lib dev proc tmp mnt etc ; do
156 mkdir -p /tmp/fs/$i
157 done
158 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
159 /dev/fuse /dev/hd* /dev/sd* ; do
160 cp -a $i /tmp/fs$i
161 done
162 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
163 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
164 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib
165 cp $i /tmp/fs/bin
166 done
167 cp -a /lib/ld-* /tmp/fs/lib
168 for i in $(busybox | sed '/Current/,$!d'); do
169 [ -e /tmp/fs/bin/${i%,} ] || ln -s busybox /tmp/fs/bin/${i%,}
170 done
171 ln -s /proc/mounts /tmp/fs/etc/mtab
172 sed 's/ .*//' /proc/modules | while read mod ; do
173 find /lib/modules/ | grep $mod.ko | \
174 sed 's|.*|cp & /tmp/fs/lib|' | sh
175 done
176 cat > /tmp/fs/init <<EOT
177 #!/bin/sh
179 arg()
180 {
181 grep -q \$1 /proc/cmdline &&
182 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
183 echo "\$2 \$val"
184 }
186 mount -t proc /proc /proc
187 arg debug "shell" && debug=true && set -x
188 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
189 arg mount "Mount device"
190 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
191 arg subroot "Change root to directory"
192 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
193 mount --bind /mnt /mnt/\$val/mnt/dos
194 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
195 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
196 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
197 [ "$debug" = "true" ] && sh
198 umount /proc
199 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
200 EOT
201 chmod +x /tmp/fs/init
202 ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
203 rm -rf /tmp/fs /tmp/wait
204 }
206 is_loram()
207 {
208 [ -s /lib/squashfs.ko* ]
209 }
211 ls_r()
212 {
213 ls -r $@ 2> /dev/null || ls $@
214 }
216 doinstall()
217 {
218 mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos
219 if ! mount.posixovl -F /mnt/slitaz -- \
220 -oallow_other -odefault_permissions -osuid; then
221 echo "Can't install SliTaz. Abort."
222 sleep 5
223 return 1
224 fi
225 dowait "Install root filesystem in /slitaz.."
226 if [ "$1" ]; then
227 if [ -d /media/cdrom/fs ]; then
228 ( cd /mnt/slitaz/fs; find | cpio -o -H newc ) | gzip -9
229 else
230 ls_r /media/cdrom/boot/rootfs* | xargs cat
231 fi > /mnt/slitaz/boot/rootfs.gz
232 tazusbinitfs /mnt/slitaz/boot/rootfs.gz
233 initrd=rootfs.gz
234 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
235 else
236 if [ -d /media/cdrom/fs ]; then
237 cp -a /media/cdrom/fs/. /mnt/slitaz
238 elif is_loram ; then
239 for i in /media/cdrom/boot/rootfs?*.* ; do
240 [ -s $(basename $i) ] && continue
241 cpio -i $i
242 done
243 for i in $(ls_r /media/cdrom/boot/rootfs*); do
244 mount -o loop,ro $i /sqfs/mnt
245 cp -a /sqfs/mnt/. /mnt/slitaz
246 umount -d /sqfs/mnt
247 done
248 else
249 for i in $(ls_r /media/cdrom/boot/rootfs*); do
250 uncpio $i /mnt/slitaz
251 done
252 fi
253 cp -a /etc/locale.conf /tmp/slitaz/etc 2> /dev/null
254 cp -a /etc/keymap.conf /tmp/slitaz/etc 2> /dev/null
255 mkinitrd /mnt/slitaz/boot/initrd
256 initrd=initrd
257 extraargs="mount=$(getuuid) subroot=slitaz"
258 fi
259 echo -en "\nInstall boot files..."
260 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
261 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
262 /media/cdrom/README /media/cdrom/boot/memtest* ; do
263 [ -s $i ] && cp $i /mnt/slitaz/boot
264 done
265 for i in /mnt/slitaz/boot/memtest /mnt/slitaz/boot/*pxe* ; do
266 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
267 mv $i $i.exe
268 done
269 gettazboot /mnt/slitaz/boot/tazboot.exe
270 unix2dos > /mnt/slitaz/boot/tazboot.cmd <<EOT
271 kernel=/slitaz/boot/bzimage
272 initrd=/slitaz/boot/$initrd
273 rw root=/dev/null $extraargs autologin
274 EOT
275 unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \
276 /mnt/slitaz/boot/README
277 [ -d /mnt/slitaz/usr/sbin -a ! -x /mnt/slitaz/usr/sbin/mount.posixovl ] &&
278 cp $(which mount.posixovl) /mnt/slitaz/usr/sbin
279 rm -f /tmp/wait
280 false &&
281 [ -s /mnt/boot.ini ] && ! grep -qs tazboot /mnt/boot.ini &&
282 echo "Update boot.ini ..." && unix2dos >> /mnt/boot.ini <<EOT
283 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
284 EOT
285 false &&
286 grep -qis menuitem /mnt/config.sys && ! grep -qi tazboot /mnt/config.sys &&
287 echo "Update config.sys ..." &&
288 sed -i 's/menudefault/menuitem SLITAZ, SliTaz\r\n&/' /mnt/config.sys &&
289 unix2dos >> /mnt/config.sys <<EOT
290 [SLITAZ]
291 install=\\slitaz\\boot\\tazboot.exe
292 EOT
293 return 0
294 }
296 install()
297 {
298 $DIALOG --clear \
299 --title " SliTaz UMSDOS way installation " \
300 --yes-label "Install" --yesno \
301 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
302 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
303 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
304 To uninstall SliTaz, you have only to remove this directory.
305 The file \\boot.ini or \\config.sys may be modified too.\n\n
306 SliTaz may run slowly on 'UMSDOS way' installation due to the
307 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
308 To do a traditional installation with disk partitioning,
309 start SliTaz Live with 'SliTaz RAM boot' menu.\n
310 " 19 70
311 [ $? -eq 0 ] || return
312 doinstall || return
313 [ -x /mnt/slitaz/sbin/init ] || return
314 umount -d /media/cdrom
315 umount_proc
316 exec chroot /mnt/slitaz /sbin/init
317 }
319 installtaz()
320 {
321 $DIALOG --clear \
322 --title " SliTaz TAZUSB way installation " \
323 --yes-label "Install" --yesno \
324 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
325 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
326 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
327 To uninstall SliTaz, you have only to remove this directory.
328 The file \\boot.ini or \\config.sys may be modified too.\n\n
329 The filesystem is loaded entirely into memory upon boot to
330 increase responsiveness. Only /home lands on hard disk.\n\n
331 To do a traditional installation with disk partitioning,
332 start SliTaz Live with 'SliTaz RAM boot' menu.\n
333 " 19 70
334 [ $? -eq 0 ] || return
335 doinstall tazusblike || return
336 dotwait
337 if [ -d /media/cdrom/fs ]; then
338 cp -a /media/cdrom/fs/. /
339 else
340 for i in $(ls_r /media/cdrom/boot/rootfs*); do
341 uncpio $i
342 done
343 fi
344 cp /tmp/fs/etc/* /etc
345 echo "/home=$(getuuid)/slitaz" > /cmdline
346 rm -f /tmp/wait
347 [ -x /init1 ] || return
348 umount -d /media/cdrom
349 umount /mnt/slitaz
350 rm -f /dev/cdrom
351 umount /mnt
352 mkdir /mnt/dos
353 umount_proc
354 exec /init1
355 }
357 tazboot()
358 {
359 $DIALOG --clear \
360 --title " SliTaz bootloader for DOS " \
361 --yes-label "Install" --yesno \
362 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
363 any linux kernel, multiple initramfs, a kernel command line and
364 an ISO image file loopback (retrieves files from an ISO file).\n\n
365 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
366 [initrd=<rootfs>[,<rootfs2>...]] [iso=<isofile>] cmdline args ...]\n\n
367 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
368 Examples for tazboot.cmd:\n\n\
369 iso=\\isos\\slitaz-4.0.iso\n\
370 kernel=boot/bzImage\n\
371 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
372 rw root=/dev/null autologin\n\n\
373 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
374 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
375 " 24 78
376 [ $? -eq 0 ] || return
377 gettazboot /mnt/tazboot.exe
378 }
380 md5()
381 {
382 dotwait "Checking files"
383 ( cd /media/cdrom ; md5sum -c md5sum* ) > /tmp/data
384 rm -f /tmp/wait
385 $DIALOG --clear \
386 --title " Checked files " \
387 --textbox /tmp/data 24 78
388 rm -f /tmp/data
389 }
391 readme()
392 {
393 $DIALOG --clear \
394 --title " Readme " \
395 --textbox /media/cdrom/README 24 78
396 }
398 bootlog()
399 {
400 $DIALOG --clear \
401 --title " Linux boot messages " \
402 --textbox /tmp/dmesg 24 78
403 }
405 bzimage()
406 {
407 $DIALOG --clear \
408 --title " Create linux.exe ? " \
409 --yes-label "Install" --yesno \
410 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
411 The cmdline arguments are supported except initrd=, vga= (you can try 'rdev -v')
412 and mem= (partially).\n\nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
413 " 12 70
414 [ $? -eq 0 ] || return
415 cp /media/cdrom/boot/bzImage /mnt/linux.exe
416 }
418 memtest()
419 {
420 $DIALOG --clear \
421 --title " Create memtest.exe ? " \
422 --yes-label "Install" --yesno \
423 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
424 computers. BIOS based memory tests are a quick, cursory check and often
425 miss many of the failures that are detected by Memtest86.\n
426 " 12 70
427 [ $? -eq 0 ] || return
428 cp /media/cdrom/boot/memtest /mnt/memtest.exe
429 }
431 mkfloppy()
432 {
433 dotwait "Create a $(basename $1) boot floppy"
434 ddq if=$1 of=/dev/fd0
435 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
436 J=$(($(get 3 $1 1) + 0x02))
437 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
438 [ $R -lt 2500 ] || return
439 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
440 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
441 G="18 0 2 0 0 0 0 0"
442 [ $J -gt 25 ] || G=""
443 F=0
444 for i in 1 2 3; do
445 F=$((((2880-$R-$F-$F)*3+1023)/1024))
446 done
447 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
448 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
449 $G | ddq bs=1 of=/dev/fd0
450 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
451 for i in $R $(($R+$F)) ; do
452 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
453 done
454 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
455 rm -f /tmp/wait
456 }
458 fdmemtest()
459 {
460 $DIALOG --clear \
461 --title " Create a Memtest86 boot floppy " \
462 --yes-label "Create floppy" --yesno \
463 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
464 computers. BIOS based memory tests are a quick, cursory check and often
465 miss many of the failures that are detected by Memtest86.\n\n
466 Please insert a blank disk in floppy drive.\n
467 " 12 70
468 [ $? -eq 0 ] && mkfloppy /media/cdrom/boot/memtest
469 }
471 pxe()
472 {
473 pxe=$(ls /media/cdrom/boot/?pxe)
474 $DIALOG --clear \
475 --title " Create $(basename $pxe).exe ? " \
476 --yes-label "Install" --yesno \
477 "\nBoot your operating system from the internet and enjoy a full system
478 working entirely in RAM with speed and stability in mind. The Linux Kernel
479 and the complete SliTaz compressed root filesystem will be loaded into RAM
480 from the Web using PXE and HTTP protocols.\n
481 " 12 70
482 [ $? -eq 0 ] || return
483 cp $pxe /mnt/$(basename $pxe).exe
484 }
486 fdpxe()
487 {
488 $DIALOG --clear \
489 --title " Create a SliTaz Web boot floppy " \
490 --yes-label "Create floppy" --yesno \
491 "\nBoot your operating system from the internet and enjoy a full system
492 working entirely in RAM with speed and stability in mind. The Linux Kernel
493 and the complete SliTaz compressed root filesystem will be loaded into RAM
494 from the Web using PXE and HTTP protocols.\n\n
495 Please insert a blank disk in floppy drive.\n
496 " 12 70
497 [ $? -eq 0 ] && mkfloppy /media/cdrom/boot/?pxe
498 }
500 gotposixovl()
501 {
502 mount.posixovl 2>&1 | grep -qi usage &&
503 echo -en "\"$1\" \"$2\""
504 }
506 xfile()
507 {
508 [ "$(which $1)" ] && echo -en "\"$2\" \"$3\""
509 }
511 cdfile()
512 {
513 for i in ${1//,/ }; do
514 [ -s /media/cdrom/$i ] && echo -en "\"$2\" \"$3\"" && break
515 done
516 }
518 cdfilex()
519 {
520 [ "$(which kexec)" ] && cdfile "$@"
521 }
523 cdexe()
524 {
525 [ $(get 0 /media/cdrom/$1 2> /dev/null || echo 0) -eq 23117 ] &&
526 echo -en "\"$2\" \"$3\""
527 }
529 fddata()
530 {
531 [ $(get 28 /mnt/$ISO 1 2> /dev/null || echo 0) -ne 0 ] &&
532 echo -en "\"$1\" \"$2\""
533 }
535 fdbootstrap()
536 {
537 sz=$((512 * $(echo $(get 28 /mnt/$ISO 1))))
538 $DIALOG --clear \
539 --title " Create a floppy bootstrap " \
540 --yes-label "Continue" --yesno \
541 "\nThe floppy will install a driver to access the ISO file
542 on your hard disk and will emulate a CD-ROM during the boot process.\n\n
543 Please insert a floppy in drive now.\n
544 " 10 70
545 [ $? -eq 0 ] || return
546 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=512 \
547 skip=$(( $(get 66 /mnt/$ISO) - $sz ))
548 echo "$ISO" | ddq of=/tmp/bootiso bs=512 seek=1 count=1
549 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=$sz seek=2 \
550 skip=$(( $(get 66 /mnt/$ISO) - $sz + 512 ))
551 mkfloppy /tmp/bootiso
552 rm -f /tmp/bootiso
553 }
555 usbdev()
556 {
557 dotwait "Wait 5 seconds for USB devices"
558 sleep 5
559 rm -f /tmp/wait
560 DEV="$(grep -l 1 /sys/block/*/removable | \
561 sed 's|/sys/block/\(.*\)/removable|\1|')"
562 [ "$DEV" ] || return
563 exec 3>&1
564 device=`$DIALOG --clear \
565 --title " Select your USB key " \
566 --menu "\nPlease select the USB key according to its known size.\n\n" \
567 14 70 4 \
568 $(for i in $DEV ; do
569 echo "/dev/$i $(( $(cat /sys/block/$i/size) / 1024 ))MB"
570 done) \
571 2>&1 1>&3`
572 retval=$?
573 exec 3>&-
574 [ $retval -eq 0 ]
575 }
577 usbbootkey()
578 {
579 $DIALOG --clear \
580 --title " Create a USB boot key " \
581 --yes-label "Continue" --yesno \
582 "\nThe USB key will be used like a CD-ROM. You will not be able to write
583 any data on the boot partition.\n\n
584 An extra FAT32 partition will be created with the remaining free space.\n\n
585 You should choose 'USB key read/write installation' to be
586 able to save the package updates or your own configuration and data files.\n\n
587 Please plug your USB stick in now.\n
588 " 16 70
589 [ $? -eq 0 ] || return
590 usbdev || return
592 # perform dd in progess bar
593 max=$(($(stat -c %s /mnt/$ISO)/1024/1024))
594 i=0; ddq if=/mnt/$ISO bs=1024k | (
595 while ddq bs=1024k count=1 ; do
596 i=$(($i + 1))
597 [ $i -gt $max ] && break
598 echo $((($i*100)/$max)) | dialog --gauge \
599 " The ISO image transfer can be long. Please wait..." \
600 6 70 0 > /dev/tty0 2>&1
601 done ) > $device
603 # partition + fat32 format for the remining space
604 od -j 466 -N 12 -t u2 -An $device | { read dx cx ol oh ll lh
605 if [ $dx -eq $((0x3F17)) ]; then
606 cx=$(($cx & 0xFF00))
607 ofs=$(($ll+($lh<<16)))
608 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
609 m=$(($cx+($n/8)))
610 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
611 m=$((($m & 0xFF00)+(($m>>16)<<6)))
612 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
613 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
614 ddq bs=1 seek=446 of=$device
615 if [ "$(which mkdosfs 2> /dev/null)" ]; then
616 losetup -o $((512*$ofs)) /dev/loop0 $device
617 mkdosfs -n "SLITAZ BOOT" /dev/loop0
618 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
619 ddq bs=1 seek=28 of=/dev/loop0
620 losetup -d /dev/loop0
621 fi
622 fi ; }
623 }
625 usbkey()
626 {
627 $DIALOG --clear \
628 --title " Create a SliTaz USB key " \
629 --yes-label "Continue" --yesno \
630 "\nUnlike a hard drive install, the filesystem is kept in a compressed
631 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
632 This should increase responsiveness, protect the filesystem against
633 accidental corruption and reduce read/writes to the USB drive.
634 Once setup, the tazusb utility can rewrite the root filesystem
635 with any changes you have made since booting up,
636 giving the effective benefits of a hard drive install.\n\n
637 /home is mounted on boot using the UUID of your particular flash drive.
638 Unlike a device name, the UUID has the benefit of never changing from machine
639 to machine.\n\n
640 Please plug your USB stick in now.\n
641 " 19 70
642 [ $? -eq 0 ] || return
643 usbdev || return
644 exec 3>&1
645 format=`$DIALOG --clear \
646 --title " Select the filesystem " \
647 --radiolist "\nPlease select the filesystem type to create.\n\n\
648 The filesystem creation will erase all the data \
649 in the USB key." 14 70 4 \
650 "none" "Do not erase the USB key" on \
651 "ext3" "Ext3 journaling filesystem" off \
652 "ext2" "Ext2 filesystem" off \
653 "fat32" "Windows FAT32 filesystem" off \
654 2>&1 1>&3`
655 retval=$?
656 exec 3>&-
657 [ $retval -eq 0 ] || return
658 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
659 tazusb gen-iso2usb /mnt/$ISO $device
660 }
662 mount_loram()
663 {
664 is_loram || return
665 insmod /lib/squashfs.ko* 2> /dev/null
666 if [ -d /media/cdrom/fs ]; then
667 ln -s /media/cdrom/fs /sqfs
668 else
669 mkdir /sqfs
670 mount -o loop,ro -t squashfs /rootfs*.gz /sqfs
671 fi
672 ln -s /sqfs/lib/* lib
673 ln -s /sqfs/usr /sqfs/var /
674 for i in dmesg basename tr od reboot poweroff getty sync ; do
675 ln -s /sqfs/bin/busybox /bin/$i
676 done
677 }
679 umount_loram()
680 {
681 is_loram || return
682 rm /var /usr
683 umount -d /sqfs
684 rmdir /sqfs
685 }
687 text()
688 {
689 umount_loram
690 umount -d /media/cdrom
691 rm -f /dev/cdrom
692 umount /mnt
693 umount_proc
694 exec /init
695 }
697 live()
698 {
699 n=0
700 dotwait "Extract filesystem..."
701 for i in $(ls_r /media/cdrom/boot/rootfs*); do
702 [ $((n++)) -eq 0 ] || uncpio $i
703 done
704 rm -f /tmp/wait
705 text
706 }
708 dosync()
709 {
710 sync
711 [ ! -L /sqfs ] && umount -d /media/cdrom && umount /mnt
712 }
714 restart()
715 {
716 dosync
717 reboot -f
718 }
720 stop()
721 {
722 dosync
723 poweroff -f
724 }
726 runmemtest()
727 {
728 kexec -l /media/cdrom/boot/memtest
729 dosync
730 kexec -e
731 }
733 runpxe()
734 {
735 kexec -l /media/cdrom/boot/?pxe
736 dosync
737 kexec -e
738 }
740 shell()
741 {
742 getty -n -l /bin/ash 38400 tty1 || sh
743 }
745 BIN=bin/mount.posixovl
746 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
747 /usr/s$BIN 2> /dev/null || mv /bin/mount.posixovl.iso2exe /$BIN
748 mount_proc
749 ISO="$(getarg iso | sed 's/.://;s|\\|/|g')"
750 getiso
751 mount_loram
752 case "${ISO##*/}$(getarg mode)" in
753 *install*|*INSTALL*) install ;;
754 *live*|*LIVE*) live ;;
755 *text*|*TEXT*) text ;;
756 esac
757 which $DIALOG 2> /dev/null || live
758 dmesg > /tmp/dmesg
760 while true; do
761 keymap="$(cat /etc/keymap.conf 2> /dev/null)"
762 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
763 cat > /tmp/dialog <<EOT
764 $DIALOG --clear \
765 --title " Welcome to SliTaz " \
766 --menu "" 23 70 17 \
767 $(xfile tazkeymap "tazkeymap" "Select keyboard ($keymap)") \
768 $(xfile tazlocale "tazlocale" "Select locale ($locale)") \
769 $(cdfile boot/bzImage "live" "SliTaz RAM boot") \
770 "text" "SliTaz RAM boot (text mode only)" \
771 $(cdfile README "readme" "Show the README file") \
772 $(cdfile md5sum* "md5" "Check ISO files") \
773 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
774 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
775 $(xfile tazusb "usbkey" "USB key read/write installation") \
776 $(cdfile boot/bzImage "usbbootkey" "USB boot key (read only)") \
777 $(fddata "fdbootstrap" "Create a floppy bootstrap") \
778 $(cdfile boot/bzImage "tazboot" "Get tazboot.exe Linux loader") \
779 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
780 $(cdexe boot/memtest "memtest" "Get Memtest86 DOS/EXE file") \
781 $(cdfile boot/memtest,boot/isolinux/memtest \
782 "fdmemtest" "Create a Memtest86 boot floppy") \
783 $(cdfilex boot/memtest,boot/isolinux/memtest \
784 "runmemtest" "Start Memtest86") \
785 $(cdexe boot/?pxe "pxe" "Get SliTaz Web boot DOS/EXE utility") \
786 $(cdfile boot/?pxe "fdpxe" "Create a SliTaz Web boot floppy") \
787 $(cdfilex boot/?pxe "runpxe" "Start the SliTaz Web boot utility") \
788 $(xfile reboot "restart" "Restart the computer") \
789 $(xfile poweroff "stop" "Power off") \
790 "bootlog" "Linux boot messages" \
791 "shell" "Shell prompt" \
793 EOT
794 exec 3>&1
795 value=$(sh /tmp/dialog 2>&1 1>&3)
796 retval=$?
797 exec 3>&-
798 [ $retval -eq 0 ] || continue
799 $value
800 done