wok view syslinux/stuff/iso2exe/init @ rev 13698
syslinux/iso2exe: tiny edits
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Fri Dec 14 22:52:32 2012 +0000 (2012-12-14) |
parents | d47403fdd900 |
children | 58b695f73790 |
line source
1 #!/bin/sh
3 DIALOG=dialog
5 get()
6 {
7 od -j $1 -N ${3:-4} -t u${3:-4} -An $2
8 }
10 getarg()
11 {
12 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
13 }
15 gettazboot()
16 {
17 echo "Creating $(basename $1) ..."
18 O=$(($(get 34 /mnt/$ISO 2) - 0xE0))
19 L=$((0x8000 - $(get 28 /mnt/$ISO 2) - $O))
20 S=$((32+$L))
21 P=$((($S+511)/512))
22 E=$((4096-(32*$P)))
23 for i in 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
24 -2 0 256 -16 28 0x6C53 0x5469 0x7A61; do
25 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
26 xargs echo -en
27 done > $1
28 dd bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1 2> /dev/null
29 }
31 checkmagic()
32 {
33 [ -s $1 ] && [ $(getarg magic) == $(get 28 $1) ]
34 }
36 getiso()
37 {
38 blkid | while read dev info ; do
39 case "$info" in
40 *dos*|*fat*|*ntfs*)
41 mount ${dev%:} /mnt
42 if checkmagic /mnt/$ISO; then
43 mount -o loop,ro /mnt/$ISO /media/cdrom
44 echo "Found $ISO on ${dev%:}"
45 break
46 fi
47 umount /mnt ;;
48 esac
49 done
50 }
52 uncpio()
53 {
54 echo "Extracting $(basename $1) ..."
55 case $(get 0 $1 2) in
56 *35615) zcat $1 ;;
57 *\ 93) unlzma -c $1 ;;
58 *) cat $1 ;;
59 esac | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
60 }
62 getuuid()
63 {
64 dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q')
65 blkid | sed "/$dev:/!d;s/.*UUID=.\\([^ ]*\\)\".*/\\1/"
66 }
68 mkinitrd()
69 {
70 echo "Creating $(basename $1) ..."
71 for i in bin lib dev proc tmp mnt etc ; do
72 mkdir -p /tmp/fs/$i
73 done
74 for i in /dev/console /dev/null /dev/tty /dev/tty1 /dev/fuse \
75 /dev/hd* /dev/sd* ; do
76 cp -a $i /tmp/fs$i
77 done
78 for i in /bin/busybox /usr/sbin/mount.posixovl $(which blkid); do
79 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
80 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib
81 cp $i /tmp/fs/bin
82 done
83 cp -a /lib/ld-* /tmp/fs/lib
84 for i in $(busybox | sed '/Current/,$!d'); do
85 ln -s busybox /tmp/fs/bin/${i%,}
86 done
87 ln -s /proc/mounts /tmp/fs/etc/mtab
88 cat > /tmp/fs/init <<EOT
89 #!/bin/sh
91 arg()
92 {
93 grep -q \$1 /proc/cmdline &&
94 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
95 echo "\$2 \$val"
96 }
98 mount -t proc /proc /proc
99 arg mount "Mount device"
100 mount \$( (blkid /dev/?d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
101 arg subroot "Change root to directory"
102 mount.posixovl /mnt/\$val
103 mount --bind /mnt /mnt/\$val/mnt/dos
104 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
105 umount /proc
106 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
107 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
108 EOT
109 chmod +x /tmp/fs/init
110 ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
111 rm -rf /tmp/fs
112 }
114 doinstall()
115 {
116 mkdir /mnt/slitaz
117 mount.posixovl /mnt/slitaz || return
118 mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos
119 for i in $(ls -r /media/cdrom/boot/rootfs*); do
120 uncpio $i /mnt/slitaz
121 done
122 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
123 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
124 /media/cdrom/README /media/cdrom/boot/memtest* ; do
125 [ -s $i ] && cp $i /mnt/slitaz/boot
126 done
127 umount -d /media/cdrom
128 gettazboot /mnt/slitaz/boot/tazboot.exe
129 mkinitrd /mnt/slitaz/boot/initrd
130 cat > /mnt/slitaz/boot/tazboot.cmd <<EOT
131 kernel=\\slitaz\\boot\\bzimage
132 initrd=\\slitaz\\boot\\initrd
133 rw root=/dev/null mount=$(getuuid) subroot=slitaz autologin
134 EOT
135 unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \
136 /mnt/slitaz/boot/README /mnt/slitaz/boot/tazboot.cmd
137 [ -x /mnt/slitaz/usr/sbin/mount.posixovl ] ||
138 cp /usr/sbin/mount.posixovl /mnt/slitaz/usr/sbin
139 ! grep -qs tazboot /mnt/boot.ini && cat >> /mnt/boot.ini <<EOT
140 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
141 EOT
142 grep -qs menuitem /mnt/config.sys && !grep -q tazboot /mnt/config.sys &&
143 sed -i 's/menudefault=/menuitem=slitaz,SliTaz\n&/' /mnt/config.sys &&
144 cat >> /mnt/config.sys <<EOT
145 [slitaz]
146 device=\\slitaz\\boot\\tazboot.exe
147 EOT
148 }
150 install()
151 {
152 $DIALOG --clear \
153 --title " SliTaz UMSDOS like installation " \
154 --yes-label "Install" --yesno \
155 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
156 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
157 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
158 To uninstall SliTaz, you have only to remove this directory.
159 The file \\boot.ini or \\config.sys may be modified too.\n\n
160 To do a traditional installation with disk partitioning,
161 start SliTaz Live with 'SliTaz RAM boot' menu.\n
162 " 16 70
163 [ $? -eq 0 -a -x /usr/sbin/mount.posixovl ] || return
164 doinstall
165 umount /proc
166 exec chroot /mnt/slitaz /sbin/init
167 }
169 tazboot()
170 {
171 $DIALOG --clear \
172 --title " SliTaz bootloader for DOS " \
173 --yes-label "Install" --yesno \
174 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
175 a bzImage linux kernel, multiple initramfs, a kernel command line and
176 an ISO image file loopback (retrieves files from an ISO file).\n\n
177 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
178 [initrd=<rootfs>[,<rootfs2>...]] [iso=<isofile>] cmdline args ...]\n\n
179 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
180 Examples for tazboot.cmd:\n\n\
181 iso=\\isos\\slitaz-4.0.iso\n\
182 kernel=boot/bzImage\n\
183 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
184 rw root=/dev/null autologin\n\n\
185 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
186 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
187 " 24 78
188 [ $? -eq 0 ] || return
189 gettazboot /mnt/tazboot.exe
190 }
192 md5()
193 {
194 ( cd /media/cdrom ; md5sum -c md5sum ) | tee /tmp/data
195 $DIALOG --clear \
196 --title " Checked files " \
197 --textbox /tmp/data 24 78
198 rm -f /tmp/data
199 }
201 readme()
202 {
203 $DIALOG --clear \
204 --title " Readme " \
205 --textbox /media/cdrom/README 24 78
206 }
208 bootlog()
209 {
210 $DIALOG --clear \
211 --title " Linux boot messages " \
212 --textbox /tmp/dmesg 24 78
213 }
215 memtest()
216 {
217 $DIALOG --clear \
218 --title " Memtest86 " \
219 --yes-label "Install" --yesno \
220 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
221 computers. BIOS based memory tests are a quick, cursory check and often
222 miss many of the failures that are detected by Memtest86.\n
223 " 12 70
224 [ $? -eq 0 ] || return
225 cp /media/cdrom/boot/memtest /mnt
226 }
228 fdmemtest()
229 {
230 $DIALOG --clear \
231 --title " Create a Memtest86 boot floppy " \
232 --yes-label "Create floppy" --yesno \
233 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
234 computers. BIOS based memory tests are a quick, cursory check and often
235 miss many of the failures that are detected by Memtest86.\n\n
236 Please insert a blank disk in floppy drive.\n
237 " 12 70
238 [ $? -eq 0 ] || return
239 dd if=/media/cdrom/boot/memtest of=/dev/fd0
240 }
242 gpxe()
243 {
244 $DIALOG --clear \
245 --title " SliTaz Web boot " \
246 --yes-label "Install" --yesno \
247 "\nBoot your operating system from the internet and enjoy a full system
248 working entirely in RAM with speed and stability in mind. The Linux Kernel
249 and the complete SliTaz compressed root filesystem will be loaded into RAM
250 from the Web using PXE and HTTP protocols.\n
251 " 12 70
252 [ $? -eq 0 ] || return
253 cp /media/cdrom/boot/gpxe /mnt
254 }
256 fdgpxe()
257 {
258 $DIALOG --clear \
259 --title " Create a SliTaz Web boot floppy " \
260 --yes-label "Create floppy" --yesno \
261 "\nBoot your operating system from the internet and enjoy a full system
262 working entirely in RAM with speed and stability in mind. The Linux Kernel
263 and the complete SliTaz compressed root filesystem will be loaded into RAM
264 from the Web using PXE and HTTP protocols.\n\n
265 Please insert a blank disk in floppy drive.\n
266 " 12 70
267 [ $? -eq 0 ] || return
268 dd if=/media/cdrom/boot/gpxe of=/dev/fd0
269 }
271 cdfile()
272 {
273 [ -s /media/cdrom/$1 ] && echo -en "$2 ${3// /.}"
274 }
276 usbkey()
277 {
278 $DIALOG --clear \
279 --title " Create a SliTaz USB key " \
280 --yes-label "Continue" --yesno \
281 "\nUnlike a hard drive install, the filesystem is kept in a compressed
282 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
283 This should increase responsiveness, protect the filesystem against
284 accidental corruption and reduce read/writes to the USB drive.
285 Once setup, the tazusb utility can rewrite the root filesystem
286 with any changes you have made since booting up,
287 giving the effective benefits of a hard drive install.\n\n
288 /home is mounted on boot using the UUID of your particular flash drive.
289 Unlike a device name, the UUID has the benefit of never changing from machine
290 to machine.\n\n
291 Please plug your USB stick in now.\n
292 " 18 70
293 [ $? -eq 0 ] || return
294 DEV="$(grep -l 1 /sys/block/*/removable | \
295 sed 's|/sys/block/\(.*\)/removable|\1|')"
296 [ -n "$DEV" ] || return
297 exec 3>&1
298 sleep 5
299 device=`$DIALOG --clear \
300 --title " Select your USB key " \
301 --menu "\nPlease select the USB key according to its known size.\n\n" \
302 14 70 4 \
303 $(for i in $DEV ; do
304 echo "/dev/$i $(( $(cat /sys/block/$i/size) / 1024 ))MB"
305 done) \
306 2>&1 1>&3`
307 retval=$?
308 exec 3>&-
309 [ $retval -eq 0 ] || continue
310 exec 3>&1
311 format=`$DIALOG --clear \
312 --title " Select the filesystem " \
313 --menu "\nPlease select the filesystem type to create.\n\n\
314 The filesystem creation will erase all the data \
315 on the USB key." 14 70 4 \
316 "none" "Do not erase the USB key" \
317 "ext3" "Ext3 journaling filesystem" \
318 "ext2" "Ext2 filesystem" \
319 "fat32" "Window FAT32 filesystem" \
320 2>&1 1>&3`
321 retval=$?
322 exec 3>&-
323 [ $retval -eq 0 ] || continue
324 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
325 tazusb gen-iso2usb /mnt/$ISO $device
326 }
328 text()
329 {
330 umount -d /media/cdrom
331 umount /mnt
332 umount /proc
333 exec /init
334 }
336 live()
337 {
338 n=0
339 for i in $(ls -r /media/cdrom/boot/rootfs*); do
340 [ $((n++)) -eq 0 ] || uncpio $i
341 done
342 text
343 }
345 reboot()
346 {
347 umount -d /media/cdrom
348 umount /mnt
349 /sbin/reboot -f
350 }
352 poweroff()
353 {
354 umount -d /media/cdrom
355 umount /mnt
356 /sbin/poweroff -f
357 }
359 shell()
360 {
361 /sbin/getty -n -l /bin/ash 38400 tty1
362 }
364 [ -x /usr/sbin/mount.posixovl ] ||
365 mv /usr/sbin/mount.posixovl.iso2exe /usr/sbin/mount.posixovl
366 mount -t proc /proc /proc
367 dmesg > /tmp/dmesg
368 ISO="$(getarg iso | sed 's/.://;s|\\|/|g')"
369 getiso
370 case "$(basename $ISO | tr [A-Z] [a-z])$(getarg mode)" in
371 *install*) install ;;
372 *live*) live ;;
373 *text*) text ;;
374 esac
376 while true; do
377 exec 3>&1
378 value=`$DIALOG --clear \
379 --title " Welcome to SliTaz " \
380 --menu "\nPlease select" 17 70 9 \
381 "live" "SliTaz RAM boot" \
382 "text" "SliTaz RAM boot (text mode only)" \
383 $(cdfile README "readme" "Show the README file") \
384 $(cdfile md5sum "md5" "Check ISO files") \
385 "install" "Hard disk installation" \
386 "usbkey" "USB key installation" \
387 "tazboot" "Get tazboot.exe Linux loader" \
388 $(cdfile Xboot/memtest "memtest" "Get Memtest86") \
389 $(cdfile boot/memtest "fdmemtest" "Create a Memtest86 boot floppy") \
390 $(cdfile Xboot/gpxe "gpxe" "Get SliTaz Web boot utility") \
391 $(cdfile boot/gpxe "fdgpxe" "Create a SliTaz Web boot floppy") \
392 "reboot" "Restart the computer" \
393 "poweroff" "Power off" \
394 "bootlog" "Linux boot messages" \
395 "shell" "Shell prompt" \
396 2>&1 1>&3`
397 retval=$?
398 exec 3>&-
399 [ $retval -eq 0 ] || continue
400 $value
401 done