diff --git a/extensions/Servers/Proxmox/Livewire/Storage.php b/extensions/Servers/Proxmox/Livewire/Storage.php index 339369d57..9f99d33e1 100644 --- a/extensions/Servers/Proxmox/Livewire/Storage.php +++ b/extensions/Servers/Proxmox/Livewire/Storage.php @@ -837,22 +837,34 @@ class Storage extends Component return; } - // Get next available index on target bus - $targetIndex = $this->getNextAvailableIndex($targetBus); - if ($targetIndex === null) { - $this->notify("No available slots for {$this->busTypes[$targetBus]['label']} drives.", 'error'); - return; - } - try { $proxmox = new Proxmox; - $targetKey = $targetBus . $targetIndex; - // Get current config to find next unused slot + // Get current config to check actual slot availability $config = $proxmox->request( '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config' ); + // Find the next available slot on the target bus by checking actual Proxmox config + $maxIndex = $this->busTypes[$targetBus]['max'] ?? 4; + $targetIndex = null; + + for ($i = 0; $i < $maxIndex; $i++) { + $slotKey = $targetBus . $i; + // Check if this slot is occupied in the actual config + if (!isset($config['data'][$slotKey])) { + $targetIndex = $i; + break; + } + } + + if ($targetIndex === null) { + $this->notify("No available slots for {$this->busTypes[$targetBus]['label']} drives.", 'error'); + return; + } + + $targetKey = $targetBus . $targetIndex; + // Find the next available unused slot $unusedIndex = 0; while (isset($config['data']['unused' . $unusedIndex])) {