Fix arch iso boot issue (#2825 #2824)

This commit is contained in:
longpanda 2024-05-12 12:36:58 +08:00
parent ee7da60d88
commit 72f5710b88

View 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,14 +153,23 @@ 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
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
done