mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-25 17:06:26 +00:00
update switch_gpu_mode.sh
This commit is contained in:
@@ -413,9 +413,7 @@ ensure_selected_gpu_not_already_in_target_vm() {
|
||||
local pci label
|
||||
pci="${ALL_GPU_PCIS[$i]}"
|
||||
_is_pci_slot_assigned_to_vm "$pci" "$SELECTED_VMID" && continue
|
||||
label="${ALL_GPU_NAMES[$i]}"
|
||||
[[ "${ALL_GPU_DRIVERS[$i]}" == "vfio-pci" ]] && label+=" [VFIO]"
|
||||
label+=" — ${pci}"
|
||||
label="${ALL_GPU_NAMES[$i]} [${ALL_GPU_DRIVERS[$i]}] — ${pci}"
|
||||
menu_items+=("$i" "$label")
|
||||
available=$((available + 1))
|
||||
done
|
||||
@@ -429,12 +427,21 @@ ensure_selected_gpu_not_already_in_target_vm() {
|
||||
fi
|
||||
|
||||
local choice
|
||||
choice=$(dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate 'GPU Already Assigned to This VM')" \
|
||||
--menu "\n$(translate 'The selected GPU is already present in this VM. Select another GPU to continue:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
2>&1 >/dev/tty) || exit 0
|
||||
if [[ "$WIZARD_CALL" == "true" ]]; then
|
||||
choice=$(whiptail --backtitle "ProxMenux" \
|
||||
--title "$(translate 'GPU Already Assigned to This VM')" \
|
||||
--menu "\n$(translate 'The selected GPU is already present in this VM. Select another GPU to continue:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
3>&1 1>&2 2>&3) || exit 0
|
||||
else
|
||||
choice=$(dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate 'GPU Already Assigned to This VM')" \
|
||||
--menu "\n$(translate 'The selected GPU is already present in this VM. Select another GPU to continue:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
2>&1 >/dev/tty) || exit 0
|
||||
fi
|
||||
|
||||
SELECTED_GPU="${ALL_GPU_TYPES[$choice]}"
|
||||
SELECTED_GPU_PCI="${ALL_GPU_PCIS[$choice]}"
|
||||
@@ -448,12 +455,16 @@ ensure_selected_gpu_not_already_in_target_vm() {
|
||||
# ==========================================================
|
||||
detect_host_gpus() {
|
||||
while IFS= read -r line; do
|
||||
local pci_short pci_full name type driver
|
||||
local pci_short pci_full name type driver pci_info
|
||||
pci_short=$(echo "$line" | awk '{print $1}')
|
||||
pci_full="0000:${pci_short}"
|
||||
|
||||
# Human-readable name: between first ":" and first "["
|
||||
name=$(echo "$line" | sed 's/^[^:]*[^:]: //' | sed 's/ \[.*//' | cut -c1-62)
|
||||
# Prefer full vendor/model descriptor for clearer menus.
|
||||
pci_info=$(lspci -nn -s "${pci_short}" 2>/dev/null | sed 's/^[^ ]* //')
|
||||
name="${pci_info#*: }"
|
||||
[[ "$name" == "$pci_info" ]] && name="$pci_info"
|
||||
name=$(echo "$name" | sed -E 's/ \(rev [^)]+\)$//' | cut -c1-72)
|
||||
[[ -z "$name" ]] && name="$(translate 'Unknown GPU')"
|
||||
|
||||
if echo "$line" | grep -qi "Intel"; then
|
||||
type="intel"
|
||||
@@ -614,19 +625,26 @@ select_gpu() {
|
||||
local menu_items=()
|
||||
local i
|
||||
for i in "${!ALL_GPU_PCIS[@]}"; do
|
||||
local label="${ALL_GPU_NAMES[$i]}"
|
||||
[[ "${ALL_GPU_DRIVERS[$i]}" == "vfio-pci" ]] && label+=" [VFIO]"
|
||||
label+=" — ${ALL_GPU_PCIS[$i]}"
|
||||
local label="${ALL_GPU_NAMES[$i]} [${ALL_GPU_DRIVERS[$i]}] — ${ALL_GPU_PCIS[$i]}"
|
||||
menu_items+=("$i" "$label")
|
||||
done
|
||||
|
||||
local choice
|
||||
choice=$(dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate 'Select GPU for VM Passthrough')" \
|
||||
--menu "\n$(translate 'Select the GPU to pass through to the VM:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
2>&1 >/dev/tty) || exit 0
|
||||
if [[ "$WIZARD_CALL" == "true" ]]; then
|
||||
choice=$(whiptail --backtitle "ProxMenux" \
|
||||
--title "$(translate 'Select GPU for VM Passthrough')" \
|
||||
--menu "\n$(translate 'Select the GPU to pass through to the VM:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
3>&1 1>&2 2>&3) || exit 0
|
||||
else
|
||||
choice=$(dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate 'Select GPU for VM Passthrough')" \
|
||||
--menu "\n$(translate 'Select the GPU to pass through to the VM:')" \
|
||||
18 82 10 \
|
||||
"${menu_items[@]}" \
|
||||
2>&1 >/dev/tty) || exit 0
|
||||
fi
|
||||
|
||||
SELECTED_GPU="${ALL_GPU_TYPES[$choice]}"
|
||||
SELECTED_GPU_PCI="${ALL_GPU_PCIS[$choice]}"
|
||||
|
||||
@@ -404,10 +404,14 @@ detect_host_gpus() {
|
||||
ALL_GPU_VIDDID=()
|
||||
|
||||
while IFS= read -r line; do
|
||||
local pci_short pci_full name type driver viddid
|
||||
local pci_short pci_full name type driver viddid pci_info
|
||||
pci_short=$(echo "$line" | awk '{print $1}')
|
||||
pci_full="0000:${pci_short}"
|
||||
name=$(echo "$line" | sed 's/^[^:]*[^:]: //' | sed 's/ \[.*//' | cut -c1-62)
|
||||
pci_info=$(lspci -nn -s "${pci_short}" 2>/dev/null | sed 's/^[^ ]* //')
|
||||
name="${pci_info#*: }"
|
||||
[[ "$name" == "$pci_info" ]] && name="$pci_info"
|
||||
name=$(echo "$name" | sed -E 's/ \(rev [^)]+\)$//' | cut -c1-72)
|
||||
[[ -z "$name" ]] && name="$(translate 'Unknown GPU')"
|
||||
if echo "$line" | grep -qi "Intel"; then
|
||||
type="intel"
|
||||
elif echo "$line" | grep -qiE "AMD|Advanced Micro|Radeon"; then
|
||||
|
||||
@@ -262,15 +262,7 @@ select_controller_nvme() {
|
||||
|
||||
if [[ ${#blocked_reasons[@]} -gt 0 ]]; then
|
||||
blocked_count=$((blocked_count + 1))
|
||||
blocked_report+="------------------------------------------------------------\n"
|
||||
blocked_report+="PCI: ${pci_full}\n"
|
||||
blocked_report+="Name: ${name}\n"
|
||||
blocked_report+="$(translate "Blocked because protected or in-use disks are attached"):\n"
|
||||
local reason
|
||||
for reason in "${blocked_reasons[@]}"; do
|
||||
blocked_report+=" - ${reason}\n"
|
||||
done
|
||||
blocked_report+="\n"
|
||||
blocked_report+=" • ${pci_full} — $(_shorten_text "$name" 56)\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -282,12 +274,7 @@ select_controller_nvme() {
|
||||
assigned_suffix=" | $(translate "Assigned to VM")"
|
||||
fi
|
||||
|
||||
if [[ ${#controller_disks[@]} -gt 0 ]]; then
|
||||
controller_desc="$(printf "%-42s [%s: %d]" "$short_name" "$(translate "attached disks")" "${#controller_disks[@]}")"
|
||||
else
|
||||
controller_desc="$(printf "%-42s [%s]" "$short_name" "$(translate "No attached disks")")"
|
||||
fi
|
||||
controller_desc+="${assigned_suffix}"
|
||||
controller_desc="${short_name}${assigned_suffix}"
|
||||
|
||||
state="off"
|
||||
menu_items+=("$pci_full" "$controller_desc" "$state")
|
||||
@@ -299,10 +286,10 @@ select_controller_nvme() {
|
||||
if [[ "$hidden_target_count" -gt 0 && "$blocked_count" -eq 0 ]]; then
|
||||
msg="$(translate "All detected controllers/NVMe are already present in the selected VM.")\n\n$(translate "No additional device needs to be added.")"
|
||||
else
|
||||
msg="$(translate "No safe controllers/NVMe devices are available for passthrough.")\n\n"
|
||||
msg="$(translate "No available Controllers/NVMe devices were found.")\n\n"
|
||||
fi
|
||||
if [[ "$blocked_count" -gt 0 ]]; then
|
||||
msg+="$(translate "Detected controllers blocked for safety:")\n\n${blocked_report}"
|
||||
msg+="$(translate "Hidden for safety"):\n${blocked_report}"
|
||||
fi
|
||||
dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate "Controller + NVMe")" \
|
||||
@@ -310,16 +297,10 @@ select_controller_nvme() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "$blocked_count" -gt 0 ]]; then
|
||||
dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate "Controller + NVMe")" \
|
||||
--msgbox "$(translate "Some controllers were hidden because they have host system disks attached.")\n\n${blocked_report}" 22 100
|
||||
fi
|
||||
|
||||
local raw selected
|
||||
raw=$(dialog --backtitle "ProxMenux" \
|
||||
--title "$(translate "Controller + NVMe")" \
|
||||
--checklist "\n$(translate "Select controllers/NVMe to passthrough (safe devices only):")\n\n$(translate "Only safe devices are shown in this list.")" 20 96 12 \
|
||||
--checklist "\n$(translate "Select available Controllers/NVMe to add:")" 20 96 12 \
|
||||
"${menu_items[@]}" \
|
||||
2>&1 >/dev/tty) || return 1
|
||||
|
||||
|
||||
@@ -325,15 +325,7 @@ function select_controller_nvme() {
|
||||
|
||||
if [[ ${#blocked_reasons[@]} -gt 0 ]]; then
|
||||
blocked_count=$((blocked_count + 1))
|
||||
blocked_report+="------------------------------------------------------------\n"
|
||||
blocked_report+="PCI: ${pci_full}\n"
|
||||
blocked_report+="Name: ${name}\n"
|
||||
blocked_report+="$(translate "Blocked because protected/in-use disks are attached"):\n"
|
||||
local reason
|
||||
for reason in "${blocked_reasons[@]}"; do
|
||||
blocked_report+=" - ${reason}\n"
|
||||
done
|
||||
blocked_report+="\n"
|
||||
blocked_report+=" • ${pci_full} — $(_shorten_text "$name" 56)\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -345,12 +337,7 @@ function select_controller_nvme() {
|
||||
assigned_suffix=" | $(translate "Assigned to VM")"
|
||||
fi
|
||||
|
||||
if [[ ${#controller_disks[@]} -gt 0 ]]; then
|
||||
controller_desc="$(printf "%-42s [%s: %d]" "$short_name" "$(translate "attached disks")" "${#controller_disks[@]}")"
|
||||
else
|
||||
controller_desc="$(printf "%-42s [%s]" "$short_name" "$(translate "No attached disks")")"
|
||||
fi
|
||||
controller_desc+="${assigned_suffix}"
|
||||
controller_desc="${short_name}${assigned_suffix}"
|
||||
|
||||
if _array_contains "$pci_full" "${CONTROLLER_NVME_PCIS[@]}"; then
|
||||
state="ON"
|
||||
@@ -368,22 +355,18 @@ function select_controller_nvme() {
|
||||
if [[ "$hidden_target_count" -gt 0 && "$blocked_count" -eq 0 ]]; then
|
||||
msg="$(translate "All detected controllers/NVMe are already present in the selected VM.")\n\n$(translate "No additional device needs to be added.")"
|
||||
else
|
||||
msg="$(translate "No safe controllers/NVMe devices are available for passthrough.")\n\n"
|
||||
msg="$(translate "No available Controllers/NVMe devices were found.")\n\n"
|
||||
fi
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
msg+="$(translate "Detected controllers blocked for safety:")\n\n${blocked_report}"
|
||||
msg+="$(translate "Hidden for safety"):\n${blocked_report}"
|
||||
fi
|
||||
whiptail --title "Controller + NVMe" --msgbox "$msg" 22 100
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
whiptail --title "Controller + NVMe" --msgbox "$(translate "Some controllers were hidden because they have host system disks attached.")\n\n${blocked_report}" 22 100
|
||||
fi
|
||||
|
||||
local selected
|
||||
selected=$(whiptail --title "Controller + NVMe" --checklist \
|
||||
"$(translate "Select controllers/NVMe to passthrough (safe devices only):")\n\n$(translate "Only safe devices are shown in this list.")" 20 96 10 \
|
||||
"$(translate "Select available Controllers/NVMe to add:")" 20 96 10 \
|
||||
"${menu_items[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
[[ $? -ne 0 ]] && return 1
|
||||
|
||||
@@ -676,15 +676,7 @@ function select_controller_nvme() {
|
||||
|
||||
if [[ ${#blocked_reasons[@]} -gt 0 ]]; then
|
||||
blocked_count=$((blocked_count + 1))
|
||||
blocked_report+="------------------------------------------------------------\n"
|
||||
blocked_report+="PCI: ${pci_full}\n"
|
||||
blocked_report+="Name: ${name}\n"
|
||||
blocked_report+="$(translate "Blocked because protected/in-use disks are attached"):\n"
|
||||
local reason
|
||||
for reason in "${blocked_reasons[@]}"; do
|
||||
blocked_report+=" - ${reason}\n"
|
||||
done
|
||||
blocked_report+="\n"
|
||||
blocked_report+=" • ${pci_full} — $(_shorten_text "$name" 56)\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -696,12 +688,7 @@ function select_controller_nvme() {
|
||||
assigned_suffix=" | $(translate "Assigned to VM")"
|
||||
fi
|
||||
|
||||
if [[ ${#controller_disks[@]} -gt 0 ]]; then
|
||||
controller_desc="$(printf "%-42s [%s: %d]" "$short_name" "$(translate "attached disks")" "${#controller_disks[@]}")"
|
||||
else
|
||||
controller_desc="$(printf "%-42s [%s]" "$short_name" "$(translate "No attached disks")")"
|
||||
fi
|
||||
controller_desc+="${assigned_suffix}"
|
||||
controller_desc="${short_name}${assigned_suffix}"
|
||||
|
||||
if _array_contains "$pci_full" "${CONTROLLER_NVME_PCIS[@]}"; then
|
||||
state="ON"
|
||||
@@ -719,19 +706,18 @@ function select_controller_nvme() {
|
||||
if [[ "$hidden_target_count" -gt 0 && "$blocked_count" -eq 0 ]]; then
|
||||
msg="$(translate "All detected controllers/NVMe are already present in the selected VM.")\n\n$(translate "No additional device needs to be added.")"
|
||||
else
|
||||
msg="$(translate "No safe controllers/NVMe devices are available for passthrough.")\n\n${blocked_report}"
|
||||
msg="$(translate "No available Controllers/NVMe devices were found.")\n\n"
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
msg+="$(translate "Hidden for safety"):\n${blocked_report}"
|
||||
fi
|
||||
fi
|
||||
whiptail --title "Controller + NVMe" --msgbox "$msg" 22 100
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
whiptail --title "Controller + NVMe" --msgbox "$(translate "Some controllers were hidden because they have host system disks attached.")\n\n${blocked_report}" 22 100
|
||||
fi
|
||||
|
||||
local selected
|
||||
selected=$(whiptail --title "Controller + NVMe" --checklist \
|
||||
"$(translate "Select controllers/NVMe to passthrough (safe devices only):")\n\n$(translate "Only safe devices are shown in this list.")" 20 96 10 \
|
||||
"$(translate "Select available Controllers/NVMe to add:")" 20 96 10 \
|
||||
"${menu_items[@]}" 3>&1 1>&2 2>&3) || return 1
|
||||
|
||||
CONTROLLER_NVME_PCIS=()
|
||||
|
||||
@@ -690,15 +690,7 @@ function select_controller_nvme() {
|
||||
|
||||
if [[ ${#blocked_reasons[@]} -gt 0 ]]; then
|
||||
blocked_count=$((blocked_count + 1))
|
||||
blocked_report+="------------------------------------------------------------\n"
|
||||
blocked_report+="PCI: ${pci_full}\n"
|
||||
blocked_report+="Name: ${name}\n"
|
||||
blocked_report+="$(translate "Blocked because protected/in-use disks are attached"):\n"
|
||||
local reason
|
||||
for reason in "${blocked_reasons[@]}"; do
|
||||
blocked_report+=" - ${reason}\n"
|
||||
done
|
||||
blocked_report+="\n"
|
||||
blocked_report+=" • ${pci_full} — $(_shorten_text "$name" 56)\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -710,12 +702,7 @@ function select_controller_nvme() {
|
||||
assigned_suffix=" | $(translate "Assigned to VM")"
|
||||
fi
|
||||
|
||||
if [[ ${#controller_disks[@]} -gt 0 ]]; then
|
||||
controller_desc="$(printf "%-42s [%s: %d]" "$short_name" "$(translate "attached disks")" "${#controller_disks[@]}")"
|
||||
else
|
||||
controller_desc="$(printf "%-42s [%s]" "$short_name" "$(translate "No attached disks")")"
|
||||
fi
|
||||
controller_desc+="${assigned_suffix}"
|
||||
controller_desc="${short_name}${assigned_suffix}"
|
||||
|
||||
if _array_contains "$pci_full" "${CONTROLLER_NVME_PCIS[@]}"; then
|
||||
state="ON"
|
||||
@@ -733,19 +720,18 @@ function select_controller_nvme() {
|
||||
if [[ "$hidden_target_count" -gt 0 && "$blocked_count" -eq 0 ]]; then
|
||||
msg="$(translate "All detected controllers/NVMe are already present in the selected VM.")\n\n$(translate "No additional device needs to be added.")"
|
||||
else
|
||||
msg="$(translate "No safe controllers/NVMe devices are available for passthrough.")\n\n${blocked_report}"
|
||||
msg="$(translate "No available Controllers/NVMe devices were found.")\n\n"
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
msg+="$(translate "Hidden for safety"):\n${blocked_report}"
|
||||
fi
|
||||
fi
|
||||
whiptail --title "Controller + NVMe" --msgbox "$msg" 22 100
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $blocked_count -gt 0 ]]; then
|
||||
whiptail --title "Controller + NVMe" --msgbox "$(translate "Some controllers were hidden because they have host system disks attached.")\n\n${blocked_report}" 22 100
|
||||
fi
|
||||
|
||||
local selected
|
||||
selected=$(whiptail --title "Controller + NVMe" --checklist \
|
||||
"$(translate "Select controllers/NVMe to passthrough (safe devices only):")\n\n$(translate "Only safe devices are shown in this list.")" 20 96 10 \
|
||||
"$(translate "Select available Controllers/NVMe to add:")" 20 96 10 \
|
||||
"${menu_items[@]}" 3>&1 1>&2 2>&3) || return 1
|
||||
|
||||
CONTROLLER_NVME_PCIS=()
|
||||
|
||||
Reference in New Issue
Block a user