mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-12-06 07:44:26 +01:00
haos-vm/homeassistant: pick VM CPU model from host flags and warn without AVX2 (#19300)
This commit is contained in:
1 parent
a129061bf3
commit
2967e31778
2 files changed
+69
-2
No files matched your search
@@ -21,6 +21,10 @@ variables
|
||||
color
|
||||
catch_errors
|
||||
|
||||
if [[ "$(arch_resolve)" == "amd64" ]] && ! grep -qw avx2 /proc/cpuinfo; then
|
||||
msg_warn "The host CPU does not support AVX2. Home Assistant works without it, but some add-ons (e.g. Music Assistant) require AVX2 and will not run."
|
||||
fi
|
||||
|
||||
function update_script() {
|
||||
header_info
|
||||
check_container_storage
|
||||
|
||||
+65
-2
@@ -43,6 +43,45 @@ trap 'post_update_to_api "failed" "129"; exit 129' SIGHUP
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
pushd $TEMP_DIR >/dev/null
|
||||
|
||||
function host_supports_cpu_model() {
|
||||
local flags f need=()
|
||||
flags=" $(grep -m1 '^flags' /proc/cpuinfo | cut -d: -f2) "
|
||||
local v2=(cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3)
|
||||
local v3=(avx avx2 bmi1 bmi2 f16c fma abm movbe xsave)
|
||||
local v4=(avx512f avx512bw avx512cd avx512dq avx512vl)
|
||||
case "$1" in
|
||||
"" | host | kvm64) return 0 ;;
|
||||
x86-64-v2) need=("${v2[@]}") ;;
|
||||
x86-64-v2-AES) need=("${v2[@]}" aes) ;;
|
||||
x86-64-v3) need=("${v2[@]}" "${v3[@]}") ;;
|
||||
x86-64-v4) need=("${v2[@]}" "${v3[@]}" "${v4[@]}") ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
for f in "${need[@]}"; do
|
||||
[[ "$flags" == *" $f "* ]] || return 1
|
||||
done
|
||||
}
|
||||
|
||||
function detect_cpu_model() {
|
||||
local model
|
||||
for model in x86-64-v3 x86-64-v2-AES x86-64-v2; do
|
||||
if host_supports_cpu_model "$model"; then
|
||||
echo "$model"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function check_cpu_model() {
|
||||
[[ "$(vm_arch)" == "amd64" ]] || return 0
|
||||
local model="${CPU_TYPE# -cpu }" best
|
||||
if ! host_supports_cpu_model "$model"; then
|
||||
best="$(detect_cpu_model)"
|
||||
msg_error "The host CPU ($(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs)) does not support the ${model} CPU model. Choose host, ${best:-kvm64} or a lower model."
|
||||
exit 106
|
||||
fi
|
||||
}
|
||||
|
||||
function default_settings() {
|
||||
BRANCH="$stable"
|
||||
var_version="${BRANCH}"
|
||||
@@ -51,7 +90,8 @@ function default_settings() {
|
||||
DISK_SIZE="32G"
|
||||
DISK_CACHE=""
|
||||
HN="homeassistant"
|
||||
CPU_TYPE=""
|
||||
CPU_MODEL="$(detect_cpu_model)"
|
||||
CPU_TYPE="${CPU_MODEL:+ -cpu $CPU_MODEL}"
|
||||
CORE_COUNT="2"
|
||||
RAM_SIZE="4096"
|
||||
BRG="vmbr0"
|
||||
@@ -81,7 +121,7 @@ function advanced_settings() {
|
||||
vm_prompt_disk_size "$DISK_SIZE" "Set Disk Size in GiB (e.g., 10, 20)"
|
||||
vm_prompt_disk_cache "writethrough"
|
||||
vm_prompt_hostname "homeassistant"
|
||||
vm_prompt_cpu_model "kvm64"
|
||||
vm_prompt_cpu_model "$(detect_cpu_model)"
|
||||
vm_prompt_cpu_cores "2"
|
||||
vm_prompt_ram "4096"
|
||||
vm_prompt_bridge "vmbr0"
|
||||
@@ -100,9 +140,32 @@ function advanced_settings() {
|
||||
fi
|
||||
}
|
||||
|
||||
function check_avx2() {
|
||||
[[ "$(vm_arch)" == "amd64" ]] || return 0
|
||||
local reason
|
||||
if ! grep -qw avx2 /proc/cpuinfo; then
|
||||
reason="The host CPU ($(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs)) does not support AVX2."
|
||||
else
|
||||
case "${CPU_TYPE# -cpu }" in
|
||||
host | x86-64-v3 | x86-64-v4) return 0 ;;
|
||||
*) reason="The CPU model $(vm_cpu_model_label) hides AVX2 from the VM. Select host (or x86-64-v3 if the host supports it) to pass it through." ;;
|
||||
esac
|
||||
fi
|
||||
msg_warn "${reason} Home Assistant OS works without AVX2, but some add-ons (e.g. Music Assistant) require it and will not run."
|
||||
[[ "${VM_UNATTENDED:-0}" == "1" ]] && return 0
|
||||
if ! vm_dialog yesno "NO AVX2" "${reason}
|
||||
|
||||
Home Assistant OS works without AVX2, but some add-ons (e.g. Music Assistant) require it and will not run.
|
||||
|
||||
Continue anyway?" 15 68; then
|
||||
exit_script "Aborted: no AVX2 available to the VM"
|
||||
fi
|
||||
}
|
||||
|
||||
vm_preflight
|
||||
vm_start_script "Use Default Settings?" 10 58
|
||||
check_cpu_model
|
||||
check_avx2
|
||||
post_to_api_vm
|
||||
|
||||
vm_select_storage "$HN"
|
||||
|
||||
Reference in new issue
Block a user