diff --git a/extensions/Servers/Proxmox/Livewire/Storage.php b/extensions/Servers/Proxmox/Livewire/Storage.php index 965d4248c..ec018b2a1 100644 --- a/extensions/Servers/Proxmox/Livewire/Storage.php +++ b/extensions/Servers/Proxmox/Livewire/Storage.php @@ -760,6 +760,7 @@ class Storage extends Component } $driveKey = $this->detachingDriveKey; + $drive = $this->drives[$driveKey]; // Check VM status - must be stopped to detach if ($this->status && $this->status->status !== 'stopped') { @@ -770,11 +771,24 @@ class Storage extends Component try { $proxmox = new Proxmox; - // Use the delete parameter to remove the disk from the config (keeps the volume as unused) + // Get current config to find next unused slot + $config = $proxmox->request( + '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config' + ); + + // Find the next available unused slot + $unusedIndex = 0; + while (isset($config['data']['unused' . $unusedIndex])) { + $unusedIndex++; + } + + // Move the disk to an unused slot instead of deleting it + // This preserves the volume data $proxmox->request( '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config', 'put', [ + 'unused' . $unusedIndex => $drive['volume'], 'delete' => $driveKey, ] );