]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix arch iso boot issue (#2825 #2824)
authorlongpanda <admin@ventoy.net>
Sun, 12 May 2024 04:36:58 +0000 (12:36 +0800)
committerlongpanda <admin@ventoy.net>
Sun, 12 May 2024 04:36:58 +0000 (12:36 +0800)
IMG/cpio/ventoy/init_chain

index 7f78e538fcaf726a1b978f487a12520b802131d4..5a541cf47b5f66626cd09b55b6c6b593845dc0f7 100644 (file)
@@ -112,6 +112,28 @@ ventoy_unpack_initrd() {
     done    
 }
 
+vtfile_head_zero() {
+    local vsize
+    local voffset
+    local vfile
+    local vzero
+    local vdump
+    
+    voffset=0
+    vfile=$1
+    vsize=$(stat -c '%s' ${vfile})
+    vzero=$(hexdump -n 512 -e '512/1 "%02X"' $vfile)
+    
+    while [ $voffset -lt $vsize ]; do
+        vdump=$(hexdump -s $voffset -n 512 -e '512/1 "%02X"' $vfile)
+        if [ "$vdump" != "$vzero" ]; then
+            echo $voffset
+            return
+        fi
+        voffset=$($BUSYBOX_PATH/expr $voffset + 512)
+    done    
+    echo 0
+}
 
 # This export is for busybox cpio command
 export EXTRACT_UNSAFE_SYMLINKS=1
@@ -131,13 +153,22 @@ for vtfile in $(ls /initrd*); do
     #only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
     while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
         mv ${vtfile}_tmp $vtfile
+        
         vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
         vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
         let vtoffset="(${#vtdump}-${#vtmagic})/2"
         
         if [ -z "$vtmagic" ]; then
-            echo "terminate with all zero data file" >> $VTLOG
-            break
+            vtHeadZero=$(vtfile_head_zero $vtfile)
+            if [ $vtHeadZero -gt 0 ]; then
+                vtdump=$(hexdump -s $vtHeadZero -n 512 -e '512/1 "%02X"' $vtfile)
+                vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
+                let vtoffset="(${#vtdump}-${#vtmagic})/2+$vtHeadZero"                
+                echo "skip head $vtHeadZero zeros with magic ${vtmagic:0:4}" >> $VTLOG
+            else
+                echo "terminate with all zero data file" >> $VTLOG            
+                break
+            fi            
         fi
         
         ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp