wok rev 16055

syslinux/iso2exe: fix 'a la tazusb' install
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Mar 11 15:44:47 2014 +0000 (2014-03-11)
parents 38cdd37ed6ef
children e1174b47e40e
files syslinux/stuff/iso2exe/init syslinux/stuff/iso2exe/iso2exe.c
line diff
     1.1 --- a/syslinux/stuff/iso2exe/init	Mon Mar 10 18:05:36 2014 +0100
     1.2 +++ b/syslinux/stuff/iso2exe/init	Tue Mar 11 15:44:47 2014 +0000
     1.3 @@ -79,6 +79,48 @@
     1.4  	blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/"
     1.5  }
     1.6  
     1.7 +tazusbinitfs()
     1.8 +{
     1.9 +	PAD=$(($(stat -c %s $1) % 4))
    1.10 +	[ $PAD -ne 0 ] && dd if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
    1.11 +	mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
    1.12 +	cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
    1.13 +	cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
    1.14 +	sed 's/ .*//' /proc/modules | while read mod ; do
    1.15 +		find /lib/modules/ | grep $mod.ko | \
    1.16 +			sed 's|.*|cp & /tmp/fs/lib|' | sh
    1.17 +	done
    1.18 +	cat > /tmp/fs/init1 <<EOT
    1.19 +#!/bin/sh
    1.20 +sed -i 's|sbin/init|init2|' /init
    1.21 +exec /init
    1.22 +EOT
    1.23 +	cat > /tmp/fs/init2 <<EOT
    1.24 +#!/bin/sh
    1.25 +
    1.26 +mount -t proc /proc /proc
    1.27 +  grep -q debug /proc/cmdline && debug=true && set -x
    1.28 +for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
    1.29 +v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
    1.30 +mount / -o remount,rw
    1.31 +mkdir /mnt/dos
    1.32 +rm -f /cmdline 2> /dev/null
    1.33 +mount / -o remount,ro
    1.34 +mnt=/mnt/dos/\${v#*/}
    1.35 +dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
    1.36 +echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
    1.37 +mount \$dev /mnt/dos
    1.38 +mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
    1.39 +mount --bind \$mnt /home
    1.40 +  [ "\$debug" = "true" ] && sh
    1.41 +umount /proc
    1.42 +exec /sbin/init
    1.43 +EOT
    1.44 +	chmod 755 /tmp/fs/init?
    1.45 +	cp -a /tmp/fs/* /
    1.46 +	( cd /tmp/fs ; find * | cpio -o -H newc ) | gzip -9 >> $1
    1.47 +}
    1.48 +
    1.49  mkinitrd()
    1.50  {
    1.51  	echo "Creating $(basename $1) ..."
    1.52 @@ -115,9 +157,9 @@
    1.53  
    1.54  mount -t proc /proc /proc
    1.55    arg debug "shell" && debug=true && set -x
    1.56 -for i in /lib/*.ko* ; do insmod \$i ; done; sleep 2
    1.57 +for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
    1.58  arg mount "Mount device"
    1.59 -mount \$( (blkid /dev/?d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
    1.60 +mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
    1.61  arg subroot "Change root to directory"
    1.62  mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
    1.63  mount --bind /mnt /mnt/\$val/mnt/dos
    1.64 @@ -158,9 +200,9 @@
    1.65  		else
    1.66  			ls_r /media/cdrom/boot/rootfs* | xargs cat
    1.67  		fi > /mnt/slitaz/boot/rootfs.gz
    1.68 -		mkdir /mnt/slitaz/home
    1.69 +		tazusbinitfs /mnt/slitaz/boot/rootfs.gz
    1.70  		initrd=rootfs.gz
    1.71 -		extraargs="/home=$(getuuid)/slitaz/home" # FIXME /mnt/dos
    1.72 +		extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
    1.73  	else
    1.74  		if [ -d /media/cdrom/fs ]; then
    1.75  			cp -a /media/cdrom/fs/. /mnt/slitaz
    1.76 @@ -179,6 +221,8 @@
    1.77  				uncpio $i /mnt/slitaz
    1.78  			done
    1.79  		fi
    1.80 +		cp -a /etc/locale.conf /tmp/slitaz/etc 2> /dev/null
    1.81 +		cp -a /etc/keymap.conf /tmp/slitaz/etc 2> /dev/null
    1.82  		mkinitrd /mnt/slitaz/boot/initrd
    1.83  		initrd=initrd
    1.84  		extraargs="mount=$(getuuid) subroot=slitaz"
    1.85 @@ -261,18 +305,21 @@
    1.86  	[ $? -eq 0 ] || return
    1.87  	doinstall tazusblike || return
    1.88  	if [ -d /media/cdrom/fs ]; then
    1.89 -		zcat /mnt/slitaz/boot/rootfs.gz | cpio -idmu
    1.90 +		cp -a /media/cdrom/fs/. /
    1.91  	else
    1.92  		for i in $(ls_r /media/cdrom/boot/rootfs*); do
    1.93 -			( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
    1.94 +			unlzma < $i | (cd / ; cpio -idmu )
    1.95  		done
    1.96  	fi
    1.97 -	[ -x /sbin/init ] || return
    1.98 +	cp /tmp/fs/etc/* /etc
    1.99 +	echo "/home=$(getuuid)/slitaz" > /cmdline
   1.100 +	[ -x /init1 ] || return
   1.101  	umount -d /media/cdrom
   1.102 -	mount --move /mnt /mnt/dos
   1.103 -	ln -s /mnt/dos/slitaz/home /home
   1.104 +	umount /mnt/slitaz
   1.105 +	umount /mnt
   1.106 +	mkdir /mnt/dos
   1.107  	umount_proc
   1.108 -	exec /sbin/init
   1.109 +	exec /init1
   1.110  }
   1.111  
   1.112  tazboot()
   1.113 @@ -576,10 +623,14 @@
   1.114  dmesg > /tmp/dmesg
   1.115  
   1.116  while true; do
   1.117 +	keymap="$(cat /etc/keymap.conf 2> /dev/null)"
   1.118 +	locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
   1.119  	cat > /tmp/dialog <<EOT
   1.120  $DIALOG  --clear \
   1.121  	--title " Welcome to SliTaz " \
   1.122  	--menu "" 21 70 15 \
   1.123 +$(xfile tazkeymap	"tazkeymap"	"Select keyboard ($keymap)") \
   1.124 +$(xfile tazlocale	"tazlocale"	"Select locale ($locale)") \
   1.125  $(cdfile boot/bzImage	"live"		"SliTaz RAM boot") \
   1.126  			"text"		"SliTaz RAM boot (text mode only)" \
   1.127  $(cdfile README		"readme"	"Show the README file") \
     2.1 --- a/syslinux/stuff/iso2exe/iso2exe.c	Mon Mar 10 18:05:36 2014 +0100
     2.2 +++ b/syslinux/stuff/iso2exe/iso2exe.c	Tue Mar 11 15:44:47 2014 +0000
     2.3 @@ -6,7 +6,7 @@
     2.4  #endif
     2.5  #include "iso2exe.h"
     2.6  
     2.7 -static int fd, status = 1;
     2.8 +static int fd, forced, status = 1;
     2.9  static char tazlitoinfo[10*1024];
    2.10  #define buffer tazlitoinfo
    2.11  #define BUFFERSZ 2048
    2.12 @@ -36,40 +36,43 @@
    2.13  	     bootiso++) if (bootiso < (char *) install) return "No bootiso data.\n";
    2.14  #endif
    2.15  	if (!filename)
    2.16 -		return "Usage: isohybrid.exe file.iso\n";
    2.17 +		return "Usage: isohybrid.exe file.iso [--forced]\n";
    2.18  	fd = open(filename,O_RDWR|O_BINARY);
    2.19  	if (fd == -1)
    2.20  		return "Can't open rw the iso file.\n";
    2.21  
    2.22 -	// Install hybridiso boot sector
    2.23 -	readsector(17UL);
    2.24 -	if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23))
    2.25 -		return "No EL TORITO signature.\n";
    2.26 -	catalog = * (unsigned long *) (buffer + 71);
    2.27 -	readsector(catalog);
    2.28 -	if (* (unsigned long *) buffer != 1 || 
    2.29 -	    * (unsigned long *) (buffer + 30) != 0x88AA55)
    2.30 -	    	return "Invalid boot catalog.\n";
    2.31 -	lba = * (unsigned long *) (buffer + 40);
    2.32 -	readsector(lba);
    2.33 -	if (* (unsigned long *) (buffer + 64) != 1886961915)
    2.34 -		return "No isolinux.bin hybrid signature.\n";
    2.35 -	isohybrid = bootiso[69] * 512;
    2.36 -	* (unsigned long *)  &bootiso[isohybrid + 432] = lba * 4;
    2.37 -	* (unsigned long *)  &bootiso[isohybrid + 440] = rand();
    2.38 -	* (unsigned long *)  &bootiso[isohybrid + partition] = 0x10080;
    2.39 -	* (unsigned short *) &bootiso[isohybrid + 510] = 0xAA55;
    2.40 -	size = lseek(fd, 0UL, SEEK_END);
    2.41 -	cylinders = (size + trksz - 1) / trksz;
    2.42 -	bootiso[isohybrid + partition + 4] = 23; // "Windows hidden IFS"
    2.43 -	bootiso[isohybrid + partition + 5] = heads - 1;
    2.44 -	bootiso[isohybrid + partition + 6] = (((cylinders - 1) & 0x300) >> 2) + sectors;
    2.45 -	bootiso[isohybrid + partition + 7] = (cylinders - 1) & 0xFF;
    2.46 -	* (unsigned long *) &bootiso[isohybrid + partition + 8] = 0;
    2.47 -	* (unsigned long *) &bootiso[isohybrid + partition + 12] = cylinders * sectors * heads;
    2.48 +	if (forced == 0) {
    2.49 +		status = 2;
    2.50 +		// Install hybridiso boot sector
    2.51 +		readsector(17UL);
    2.52 +		if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23))
    2.53 +			return "No EL TORITO signature.\n";
    2.54 +		catalog = * (unsigned long *) (buffer + 71);
    2.55 +		readsector(catalog);
    2.56 +		if (* (unsigned long *) buffer != 1 || 
    2.57 +		    * (unsigned long *) (buffer + 30) != 0x88AA55)
    2.58 +		    	return "Invalid boot catalog.\n";
    2.59 +		lba = * (unsigned long *) (buffer + 40);
    2.60 +		readsector(lba);
    2.61 +		if (* (unsigned long *) (buffer + 64) != 1886961915)
    2.62 +			return "No isolinux.bin hybrid signature.\n";
    2.63 +		isohybrid = bootiso[69] * 512;
    2.64 +		* (unsigned long *)  &bootiso[isohybrid + 432] = lba * 4;
    2.65 +		* (unsigned long *)  &bootiso[isohybrid + 440] = rand();
    2.66 +		* (unsigned long *)  &bootiso[isohybrid + partition] = 0x10080;
    2.67 +		* (unsigned short *) &bootiso[isohybrid + 510] = 0xAA55;
    2.68 +		size = lseek(fd, 0UL, SEEK_END);
    2.69 +		cylinders = (size + trksz - 1) / trksz;
    2.70 +		bootiso[isohybrid + partition + 4] = 23; // "Windows hidden IFS"
    2.71 +		bootiso[isohybrid + partition + 5] = heads - 1;
    2.72 +		bootiso[isohybrid + partition + 6] = (((cylinders - 1) & 0x300) >> 2) + sectors;
    2.73 +		bootiso[isohybrid + partition + 7] = (cylinders - 1) & 0xFF;
    2.74 +		* (unsigned long *) &bootiso[isohybrid + partition + 8] = 0;
    2.75 +		* (unsigned long *) &bootiso[isohybrid + partition + 12] = cylinders * sectors * heads;
    2.76  
    2.77 -	// Copy the partition table
    2.78 -	memcpy(bootiso + 0x1BE, bootiso + isohybrid + 0x1BE, 66);
    2.79 +		// Copy the partition table
    2.80 +		memcpy(bootiso + 0x1BE, bootiso + isohybrid + 0x1BE, 66);
    2.81 +	}
    2.82  
    2.83  	// Install iso2exe boot sector
    2.84  	* (unsigned short *) (bootiso + 26) = rand();
    2.85 @@ -106,7 +109,10 @@
    2.86  
    2.87  int main(int argc, char *argv[])
    2.88  {
    2.89 +	forced = (argc > 2);
    2.90  	puts(install(argv[1]));
    2.91 +	if (status > 1)
    2.92 +		puts("You can add --forced to proceed anayway");
    2.93  #ifdef WIN32
    2.94  	Sleep(2000);
    2.95  #endif