Moving all disks to new Storage

Younex

Well-Known Member
Jan 30, 2018
93
23
48
46
Hi,

Sometimes i need to move all disk of each VM to new storage in order to maintenance on SAN.

I do this by clicking manually trough each VM and move each disk.

Is there any command to move all existing disks on one storage to another?

Thanks!

Kind Regards
 
Last edited:
There is no single command that moves all disks of a given VM to another storage. You should write a script that utilizes either API or CLI to automate things.
A very back of the napkin example:
Code:
for vmid in 2000 2001;do for disk in $(pvesm list blockbridge1 --vmid $vmid|egrep -v Volid|awk '{print $1}');do echo qm move-disk $vmid $disk blockbridge2;done;done
qm move-disk 2000 blockbridge1:vm-2000-cloudinit blockbridge2
qm move-disk 2000 blockbridge1:vm-2000-disk-0 blockbridge2
qm move-disk 2001 blockbridge1:vm-2001-cloudinit blockbridge2
qm move-disk 2001 blockbridge1:vm-2001-disk-0 blockbridge2


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
  • Like
Reactions: Kingneutron
Hi,

Sometimes i need to move all disk of each VM to new storage in order to maintenance on SAN.

I do this by clicking manually trough each VM and move each disk.

Is there any command to move all existing disks on one storage to another?

Thanks!

Kind Regards
This could be nice feature to have in GUI. Most our VM have multiple disks and this should help.
 
This could be nice feature to have in GUI. Most our VM have multiple disks and this should help.
Sure, it's nice to have CLI vs GUI parity. But at the same time, it would mean a batch operation to do something that can fail in multiple places. That, in turn, means error recovery from all the edge conditions. GUI users, generally, expect "easy to understand error message". Additionally, in some cases, you may want a rollback of the operation, which is not an easy task.

All of that is for a once-a-year (if that) event that is unlikely to be performed by most users, and those who do need it are likely to have the skills to execute it.
Can you make a business case for it? Sure. But it would need to be more than a "nice feature to have".


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Last edited:
Very simple script, no error checking: input vm id and target storage name

Bash:
#!/bin/bash

read -p "VM ID: " vm
read -p "Target storage name: " target

echo .
echo "Migrate all disks for VM: $vm to Storage: $target"
echo .
read -p "Are you sure ? | Y: Continue N: Stop " go

if [ "$go" = "y" ] || [ "$go" = "Y" ]
    then
        for disk in $(qm config $vm | grep vm-$vm-disk | grep -v unused | cut -d: -f1); do
        ## --delete deletes the source disk after copy/clone
        qm move-disk $vm $disk $target --delete
        done
    else
    echo "No action taken... bye"
    
    fi
 
  • Like
Reactions: Thorben
But when you have access only using web interface (AD as LDAP), you can do things only in GUI.
 
But when you have access only using web interface (AD as LDAP), you can do things only in GUI.
Shell is accessable within the webinterface: DATACENTER --> nodename --> Shell.

open shell --> typ: nano movedisks.sh --> copy/paste script --> CTRL + X --> confirm with Y and hit Enter --> typ: bash movedisks.sh
 
Shell is accessable within the webinterface: DATACENTER --> nodename --> Shell.

open shell --> typ: nano movedisks.sh --> copy/paste script --> CTRL + X --> confirm with Y and hit Enter --> typ: bash movedisks.sh
No shell for LDAP users. This works only for @pam
 
This is what I have thrown together for this when I had to move a lot of VMs to new storage recently. It takes a file with a list of VMIDs, one per line, and the destination storage as inputs. Handles templates with base disks and removing/recreating cloud-init disks.

Bash:
#!/bin/bash
set -ex

if [ "$#" -ne 2 ] ; then
    echo "Invalid Arguments. Usage: bulkMove.sh [VMIDs file] [newStorage]"
    exit
fi

if [ ! -e $1 ] ; then
    echo "VMIDs file $1 does not exist"
    exit 2
fi

vmids=$1
newStorage=$2

while read vmid ; do
    if qm config $vmid | grep -q protect ; then
        qm set --protection 0 $vmid
    fi
    for disk in $(qm config $vmid | grep "vm-$vmid-disk\|base-$vmid-disk" | grep -v unused | cut -d: -f1); do
        qm move-disk $vmid $disk $newStorage --delete
    done
    for disk in $(qm config $vmid | grep "vm-$vmid-cloudinit" | grep -v unused | cut -d: -f1); do
        qm set $vmid --delete $disk
        qm set $vmid --$disk $newStorage:cloudinit
    done
done <$vmids
 
Last edited: