Skip to content

Commit

Permalink
Fix arch iso boot issue (#2825 #2824)
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed May 12, 2024
1 parent ee7da60 commit 72f5710
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions IMG/cpio/ventoy/init_chain
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 72f5710

Please sign in to comment.