mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-08-15 01:12:22 +00:00
Update disk-passthrough.sh
This commit is contained in:
parent
1f0cf67eb8
commit
91cd4882e4
@ -42,6 +42,8 @@ initialize_cache
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Function to get detailed disk information
|
||||||
get_disk_info() {
|
get_disk_info() {
|
||||||
local disk=$1
|
local disk=$1
|
||||||
MODEL=$(lsblk -dn -o MODEL "$disk" | xargs)
|
MODEL=$(lsblk -dn -o MODEL "$disk" | xargs)
|
||||||
@ -50,13 +52,16 @@ get_disk_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Display list of available VMs
|
||||||
VM_LIST=$(qm list | awk 'NR>1 {print $1, $2}')
|
VM_LIST=$(qm list | awk 'NR>1 {print $1, $2}')
|
||||||
if [ -z "$VM_LIST" ]; then
|
if [ -z "$VM_LIST" ]; then
|
||||||
whiptail --title "$(translate "Error")" --msgbox "$(translate "No VMs available in the system.")" 8 40
|
whiptail --title "$(translate "Error")" --msgbox "$(translate "No VMs available in the system.")" 8 40
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Select VM
|
||||||
VMID=$(whiptail --title "$(translate "Select VM")" --menu "$(translate "Select the VM to which you want to add disks:")" 15 60 8 $VM_LIST 3>&1 1>&2 2>&3)
|
VMID=$(whiptail --title "$(translate "Select VM")" --menu "$(translate "Select the VM to which you want to add disks:")" 15 60 8 $VM_LIST 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
if [ -z "$VMID" ]; then
|
if [ -z "$VMID" ]; then
|
||||||
@ -67,6 +72,8 @@ fi
|
|||||||
VMID=$(echo "$VMID" | tr -d '"')
|
VMID=$(echo "$VMID" | tr -d '"')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#clear
|
||||||
msg_ok "$(translate "VM selected successfully.")"
|
msg_ok "$(translate "VM selected successfully.")"
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +89,7 @@ fi
|
|||||||
msg_info "$(translate "Detecting available disks...")"
|
msg_info "$(translate "Detecting available disks...")"
|
||||||
|
|
||||||
USED_DISKS=$(lsblk -n -o PKNAME,TYPE | grep 'lvm' | awk '{print "/dev/" $1}')
|
USED_DISKS=$(lsblk -n -o PKNAME,TYPE | grep 'lvm' | awk '{print "/dev/" $1}')
|
||||||
|
|
||||||
MOUNTED_DISKS=$(lsblk -ln -o NAME,MOUNTPOINT | awk '$2!="" {print "/dev/" $1}')
|
MOUNTED_DISKS=$(lsblk -ln -o NAME,MOUNTPOINT | awk '$2!="" {print "/dev/" $1}')
|
||||||
|
|
||||||
ZFS_DISKS=""
|
ZFS_DISKS=""
|
||||||
@ -138,11 +146,11 @@ is_disk_in_use() {
|
|||||||
|
|
||||||
FREE_DISKS=()
|
FREE_DISKS=()
|
||||||
|
|
||||||
LVM_DEVICES=$(pvs --noheadings -o pv_name 2> >(grep -v 'File descriptor .* leaked') | xargs -n1 readlink -f | sort -u)
|
LVM_DEVICES=$(pvs --noheadings -o pv_name | xargs -n1 readlink -f | sort -u)
|
||||||
RAID_ACTIVE=$(grep -Po 'md\d+\s*:\s*active\s+raid[0-9]+' /proc/mdstat | awk '{print $1}' | sort -u)
|
RAID_ACTIVE=$(grep -Po 'md\d+\s*:\s*active\s+raid[0-9]+' /proc/mdstat | awk '{print $1}' | sort -u)
|
||||||
|
|
||||||
while read -r DISK; do
|
while read -r DISK; do
|
||||||
|
# Saltar ZVOLs
|
||||||
[[ "$DISK" =~ /dev/zd ]] && continue
|
[[ "$DISK" =~ /dev/zd ]] && continue
|
||||||
|
|
||||||
INFO=($(get_disk_info "$DISK"))
|
INFO=($(get_disk_info "$DISK"))
|
||||||
@ -170,24 +178,24 @@ while read -r DISK; do
|
|||||||
IS_MOUNTED=true
|
IS_MOUNTED=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# RAID activo → no mostrar
|
||||||
if $IS_RAID && grep -q "$DISK" <<< "$(cat /proc/mdstat)"; then
|
if $IS_RAID && grep -q "$DISK" <<< "$(cat /proc/mdstat)"; then
|
||||||
if grep -q "active raid" /proc/mdstat; then
|
if grep -q "active raid" /proc/mdstat; then
|
||||||
SHOW_DISK=false
|
SHOW_DISK=false
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ZFS no mostrar nunca
|
||||||
if $IS_ZFS; then
|
if $IS_ZFS; then
|
||||||
SHOW_DISK=false
|
SHOW_DISK=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Si está montado → ocultar
|
||||||
if $IS_MOUNTED; then
|
if $IS_MOUNTED; then
|
||||||
SHOW_DISK=false
|
SHOW_DISK=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ya asignado a la VM actual
|
||||||
if qm config "$VMID" | grep -q "$DISK"; then
|
if qm config "$VMID" | grep -q "$DISK"; then
|
||||||
SHOW_DISK=false
|
SHOW_DISK=false
|
||||||
fi
|
fi
|
||||||
@ -204,6 +212,13 @@ done < <(lsblk -dn -e 7,11 -o PATH)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [ "${#FREE_DISKS[@]}" -eq 0 ]; then
|
if [ "${#FREE_DISKS[@]}" -eq 0 ]; then
|
||||||
cleanup
|
cleanup
|
||||||
whiptail --title "$(translate "Error")" --msgbox "$(translate "No disks available for this VM.")" 8 40
|
whiptail --title "$(translate "Error")" --msgbox "$(translate "No disks available for this VM.")" 8 40
|
||||||
@ -260,6 +275,9 @@ SUCCESS_MESSAGES=""
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
msg_info "$(translate "Processing selected disks...")"
|
msg_info "$(translate "Processing selected disks...")"
|
||||||
|
|
||||||
for DISK in $SELECTED; do
|
for DISK in $SELECTED; do
|
||||||
@ -319,6 +337,10 @@ msg_ok "$(translate "Disk processing completed.")"
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$SUCCESS_MESSAGES" ]; then
|
if [ -n "$SUCCESS_MESSAGES" ]; then
|
||||||
MSG_LINES=$(echo "$SUCCESS_MESSAGES" | wc -l)
|
MSG_LINES=$(echo "$SUCCESS_MESSAGES" | wc -l)
|
||||||
whiptail --title "$(translate "Successful Operations")" --msgbox "$SUCCESS_MESSAGES" 16 70
|
whiptail --title "$(translate "Successful Operations")" --msgbox "$SUCCESS_MESSAGES" 16 70
|
||||||
|
Loading…
x
Reference in New Issue
Block a user