tazlito rev 535
tazlito: fix EFI eltorito boot file size
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 07 08:41:10 2022 +0000 (2022-04-07) |
parents | bf8d0ce5da01 |
children | 299ee29d2c03 |
files | tazlito |
line diff
1.1 --- a/tazlito Sun Feb 27 21:14:03 2022 +0000 1.2 +++ b/tazlito Thu Apr 07 08:41:10 2022 +0000 1.3 @@ -34,7 +34,7 @@ 1.4 CACHE_DIR='/var/cache/tazpkg' 1.5 MIRROR="$LOCALSTATE/mirror" 1.6 DEFAULT_MIRROR="http://mirror1.slitaz.org/packages/$(cat /etc/slitaz-release)/" 1.7 -efi_img="efi/esp.img" 1.8 +efi_img="EFI/esp.img" 1.9 1.10 log='/var/log/tazlito.log' 1.11 if [ $(id -u) -eq 0 ]; then 1.12 @@ -278,10 +278,10 @@ 1.13 # Force size and location in the 2nd eltorito boot file (/$efi_img) 1.14 1.15 fix_efi_boot_img_size() { 1.16 - local n=$3 1.17 + local n=$(($3/4)) 1.18 # Sector count on 16 bits (max 128MB), see offset 6-7 in page 11 of 1.19 # https://pdos.csail.mit.edu/6.828/2014/readings/boot-cdrom.pdf 1.20 - [ $n -gt 65535 ] && n=65535 && echo "Warning: truncate EFI eltorito boot file" 1.21 + [ $n -gt 65535 ] && echo "Warning: truncate EFI eltorito boot file $n" && n=65535 1.22 set32 $((0x66+2048*$(first_block $2/boot/isolinux/boot.cat))) $n $1 16 1.23 set32 $((0x1C+2048*$4)) $(($4*4)) $1 1.24 } 1.25 @@ -333,6 +333,16 @@ 1.26 basecluster=$(((resv+2*fatsz)/4+efiblock-1)) 1.27 fi 2> /dev/null 1.28 hd "$2/$efi_img" | awk 'BEGIN { skiphead='$skiphead' } 1.29 +function setname() { 1.30 + if (name!="") return 1.31 + name=substr($0,62,8) 1.32 + i=index(name," ") 1.33 + if (i>0) name=substr($0,62,i-1) 1.34 + i=index(substr($0,70,3)," ") 1.35 + if (i==0) i=3 1.36 + if (i>1) name=name "." substr($0,70,i) 1.37 + name=tolower(name) 1.38 +} 1.39 { 1.40 if (skiphead!=0) { 1.41 if ($1=="*") skiphead-- 1.42 @@ -380,16 +390,20 @@ 1.43 next 1.44 } 1.45 if ($13=="10") { 1.46 + setname() 1.47 name=name "/" 1.48 gotname=2 1.49 next 1.50 } 1.51 if ($13=="20") { 1.52 + setname() 1.53 gotname=1 1.54 next 1.55 } 1.56 + if ($13!="08" && $13!="00" && $13!="") exit 1.57 } 1.58 ' | ( while read offset cluster file; do 1.59 + file="${file/efi/EFI}" 1.60 cluster=$(($(first_block "$2/$file")-basecluster)) 1.61 set32 $((efiblock*2048+0x$offset+10)) $cluster "$1" 16 1.62 set32 $((efiblock*2048+0x$offset+4)) $((cluster>>16)) "$1" 16 1.63 @@ -453,7 +467,11 @@ 1.64 for (i=1;i<=pos;i+=2) { 1.65 if (c[i]=="") c[i]=0 1.66 if (c[i+1]=="") c[i+1]=0 1.67 - if (fat==12) printf "0 %02X %1X%1X %02X |\n",c[i]%256,c[i+1]%16,(c[i]/256)%16,(c[i+1]/16)%256 1.68 + if (fat==12) { 1.69 + printf "0 %02X %1X%1X ",c[i]%256,c[i+1]%16,(c[i]/256)%16 1.70 + if (i<pos) printf "%02X ",(c[i+1]/16)%256 1.71 + print "|" 1.72 + } 1.73 else if (fat==16) printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,c[i+1]%256,(c[i+1]/256)%256 1.74 else { 1.75 printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,(c[i]/65536)%256,(c[i]/16777216)%256 1.76 @@ -480,34 +498,36 @@ 1.77 return 1.78 fi 1.79 local fclust=$({ 1.80 - [ -d $basedir/efi ] && 1.81 - find $basedir/efi -type f -exec busybox stat -c "%s %n" {} \; 1.82 + [ -d $basedir/efi ] && find $basedir/EFI -type f -exec \ 1.83 + busybox stat -c "%s %n" {} \; | grep -v $efi_img 1.84 while [ -s "$1" ]; do 1.85 local efifile 1.86 case "$1" in 1.87 *taz) efifile=bootia32.efi ;; 1.88 *taz64) efifile=bootx64.efi ;; 1.89 esac 1.90 - if [ ! -s $basedir/efi/boot/$efifile ] && 1.91 + if [ ! -s $basedir/EFI/boot/$efifile ] && 1.92 [ $(get $((0x82)) "$1") = $((0x4550)) ]; then 1.93 - mkdir -p $basedir/efi/boot 2> /dev/null 1.94 - ln "$1" "$basedir/efi/boot/$efifile" 1.95 + mkdir -p $basedir/EFI/boot 2> /dev/null 1.96 + ln "$1" "$basedir/EFI/boot/$efifile" 1.97 stat -c "%s %n" "$1" 1.98 for i in $basedir/boot/rootfs* ; do 1.99 - ln "$i" $basedir/efi/boot/ && 1.100 + ln "$i" $basedir/EFI/boot/ && 1.101 stat -c "%s %n" "$i" 1.102 done 2> /dev/null 1.103 - [ -s $basedir/efi/boot/linux.cmdline ] || 1.104 - sed 's|/|\\|g' > $basedir/efi/boot/linux.cmdline <<EOT 1.105 + if [ ! -s $basedir/EFI/boot/linux.cmdline ]; then 1.106 + sed 's|/|\\|g' > $basedir/EFI/boot/linux.cmdline <<EOT 1.107 rw root=0x100$(sed '/bzImage/!d;s|.*root=[^ ]*||;q' $basedir/boot/isolinux/isolinux.cfg)\ 1.108 -$( ( cd $basedir/efi/boot ; ls -r rootfs*gz ) | while read f ; do \ 1.109 -echo -n " initrd=/EFI/BOOT/$f";done) 1.110 +$( ( cd $basedir/EFI/boot ; ls -r rootfs*gz ) | while read f ; do \ 1.111 +echo -n " initrd=/EFI/boot/$f";done) 1.112 EOT 1.113 + stat -c "%s %n" $basedir/EFI/boot/linux.cmdline 1.114 + fi 1.115 fi 1.116 shift 1.117 - done; } | sort | uniq | awk '{ n+=int(($1+2047)/2048) } END { print n+1 }') 1.118 + done; } | sort | uniq | awk '{ n+=int(($1+2047)/2048) } END { print n }') 1.119 [ ${fclust:-0} -eq 0 ] && return 1.120 - local dclust=$( (cd $basedir; find efi -type d 2>/dev/null) | awk ' 1.121 + local dclust=$( (cd $basedir; find EFI -type d 2>/dev/null) | awk ' 1.122 BEGIN { 1.123 FS="/" 1.124 } 1.125 @@ -602,13 +622,13 @@ 1.126 seek=$((rsect+fsect+fsect)) 2> /dev/null 1.127 1.128 mkdir -p /tmp/mnt$$ 1.129 - mount -o loop $basedir/$efi_img /tmp/mnt$$ 1.130 - ( cd $basedir; find efi -type d | cpio -o -H newc ) | \ 1.131 + mount -o loop -t vfat $basedir/$efi_img /tmp/mnt$$ 1.132 + ( cd $basedir; find EFI -type d | cpio -o -H newc ) | \ 1.133 ( cd /tmp/mnt$$ ; cpio -idmu 2> /dev/null ) 1.134 sync 1.135 dd if=$basedir/$efi_img of=/tmp/fat$$ \ 1.136 skip=$rsect bs=512 count=$fsect 2> /dev/null 1.137 - ( cd $basedir; find efi/boot -type f | cpio -o -H newc ) | \ 1.138 + ( cd $basedir; find EFI -type f | grep -v $efi_img | cpio -o -H newc ) | \ 1.139 ( cd /tmp/mnt$$ ; cpio -idmu 2> /dev/null ) 1.140 umount /tmp/mnt$$ 1.141 cat /tmp/fat$$ /tmp/fat$$ | dd of=$basedir/$efi_img \ 1.142 @@ -657,8 +677,10 @@ 1.143 $PWD/boot/isolinux/c32box.c32 1.144 $PWD/boot/isolinux/kbd 1.145 $PWD/$efi_img 1.146 +$(find $PWD/$efi_img $PWD/EFI/ -type f 2> /dev/null | grep -v $PWD/EFI/boot/bzImage | \ 1.147 +grep -v $PWD/EFI/boot/rootfs | grep -v $PWD/EFI/boot/linux.cmdline) 1.148 $PWD/boot/bzImage* 1.149 -$PWD/efi/boot/linux.cmdline* 1.150 +$PWD/EFI/boot/linux.cmdline* 1.151 $(ls $PWD/boot/rootfs* | tac) 1.152 EOT 1.153 1.154 @@ -1300,23 +1322,23 @@ 1.155 } 1.156 1.157 1.158 -# Remove duplicated files in $1/efi/boot from $1/boot 1.159 +# Remove duplicated files in $1/EFI/boot from $1/boot 1.160 1.161 cleanup_efi_boot() { 1.162 for i in $1/$efi_img $1/boot/isolinux/efi.img ; do 1.163 [ -s $i ] && [ ! -x $i ] && rm -f $i 1.164 done 1.165 - for i in $1/efi/boot/* ; do 1.166 + for i in $1/EFI/boot/* ; do 1.167 [ -f $i ] || continue 1.168 case "$i" in 1.169 - */rootfs*) cmp $i ${i/\/efi\//\/} || continue ;; 1.170 + */rootfs*) cmp $i ${i/\/EFI\//\/} || continue ;; 1.171 */bootia32.efi) cmp $i $1/boot/bzImage || continue 1.172 - rm $1/efi/boot/linux.cmdline ;; 1.173 + rm $1/EFI/boot/linux.cmdline ;; 1.174 */bootx64.efi) cmp $i $1/boot/bzImage64 || continue 1.175 - rm $1/efi/boot/linux.cmdline* ;; 1.176 + rm $1/EFI/boot/linux.cmdline* ;; 1.177 esac 1.178 rm -f $i 1.179 - rmdir $1/efi/boot && rmdir $1/efi 1.180 + rmdir $1/EFI/boot && rmdir $1/EFI 1.181 done 2> /dev/null 1.182 } 1.183 1.184 @@ -2652,7 +2674,7 @@ 1.185 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs*.gz | awk 'END { print $1 }') 1.186 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum 1.187 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs 1.188 - [ -d $TMP_DIR/rootcd/efi ] && mv $TMP_DIR/rootcd/efi $TMP_DIR/rootfs 1.189 + [ -d $TMP_DIR/rootcd/EFI ] && mv $TMP_DIR/rootcd/EFI $TMP_DIR/rootfs 1.190 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \ 1.191 < $TMP_DIR/rootfs$INSTALLED.md5 1.192 PKGCNT=$(grep -cv ^# $TMP_DIR/$FLAVOR.pkglist) 1.193 @@ -2668,7 +2690,7 @@ 1.194 else 1.195 find_flavor_rootfs $TMP_DIR/rootfs 1.196 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd 1.197 - [ -d $TMP_DIR/rootfs/efi ] && mv $TMP_DIR/rootfs/efi $TMP_DIR/rootcd 1.198 + [ -d $TMP_DIR/rootfs/EFI ] && mv $TMP_DIR/rootfs/EFI $TMP_DIR/rootcd 1.199 for i in rootfs rootcd ; do 1.200 [ "$(ls $TMP_DIR/$i)" ] && 1.201 ( cd "$TMP_DIR/$i"; find * | cpio -o -H newc ) | dogzip "$TMP_DIR/$FLAVOR.$i" 1.202 @@ -2836,10 +2858,10 @@ 1.203 status 1.204 1.205 # Move the boot dir with the Linux kernel from rootfs. 1.206 - # The efi & boot dirs go directly on the CD. 1.207 - if [ -d "$ROOTFS/efi" ] ; then 1.208 - action 'Moving the efi directory...' 1.209 - mv $ROOTFS/efi $ROOTCD 1.210 + # The EFI & boot dirs go directly on the CD. 1.211 + if [ -d "$ROOTFS/EFI" ] ; then 1.212 + action 'Moving the EFI directory...' 1.213 + mv $ROOTFS/EFI $ROOTCD 1.214 status 1.215 fi 1.216 if [ -d "$ROOTFS/boot" ] ; then