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

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