Merge e13e4f764643b18e6d8256a0fade47e7df0019c0 into 2dafe755097057a4faf5e240f0abc98b9b4cdcb8

This commit is contained in:
Kristopher James Kent 2025-03-22 22:18:49 +00:00 committed by GitHub
commit 98a9009717
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 72 additions and 48 deletions

View File

@ -312,21 +312,17 @@ if [ "$MODE" = "install" -a -z "$NONDESTRUCTIVE" ]; then
#format part1 #format part1
wait_and_create_part ${PART1} ${PART2} wait_and_create_part ${PART1} ${PART2}
if [ -b ${PART1} ]; then
vtinfo "Format partition 1 ${PART1}..." vtinfo "Format partition 1 ${PART1}..."
mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1} mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "mkexfatfs failed, now retry..." vtwarn "mkexfatfs failed; retrying..."
mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1} mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "######### mkexfatfs failed, exit ########" vterr "######## mkexfatfs failed, exit ########"
exit 1 exit 1
fi fi
else else
echo "mkexfatfs success" vtinfo "mkexfatfs success"
fi
else
vterr "${PART1} NOT exist"
fi fi
vtinfo "writing data to disk ..." vtinfo "writing data to disk ..."

View File

@ -210,45 +210,73 @@ get_disk_ventoy_version() {
ventoy_false ventoy_false
} }
wait_and_create_part() { wait_for_blockdevs() {
vPART1=$1 attempts=3
vPART2=$2 delay=2
echo 'Wait for partitions $vPART1 and $vPART2 ...'
for i in 0 1 2 3 4 5 6 7 8 9; do vtdebug "wait_for_blockdevs called with the following arguments:"
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then for dev in "$@"; do
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then vtdebug ' - '"$dev"
done
i=
while [ $((i+=1)) -le $attempts ]; do
all_ready=0
echo "Waiting for block devices..."
for dev in "$@"; do
if ! [ -b "$dev" ]; then
vtwarn "$dev not found."
all_ready=1
break break
fi fi
else
echo "Wait for $vPART1 and $vPART2 ..."
sleep 1
fi
done done
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then if [ "$all_ready" -eq 0 ]; then
echo "$vPART1 exist OK" vtinfo "Block devices ready!"
else return
MajorMinor=$(sed "s/:/ /" /sys/class/block/${vPART1#/dev/}/dev)
echo "mknod -m 0660 $vPART1 b $MajorMinor ..."
mknod -m 0660 $vPART1 b $MajorMinor
fi fi
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then echo 'Refreshing kernel partition table'
echo "$vPART2 exist OK" partprobe
else
MajorMinor=$(sed "s/:/ /" /sys/class/block/${vPART2#/dev/}/dev)
echo "mknod -m 0660 $vPART2 b $MajorMinor ..."
mknod -m 0660 $vPART2 b $MajorMinor
fi
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then sleep "$delay"
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then done
echo "partition exist OK"
fi vterr "Required block devices not ready."
else return 1
echo "[FAIL] $vPART1/$vPART2 does not exist" }
wait_and_create_part() {
# Return immediately if devices found
wait_for_blockdevs "$@" && return
# Fallback: manually create fs nodes
echo "Attempting to create device nodes in /dev/"
for part in "$@"; do
# Skip if device found
[ -b $part ] && continue
MajorMinor=$(sed "s/:/ /" /sys/class/block/${part#/dev/}/dev)
echo ">> mknod -m 0660 $part b $MajorMinor..."
mknod -m 0660 $part b $MajorMinor
if [ "$?" -ne 0 ]; then
vterr 'Creating device node failed'
exit 1 exit 1
fi fi
done
partprobe
echo "Confirming partitions are now available..."
# Return if success
wait_for_blockdevs "$@" && return
# RIP
vterr 'Cannot proceed -- please check your device. Try re-plugging or using a different USB port or device.'
exit 1
} }