wok-current rev 23947

syslinux/taziso/usbbootkey: gpt supprt
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 20 15:59:25 2020 +0000 (2020-09-20)
parents 09d8c12d6514
children 3996eb426001
files syslinux/stuff/iso2exe/taziso
line diff
     1.1 --- a/syslinux/stuff/iso2exe/taziso	Sun Sep 20 14:15:26 2020 +0000
     1.2 +++ b/syslinux/stuff/iso2exe/taziso	Sun Sep 20 15:59:25 2020 +0000
     1.3 @@ -33,6 +33,23 @@
     1.4  	done | xargs echo -en
     1.5  }
     1.6  
     1.7 +word32s2bin()
     1.8 +{
     1.9 +	for i in $@ ; do
    1.10 +		printf '\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X' $(($i&255)) \
    1.11 +			$((($i>>8)&255)) $((($i>>16)&255)) $((($i>>24)&255))
    1.12 +	done | xargs echo -en
    1.13 +}
    1.14 +
    1.15 +word64s2bin()
    1.16 +{
    1.17 +	for i in $@ ; do
    1.18 +		printf '\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X' \
    1.19 +			$(($i&255)) $((($i>>8)&255)) $((($i>>16)&255)) $((($i>>24)&255)) \
    1.20 +			$((($i>>32)&255)) $((($i>>40)&255)) $((($i>>48)&255)) $((($i>>56)&255))
    1.21 +	done | xargs echo -en
    1.22 +}
    1.23 +
    1.24  gettazboot()
    1.25  {
    1.26  	echo -e "\nCreating $(basename $1) ..."
    1.27 @@ -54,6 +71,16 @@
    1.28  	grep -q ' lm ' /proc/cpuinfo && [ -s ${1}64 ] && echo 64
    1.29  }
    1.30  
    1.31 +size()
    1.32 +{
    1.33 +	[ -L "$1" ] && case "$(readlink "$1")" in
    1.34 +	/*) set -- $(readlink "$1") ;;
    1.35 +	*)  set -- $(dirname "$1")/$(readlink "$1") ;;
    1.36 +	esac
    1.37 +	[ ! -b "$1" ] && echo $(stat -c %s "$1") ||
    1.38 +	echo $(($(cat /sys/block/${1#/dev/}/size)*512)
    1.39 +}
    1.40 +
    1.41  uncpio()
    1.42  {
    1.43  	i=$1                                                    
    1.44 @@ -90,7 +117,7 @@
    1.45  
    1.46  tazusbinitfs()
    1.47  {
    1.48 -	PAD=$(($(stat -c %s $1) % 4))
    1.49 +	PAD=$(($(size $1) % 4))
    1.50  	[ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
    1.51  	mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
    1.52  	cp -a /etc/locale.conf /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
    1.53 @@ -623,7 +650,7 @@
    1.54  	for i in $(ls_r $media/boot/rootfs*gz); do
    1.55  		i=$(maybe64 $i)
    1.56  		cat $i
    1.57 -		n=$((4 - ($(stat -c %s $i) % 4)))
    1.58 +		n=$((4 - ($(size $i) % 4)))
    1.59  		[ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
    1.60  	done > initrd$$
    1.61  	cmdline="root=/dev/null autologin lang=$LANG"
    1.62 @@ -1081,6 +1108,84 @@
    1.63  able to save the package updates or your own configuration and data files.\n\n"
    1.64  }
    1.65  
    1.66 +gpt_crc32()
    1.67 +{
    1.68 +	t0=00000000; t1=77073096; t2=EE0E612C; t3=990951BA;
    1.69 +	t4=076DC419; t5=706AF48F; t6=E963A535; t7=9E6495A3;
    1.70 +	t8=0EDB8832; t9=79DCB8A4; t10=E0D5E91E; t11=97D2D988;
    1.71 +	t12=09B64C2B; t13=7EB17CBD; t14=E7B82D07; t15=90BF1D91;
    1.72 +	t16=1DB71064; t17=6AB020F2; t18=F3B97148; t19=84BE41DE;
    1.73 +	t20=1ADAD47D; t21=6DDDE4EB; t22=F4D4B551; t23=83D385C7;
    1.74 +	t24=136C9856; t25=646BA8C0; t26=FD62F97A; t27=8A65C9EC;
    1.75 +	t28=14015C4F; t29=63066CD9; t30=FA0F3D63; t31=8D080DF5;
    1.76 +	t32=3B6E20C8; t33=4C69105E; t34=D56041E4; t35=A2677172;
    1.77 +	t36=3C03E4D1; t37=4B04D447; t38=D20D85FD; t39=A50AB56B;
    1.78 +	t40=35B5A8FA; t41=42B2986C; t42=DBBBC9D6; t43=ACBCF940;
    1.79 +	t44=32D86CE3; t45=45DF5C75; t46=DCD60DCF; t47=ABD13D59;
    1.80 +	t48=26D930AC; t49=51DE003A; t50=C8D75180; t51=BFD06116;
    1.81 +	t52=21B4F4B5; t53=56B3C423; t54=CFBA9599; t55=B8BDA50F;
    1.82 +	t56=2802B89E; t57=5F058808; t58=C60CD9B2; t59=B10BE924;
    1.83 +	t60=2F6F7C87; t61=58684C11; t62=C1611DAB; t63=B6662D3D;
    1.84 +	t64=76DC4190; t65=01DB7106; t66=98D220BC; t67=EFD5102A;
    1.85 +	t68=71B18589; t69=06B6B51F; t70=9FBFE4A5; t71=E8B8D433;
    1.86 +	t72=7807C9A2; t73=0F00F934; t74=9609A88E; t75=E10E9818;
    1.87 +	t76=7F6A0DBB; t77=086D3D2D; t78=91646C97; t79=E6635C01;
    1.88 +	t80=6B6B51F4; t81=1C6C6162; t82=856530D8; t83=F262004E;
    1.89 +	t84=6C0695ED; t85=1B01A57B; t86=8208F4C1; t87=F50FC457;
    1.90 +	t88=65B0D9C6; t89=12B7E950; t90=8BBEB8EA; t91=FCB9887C;
    1.91 +	t92=62DD1DDF; t93=15DA2D49; t94=8CD37CF3; t95=FBD44C65;
    1.92 +	t96=4DB26158; t97=3AB551CE; t98=A3BC0074; t99=D4BB30E2;
    1.93 +	t100=4ADFA541; t101=3DD895D7; t102=A4D1C46D; t103=D3D6F4FB;
    1.94 +	t104=4369E96A; t105=346ED9FC; t106=AD678846; t107=DA60B8D0;
    1.95 +	t108=44042D73; t109=33031DE5; t110=AA0A4C5F; t111=DD0D7CC9;
    1.96 +	t112=5005713C; t113=270241AA; t114=BE0B1010; t115=C90C2086;
    1.97 +	t116=5768B525; t117=206F85B3; t118=B966D409; t119=CE61E49F;
    1.98 +	t120=5EDEF90E; t121=29D9C998; t122=B0D09822; t123=C7D7A8B4;
    1.99 +	t124=59B33D17; t125=2EB40D81; t126=B7BD5C3B; t127=C0BA6CAD;
   1.100 +	t128=EDB88320; t129=9ABFB3B6; t130=03B6E20C; t131=74B1D29A;
   1.101 +	t132=EAD54739; t133=9DD277AF; t134=04DB2615; t135=73DC1683;
   1.102 +	t136=E3630B12; t137=94643B84; t138=0D6D6A3E; t139=7A6A5AA8;
   1.103 +	t140=E40ECF0B; t141=9309FF9D; t142=0A00AE27; t143=7D079EB1;
   1.104 +	t144=F00F9344; t145=8708A3D2; t146=1E01F268; t147=6906C2FE;
   1.105 +	t148=F762575D; t149=806567CB; t150=196C3671; t151=6E6B06E7;
   1.106 +	t152=FED41B76; t153=89D32BE0; t154=10DA7A5A; t155=67DD4ACC;
   1.107 +	t156=F9B9DF6F; t157=8EBEEFF9; t158=17B7BE43; t159=60B08ED5;
   1.108 +	t160=D6D6A3E8; t161=A1D1937E; t162=38D8C2C4; t163=4FDFF252;
   1.109 +	t164=D1BB67F1; t165=A6BC5767; t166=3FB506DD; t167=48B2364B;
   1.110 +	t168=D80D2BDA; t169=AF0A1B4C; t170=36034AF6; t171=41047A60;
   1.111 +	t172=DF60EFC3; t173=A867DF55; t174=316E8EEF; t175=4669BE79;
   1.112 +	t176=CB61B38C; t177=BC66831A; t178=256FD2A0; t179=5268E236;
   1.113 +	t180=CC0C7795; t181=BB0B4703; t182=220216B9; t183=5505262F;
   1.114 +	t184=C5BA3BBE; t185=B2BD0B28; t186=2BB45A92; t187=5CB36A04;
   1.115 +	t188=C2D7FFA7; t189=B5D0CF31; t190=2CD99E8B; t191=5BDEAE1D;
   1.116 +	t192=9B64C2B0; t193=EC63F226; t194=756AA39C; t195=026D930A;
   1.117 +	t196=9C0906A9; t197=EB0E363F; t198=72076785; t199=05005713;
   1.118 +	t200=95BF4A82; t201=E2B87A14; t202=7BB12BAE; t203=0CB61B38;
   1.119 +	t204=92D28E9B; t205=E5D5BE0D; t206=7CDCEFB7; t207=0BDBDF21;
   1.120 +	t208=86D3D2D4; t209=F1D4E242; t210=68DDB3F8; t211=1FDA836E;
   1.121 +	t212=81BE16CD; t213=F6B9265B; t214=6FB077E1; t215=18B74777;
   1.122 +	t216=88085AE6; t217=FF0F6A70; t218=66063BCA; t219=11010B5C;
   1.123 +	t220=8F659EFF; t221=F862AE69; t222=616BFFD3; t223=166CCF45;
   1.124 +	t224=A00AE278; t225=D70DD2EE; t226=4E048354; t227=3903B3C2;
   1.125 +	t228=A7672661; t229=D06016F7; t230=4969474D; t231=3E6E77DB;
   1.126 +	t232=AED16A4A; t233=D9D65ADC; t234=40DF0B66; t235=37D83BF0;
   1.127 +	t236=A9BCAE53; t237=DEBB9EC5; t238=47B2CF7F; t239=30B5FFE9;
   1.128 +	t240=BDBDF21C; t241=CABAC28A; t242=53B39330; t243=24B4A3A6;
   1.129 +	t244=BAD03605; t245=CDD70693; t246=54DE5729; t247=23D967BF;
   1.130 +	t248=B3667A2E; t249=C4614AB8; t250=5D681B02; t251=2A6F2B94;
   1.131 +	t252=B40BBE37; t253=C30C8EA1; t254=5A05DF1B; t255=2D02EF8D;
   1.132 +	crc=$((0xFFFFFFFF))
   1.133 +	dd if=$iso bs=1 skip=$(($1)) count=$(($2)) 2> /dev/null | \
   1.134 +	od -v -w1 -t u1 -An | {
   1.135 +		while read n; do
   1.136 +			local x=$((($crc ^ $n) & 255))
   1.137 +			eval x=0x\$t$x
   1.138 +			crc=$(((($crc >> 8) & 0x00FFFFFF) ^ $x))
   1.139 +		done
   1.140 +		echo $(($crc ^ 0xFFFFFFFF))
   1.141 +	}
   1.142 +}
   1.143 +
   1.144  usbbootkey()
   1.145  {
   1.146  	if [ -b "$1" ]; then
   1.147 @@ -1100,7 +1205,7 @@
   1.148  	fi
   1.149  	
   1.150  	# perform dd in progress bar
   1.151 -	max=$(($(stat -c %s "$ISO")/1024/1024))
   1.152 +	max=$(($(size "$ISO")/1024/1024))
   1.153  	i=0; while [ $i -le $max ]; do
   1.154  		ddq if="$ISO" bs=1024k count=1 skip=$i seek=$i of=$device
   1.155  		echo $((($i*100)/$max))
   1.156 @@ -1108,30 +1213,33 @@
   1.157  	done | dialog --gauge " The ISO image transfer can be long. Please wait..." \
   1.158  			6 70 0 > /dev/tty 2>&1
   1.159  
   1.160 -	# partition + fat32 format for the remaining space
   1.161 -	for p in 0 16; do
   1.162 -		get $((450+$p)) $device 2 12 | xargs echo | {
   1.163 -		read dx cx ol oh ll lh
   1.164 -		[ $dx -eq $((0x3F17)) ] || continue
   1.165 -		cx=$(($cx & 0xFF00))
   1.166 -		ofs=$(($ll+($lh<<16)))
   1.167 -		n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
   1.168 -		m=$(($cx+($n/8)))
   1.169 -		[ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
   1.170 -		m=$((($m & 0xFF00)+(($m>>16)<<6)))
   1.171 -		words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
   1.172 -			$ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
   1.173 -			ddq bs=1 seek=$((462-$p)) of=$device
   1.174 -		if [ "$(which mkdosfs 2> /dev/null)" ]; then
   1.175 -			losetup -o $((512*$ofs)) /dev/loop2 $device
   1.176 -			mkdosfs -n "SLITAZ BOOT" /dev/loop2
   1.177 -			words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
   1.178 -				ddq bs=1 seek=28 of=/dev/loop2
   1.179 -			sync
   1.180 -			losetup -d /dev/loop2
   1.181 -		fi
   1.182 - 		}
   1.183 - 	done
   1.184 +	# GPT partition + fat32 format for the remaining space
   1.185 +	sectors=$(($(size $device)/512))
   1.186 +	word32s2bin $(($sectors-1)) | ddq bs=1 seek=458 of=$device	# pmbr
   1.187 +	word32s2bin 0 | ddq bs=1 seek=$((512+16)) of=$device
   1.188 +	word64s2bin $(($sectors-3)) | ddq bs=1 seek=$((512+48)) of=$device
   1.189 +	uudecode - <<EOT | gunzip | ddn bs=128 seek=9 of=$device	# partiton fat32
   1.190 +begin-base64 644 -
   1.191 +H4sIAAAAAAACA1u04MLrpzuNXdoPZGzbrjbz+C/fHwyfEro9Z7E93Fi5/8sH
   1.192 +BhzAiSGRoZghkyGZQYEhBcguAWIFhgIgWQRkZ4JxPkMeAyEAAOuEo7uAAAAA
   1.193 +====
   1.194 +EOT
   1.195 +	last=$(($(size "$ISO")/512))
   1.196 +	custom=$((4*$(get 32848 $device 4)))
   1.197 +	[ $custom -gt $(($last-4)) ] && last=$(($custom+4))		# room for cmdline
   1.198 +	word64s2bin $last | ddq bs=1 seek=$((1024+128+32)) of=$device	# vfat first address
   1.199 +	word64s2bin $(($sectors-3)) | ddq bs=1 seek=$((1024+128+40)) of=$device	# vfat last address
   1.200 +	word32s2bin $(gpt_crc32 1024 $(($(get 596 $device 4)*$(get 592 $device 4)))) | ddq bs=1 seek=$((512+88))	# CRC32 partitions
   1.201 +	ddn of=$device if=$device bs=512 skip=1 seek=$(($sectors-1)) count=1
   1.202 +	ddn of=$device if=$device bs=512 skip=2 seek=$(($sectors-2)) count=1
   1.203 +	word64s2bin $(($sectors-1)) 1 | ddq bs=1 seek=$(($sectors*512-512+24)) of=$device	# my gpt, alt gpt
   1.204 +	word64s2bin $(($sectors-1)) | ddq bs=1 seek=$((512+32)) of=$device	# alt gpt
   1.205 +	word64s2bin $(($sectors-2)) | ddq bs=1 seek=$(($sectors*512-512+72)) of=$device
   1.206 +	word32s2bin $(gpt_crc32 $(($sectors*512-512)) $(get 525 $device 4)) | ddq bs=1 seek=$(($sectors*512-512+16))	# CRC32 header
   1.207 +	word32s2bin $(gpt_crc32 512 $(get 524 $device 4)) | ddq bs=1 seek=$((512+16))	# CRC32 header
   1.208 +	partprobe $device
   1.209 +	homedev=/dev/$(basename /sys/block/${device#/dev/}/${device#/dev/}*2)
   1.210 +	mkdosfs -n 'SLITAZ HOME' $homedev
   1.211  
   1.212  	# update boot/exe crc16
   1.213  	i=$(($(get 2 $1) - 1 + ($(get 4 $1) - 1)*512))
   1.214 @@ -1139,6 +1247,19 @@
   1.215  		awk '{ i+= $0 } END { print (i % 65536) }') \
   1.216  		+ $(get $(($i+1)) $device 1)))
   1.217  	words2bin $(( (-$i -1) % 65536 )) | ddq bs=1 seek=18 of=$device
   1.218 +
   1.219 +	$DIALOG --clear --title " Set /home persistent " \
   1.220 +			--yes-label "Continue" --yesno \
   1.221 +"\nThe USB key will run fully in ram. The datas will be lost after reboot.\n\n
   1.222 +This option will mount /home on the USB key during the boot process.\n" 16 70
   1.223 +	if [ $? -eq 0 ]; then
   1.224 +		data="append=home=$(blkid $homedev | sed 's|.* UUID="||;s|".*||') kmap=$(cat /etc/keymap.conf) lang=${LANG%.UTF*} tz=$(cat /etc/TZ) loadfs"
   1.225 +		cat <<EOT | ddn bs=512 seek=$custom of=$device
   1.226 +#!boot $(echo "$data" | md5sum | sed 's/ .*//')
   1.227 +$data
   1.228 +--
   1.229 +EOT
   1.230 +	fi
   1.231  }
   1.232  
   1.233  usbkey()
   1.234 @@ -1225,7 +1346,7 @@
   1.235  
   1.236  if [ "$1" = "--build" ]; then	#install-begin
   1.237  	uuencode -m - < header.com | sed -e '/^HEADERCODE$/r/dev/stdin' \
   1.238 -	  -e "s|HEADERSZ|$(stat -c %s header.com)|" -e '/^HEADERCODE$/d' -i $0
   1.239 +	  -e "s|HEADERSZ|$(size header.com)|" -e '/^HEADERCODE$/d' -i $0
   1.240  	uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
   1.241  	  -e '/^ifmemcode$/d' -i $0
   1.242  	uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
   1.243 @@ -1317,7 +1438,7 @@
   1.244  	syssize=$(echo $(get 500 /tmp/fd$$ 4))
   1.245  	ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
   1.246  	ddq bs=512 count=$((($syssize+31)/32)) conv=sync >> /tmp/fd$$
   1.247 -	base=$(stat -c %s /tmp/fd$$)
   1.248 +	base=$(size /tmp/fd$$)
   1.249  	len=
   1.250  	if [ "$INITRD" ]; then
   1.251  		l=0
   1.252 @@ -1328,7 +1449,7 @@
   1.253  				[ -n "$j" ] && i=$j && break
   1.254  			done
   1.255  			ddq if=$i >> /tmp/fd$$
   1.256 -			l=$(($l+$(stat -c %s $i)))
   1.257 +			l=$(($l+$(size $i)))
   1.258  			r=$((4 - ($l % 4)))
   1.259  			if [ $r -ne 4 ]; then
   1.260  				ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
   1.261 @@ -1491,7 +1612,7 @@
   1.262  $(gotposixovlzip	"inst2zip"	"ZIP installation archive (UMSDOS way)") \
   1.263  $(gotposixovlzip	"insttaz2zip"	"ZIP installation archive (TAZUSB way)") \
   1.264  $(gottazusb 		"usbkey"	"USB key read/write installation") \
   1.265 -$(ishybrid		"usbbootkey"	"USB boot key (read only)") \
   1.266 +$(ishybrid		"usbbootkey"	"USB boot key (not upgradable)") \
   1.267  $(hasflavinfo		"showfavinfo"	"Show flavor extra info") \
   1.268  $(hasflavor		"flavor"	"Get flavor file") \
   1.269  $(cdfile isolinux.cfg	"floppyset"	"Boot floppy set") \