slitaz-tools 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 | abc80c498d33 |
children | d564f29ba19e |
files | tinyutils/bootfloppybox |
line diff
1.1 --- a/tinyutils/bootfloppybox Tue Jun 28 15:59:36 2011 +0200 1.2 +++ b/tinyutils/bootfloppybox Sun Jul 10 21:42:10 2011 +0200 1.3 @@ -243,44 +243,140 @@ 1.4 cat > $1/init <<EOTEOT 1.5 #!/bin/sh 1.6 1.7 +cat_floppy() 1.8 +{ 1.9 + tmp="\$(dd if=/dev/fd0 count=1 2> /dev/null | md5sum)" 1.10 + echo -n "Insert floppy \$num for \$name and press Enter or Q to skip" 1.11 + while true; do 1.12 + echo -n ":" 1.13 + read -t 10 answer < /dev/tty0 1.14 + case "\$answer" in 1.15 + Q*|q*|A*|a*) break 3;; 1.16 + esac 1.17 + dd if=/dev/fd0 count=1 > /tmp/bs.\$\$ 2> /dev/null 1.18 + [ -s /tmp/bs.\$\$ ] || continue 1.19 + [ "\$(md5sum < /tmp/bs.\$\$)" != "\$tmp" ] || continue 1.20 + rm -f /tmp/bs.\$\$ 1.21 + break 1.22 + done 1.23 + dd if=/dev/fd0 of=/tmp/rootfs.\$num 2> /dev/null || continue 1.24 + cat /tmp/rootfs.\$num >> \$1 1.25 + rm -f /tmp/rootfs.\$num 1.26 + num=\$((\$num+1)) 1.27 +} 1.28 + 1.29 mount -t proc proc /proc 1.30 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g') 1.31 # the floppy driver may not be included in kernel 1.32 insmod /lib/modules/*/kernel/drivers/block/floppy.ko.gz 2> /dev/null 1.33 # loram may put floppy.ko.gz module in /lib 1.34 insmod /lib/floppy.ko.gz 2> /dev/null 1.35 +if blkid | grep -q 'TYPE="ext'; then 1.36 + cat <<EOT 1.37 + 1.38 +You can preinstall SliTaz in one of these ext3 partition: 1.39 +\$(blkid | grep 'TYPE="ext') 1.40 + 1.41 +Simply enter the device name (/dev/XXXX) to create the slitaz/install.sh or 1.42 +leave it blank to skip : 1.43 +EOT 1.44 + read -t 60 device < /dev/tty0 1.45 + [ -n "\$device" ] && mount \$device /mnt && mkdir /mnt/slitaz 1.46 +else 1.47 + cat <<EOT 1.48 + 1.49 +You can preinstall SliTaz in an ext3 partition with this floppy set. 1.50 +After the boot process is completed, create a partition with 'fdisk', 1.51 +format it with 'mke2fs -j' and reboot from the floppies again. 1.52 + 1.53 +EOT 1.54 +fi 1.55 umount /proc 1.56 while read name min num count file md5; do 1.57 [ -e \$file ] && continue 1.58 [ \$total -lt \$min ] && break 1.59 while [ \$count -ne 0 ]; do 1.60 - tmp="\$(dd if=/dev/fd0 count=1 2> /dev/null | md5sum)" 1.61 - echo -n "Insert floppy \$num for \$name and press Enter or Q to skip" 1.62 - while true; do 1.63 - echo -n ":" 1.64 - read -t 10 answer < /dev/tty0 1.65 - case "\$answer" in 1.66 - Q*|q*|A*|a*) break 3;; 1.67 - esac 1.68 - dd if=/dev/fd0 count=1 > /tmp/bs.\$\$ 2> /dev/null 1.69 - [ -s /tmp/bs.\$\$ ] || continue 1.70 - [ "\$(md5sum < /tmp/bs.\$\$)" != "\$tmp" ] || continue 1.71 - rm -f /tmp/bs.\$\$ 1.72 - break 1.73 - done 1.74 - dd if=/dev/fd0 of=/tmp/rootfs.\$num 2> /dev/null || continue 1.75 - cat /tmp/rootfs.\$num >> /tmp/rootfs 1.76 - rm -f /tmp/rootfs.\$num 1.77 - num=\$((\$num+1)) 1.78 + cat_floppy /tmp/rootfs 1.79 count=\$((\$count-1)) 1.80 done 1.81 echo "\$md5 /tmp/rootfs" | md5sum -c || break 1.82 cpio -idmu < /tmp/rootfs > /dev/null 2>&1 || 1.83 ( zcat /tmp/rootfs 2> /dev/null || unlzma -c /tmp/rootfs ) | cpio -idmu 1.84 + if [ -d /mnt/slitaz ]; then 1.85 + cp /tmp/rootfs /mnt/slitaz/rootfs.\$num || 1.86 + mv -f /mnt/slitaz /mnt/slitaz-aborted 1.87 + fi 1.88 + rootfslist="\$rootfslist \$num" 1.89 rm -f /tmp/rootfs* 1.90 done <<EOT 1.91 $(while read line; do echo $line; done) 1.92 EOT 1.93 +if [ -d /mnt/slitaz ]; then 1.94 + cat > /mnt/slitaz/install.sh <<EOT 1.95 +#!/bin/sh 1.96 + 1.97 +[ -n "\\\$1" ] || set -- . 1.98 +cd \\\$1 1.99 +dir=\\\$(dirname \\\$0) 1.100 +for i in 0 \$rootfslist ; do 1.101 + [ -s \\\$dir/rootfs.\\\$i ] || continue 1.102 + cpio -idmu < \\\$dir/rootfs.\\\$i > /dev/null 2>&1 || 1.103 + ( zcat \\\$dir/rootfs.\\\$i 2> /dev/null || unlzma -c \\\$dir/rootfs.\\\$i ) | cpio -idmu 1.104 +done 1.105 +mv -f init.org init 1.106 +mkdir boot && cp \\\$dir/bzImage boot 1.107 +cp -a /usr/lib/grub/i386-pc boot/grub 1.108 +cat > boot/grub/menu.lst<<EOF 1.109 +# /boot/grub/menu.lst: GRUB boot loader configuration. 1.110 +# 1.111 + 1.112 +# By default, boot the first entry. 1.113 +default 0 1.114 + 1.115 +# Boot automatically after 8 secs. 1.116 +timeout 8 1.117 + 1.118 +# Change the colors. 1.119 +color yellow/brown light-green/black 1.120 + 1.121 +title SliTaz GNU/Linux 1.122 + kernel /boot/bzImage root=\$device 1.123 + 1.124 +EOF 1.125 +grub-install --no-floppy --root-directory=\\\$PWD \${device%[1-9]*} 1.126 +cd - 1.127 +EOT 1.128 + chmod +x /mnt/slitaz/install.sh 1.129 + num=1 1.130 + name="the Linux kernel" 1.131 + dd count=0 of=/mnt/slitaz/bzImage.fd 1.132 + fullsize=1 1.133 + while [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$fullsize ]; do 1.134 + cat_floppy /mnt/slitaz/bzImage.fd 1.135 + setup=\$(dd if=/mnt/slitaz/bzImage.fd skip=497 bs=1 count=1 2> /dev/null | hexdump -e '"" 1/1 "%d" "\n"') 1.136 + syssize=\$(dd if=/mnt/slitaz/bzImage.fd skip=500 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"') 1.137 + cmdline=\$(dd if=/mnt/slitaz/bzImage.fd skip=552 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"') 1.138 + initrd=\$(dd if=/mnt/slitaz/bzImage.fd skip=540 bs=1 count=4 2> /dev/null | hexdump -e '"" 1/4 "%d" "\n"') 1.139 + [ \$cmdline -eq 0 ] || cmdline=512 1.140 + size=\$((512 + \$setup * 512 + \$cmdline + \$syssize * 16)) 1.141 + [ -s /etc/slitaz-release ] || initrd=0 1.142 + fullsize=\$((\$size + \$initrd + 512)) 1.143 + [ \$(stat -c %s /mnt/slitaz/bzImage.fd) -lt \$size ] || 1.144 + name="the first initramfs" 1.145 + done 1.146 + [ -s /etc/slitaz-release ] && 1.147 + dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512+(31+\$syssize)/32)) > /mnt/slitaz/rootfs.0 && 1.148 + dd bs=1 seek=\$initrd count=0 of=/mnt/slitaz/rootfs.0 1.149 + dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=4 seek=552 1.150 + dd if=/dev/zero of=/mnt/slitaz/bzImage.fd conv=notrunc bs=1 count=8 seek=536 1.151 + dd if=/mnt/slitaz/bzImage.fd bs=512 count=\$((\$setup+1)) > /mnt/slitaz/bzImage 1.152 + dd if=/mnt/slitaz/bzImage.fd bs=512 skip=\$((\$setup+1+\$cmdline/512)) >> /mnt/slitaz/bzImage 1.153 + rm -f /mnt/slitaz/bzImage.fd 1.154 + size=\$((512 + \$setup * 512 + \$syssize * 16)) 1.155 + dd bs=1 seek=\$size count=0 of=/mnt/slitaz/bzImage 1.156 + [ \$(stat -c %s /mnt/slitaz/bzImage) -eq \$size ] || 1.157 + mv -f /mnt/slitaz /mnt/slitaz-aborted 1.158 +fi 1.159 mv -f /init.org /init || sh 1.160 exec /init 1.161 EOTEOT