Compare commits

..

9 Commits

3 changed files with 131 additions and 44 deletions

View File

@ -1477,69 +1477,161 @@ getPartitions() {
parts=$(lsblk -I 3,8,9,179,202,253,259 -lpno KNAME,TYPE $disk | awk '{if ($2 ~ /part/ || $2 ~ /md/) print $1}' | sort -V | uniq)
}
normalize() {
echo "$1" | xargs | tr '[:upper:]' '[:lower:]'
local input="$*"
# If no arguments, read from stdin
if [[ -z "$input" ]]; then
input=$(cat)
fi
echo $(trim "$input" | xargs | tr '[:upper:]' '[:lower:]')
}
resolve_path() {
local input="$*"
# If no arguments, read from stdin
if [[ -z "$input" ]]; then
input=$(cat)
fi
echo $(readlink -f "$input" 2>/dev/null || echo "$input")
}
# Gets the hard drive on the host
# Note: This function makes a best guess
getHardDisk() {
hd=""
disks=""
local devs=$(lsblk -dpno KNAME,SIZE -I 3,8,9,179,202,253,259 | awk '$2 != "0B" { print $1 }' | sort -uV)
# Get valid devices (filter out 0B disks) once, keeping lsblk enumeration order
local devs
devs=$(lsblk -dpno KNAME,SIZE -I 3,8,9,179,202,253,259 | awk '$2 != "0B" && !seen[$1]++ { print $1 }')
if [[ -n $fdrive ]]; then
found_match=0
for spec in $(echo "$fdrive" | tr "," "\n"); do
local found_match=0
for spec in ${fdrive//,/ }; do
local spec_resolved spec_norm spec_normalized matched
spec_resolved=$(resolve_path "$spec")
spec_normalized=$(normalize "$spec")
matched=0
for dev in $devs; do
dev_trimmed=$(echo "$dev" | xargs)
spec_lc=$(normalize "$spec")
size=$(blockdev --getsize64 "$dev_trimmed" 2>/dev/null | normalize)
uuid=$(blkid -s UUID -o value "$dev_trimmed" 2>/dev/null | normalize)
read -r serial wwn <<< "$(lsblk -pdno SERIAL,WWN "$dev_trimmed" 2>/dev/null | normalize)"
if [[ -n $isdebug ]]; then
echo "Comparing spec='$spec_lc' with:"
echo " dev=$dev"
echo " size=$size"
echo " serial=$serial"
echo " wwn=$wwn"
echo " uuid=$uuid"
fi
if [[ "x$spec" = "x$dev_trimmed" ||
"x$spec_lc" = "x$(trim $(blockdev --getsize64 "$dev_trimmed"))" ||
"x$spec_lc" = "x$wwn" ||
"x$spec_lc" = "x$serial" ||
"x$spec_lc" = "x$uuid" ]]; then
local size uuid serial wwn
size=$(blockdev --getsize64 "$dev" | normalize)
uuid=$(blkid -s UUID -o value "$dev" 2>/dev/null | normalize)
# Grab SERIAL and WWN safely (handles blanks and spacing)
local kv serial_raw wwn_raw
kv="$(lsblk -pdPno SERIAL,WWN "$dev" 2>/dev/null)" || kv=""
serial_raw="$(sed -n 's/.*SERIAL="\([^"]*\)".*/\1/p' <<<"$kv")"
wwn_raw="$(sed -n 's/.*WWN="\([^"]*\)".*/\1/p' <<<"$kv")"
serial="$(normalize "$serial_raw")"
wwn="$(normalize "$wwn_raw")"
[[ -n $isdebug ]] && {
echo "Comparing spec='$spec' (resolved: '$spec_resolved') with dev=$dev"
echo " size=$size serial=$serial wwn=$wwn uuid=$uuid"
}
if [[ "x$spec_resolved" == "x$dev" || \
"x$spec_normalized" == "x$size" || \
"x$spec_normalized" == "x$wwn" || \
"x$spec_normalized" == "x$serial" || \
"x$spec_normalized" == "x$uuid" ]]; then
[[ -n $isdebug ]] && echo "Matched spec '$spec' to device '$dev' (size=$size, serial=$serial, wwn=$wwn, uuid=$uuid)"
matched=1
found_match=1
disks="${disks} $dev"
# Remove matched dev from devs to avoid duplicates
escaped_dev=$(echo "$dev" | sed -e 's/[]"$&*.^|[]/\\&/g')
devs=$(echo "$devs" | sed "s/[[:space:]]*${escaped_dev}[[:space:]]*/ /")
disks="$disks $dev"
# remove matched dev from the pool
devs="$(echo " $devs " | sed "s# $dev # #g; s/^ *//; s/ *$//")"
break
fi
done
if [[ $matched -eq 0 ]]; then
echo "WARNING: Drive spec '$spec' does not match any available device. Ignoring." >&2
fi
[[ $matched -eq 0 ]] && echo "WARNING: Drive spec '$spec' does not match any available device." >&2
done
if [[ $found_match -eq 0 ]]; then
handleError "Fatal Error: No valid drives found from 'Host Primary Disk'='$fdrive'. Please ensure the device exists and is not 0 bytes. ($0)"
fi
[[ $found_match -eq 0 ]] && handleError "Fatal: No valid drives found for 'Host Primary Disk'='$fdrive'."
disks=$(echo "${disks} ${devs}" | xargs)
elif [[ -r ${imagePath}/d1.size && -r ${imagePath}/d2.size ]]; then
disks=$(echo "$devs")
disks=$(echo "$disks $devs" | xargs) # add unmatched devices for completeness
elif [[ "x$imgType" == "xmpa" ]]; then
# Multi-disk image: keep enumeration order
disks="$devs"
if [[ "x$type" == "xdown" ]]; then
# Expected disk sizes from image (d1.size, d2.size, ...)
local sizefiles expected_sizes=()
sizefiles=$(ls -1 "${imagePath}"/d*.size 2>/dev/null | sort -V)
if [[ -n "$sizefiles" ]]; then
local f exp
for f in $sizefiles; do
# file format: d1: 123456789
exp="$(awk -F: '{gsub(/[[:space:]]/,"",$2); print $2}' "$f")"
[[ -n "$exp" ]] && expected_sizes+=("$exp")
done
# Actual disks (keep lsblk order)
local actual_disks=()
for d in $devs; do actual_disks+=("$d"); done
# Build mapping in d1,d2,... order
local mapped=() used=" "
local i match candidates
for i in "${!expected_sizes[@]}"; do
exp="${expected_sizes[$i]}"
match=""
candidates=0
# Exact match pass
for d in "${actual_disks[@]}"; do
[[ "$used" == *" $d "* ]] && continue
if [[ "$(blockdev --getsize64 "$d" 2>/dev/null)" == "$exp" ]]; then
match="$d"
candidates=$((candidates+1))
fi
done
if [[ $candidates -eq 1 ]]; then
mapped+=("$match")
used+=" $match "
continue
fi
# Ambiguous or missing -> warn and fall back
echo "WARNING: Could not uniquely match disk for expected size $exp (found $candidates exact matches). Falling back to enumeration order." >&2
mapped=()
break
done
if [[ ${#mapped[@]} -gt 0 ]]; then
disks="${mapped[*]}"
hd="${mapped[0]}"
return 0
fi
fi
fi
else
# Auto-select the largest available drive if no fdrive and no imagePath match
hd=$(echo "$devs" | while read line; do echo "$(blockdev --getsize64 "$line") $line"; done | sort -n | tail -1 | cut -d' ' -f2)
[[ -z $hd ]] && handleError "Could not determine a suitable disk automatically. No drives available? ($0)"
if [[ -n $largesize ]]; then
# Auto-select largest available drive
hd=$(
for d in $devs; do
echo "$(blockdev --getsize64 "$d") $d"
done | sort -k1,1nr -k2,2 | head -1 | cut -d' ' -f2
)
else
for d in $devs; do
hd="$d"
break
done
fi
[[ -z $hd ]] && handleError "Could not determine a suitable disk automatically."
disks="$hd"
fi
# Set primary hard disk
hd=$(echo "$disks" | awk '{print $1}')
hd=$(awk '{print $1}' <<< "$disks")
}
# Finds the hard drive info and set's up the type
findHDDInfo() {
dots "Looking for Hard Disk(s)"

View File

@ -453,7 +453,6 @@ CONFIG_MITIGATION_SPECTRE_V1=y
CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SRBDS=y
CONFIG_MITIGATION_SSB=y
CONFIG_MITIGATION_ITS=y
CONFIG_ARCH_HAS_ADD_PAGES=y
#
@ -3861,8 +3860,6 @@ CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity,bpf"
# Memory initialization
#
CONFIG_INIT_STACK_NONE=y
# CONFIG_INIT_STACK_ALL_PATTERN is not set
# CONFIG_INIT_STACK_ALL_ZERO is not set
# CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not set
# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set
CONFIG_CC_HAS_ZERO_CALL_USED_REGS=y

View File

@ -3794,8 +3794,6 @@ CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity,bpf"
# Memory initialization
#
CONFIG_INIT_STACK_NONE=y
# CONFIG_INIT_STACK_ALL_PATTERN is not set
# CONFIG_INIT_STACK_ALL_ZERO is not set
# CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not set
# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set
CONFIG_CC_HAS_ZERO_CALL_USED_REGS=y