Moving disk image from one KVM machine to another (2025)

Note: Article is outdated! Please use "Disk Action -> Reassign Owner" for VMs or "Volume Actions -> Reassign Owner" for Containers.

Currently moving disks between VMs is only possible via the commandline.In most cases moving a disk to a different VM is as simple as moving aconfiguration line from one file to another and renaming a file or volume.However, there are cases where special care has to be taken (particularly whenusing LVM storages).

Contents

  • 1 Step 1: Move Disk to Target Storage
  • 2 Step 2: Find the disk config entry in the old VM
  • 3 Step 3: Rename/Move the disk
    • 3.1 For directory based storages (Directory, NFS, Gluster):
    • 3.2 For LVM (thin) storages:
    • 3.3 For ZFS:
    • 3.4 For ceph:
  • 4 Step 4: Update the configuration
  • 5 Step 5: Storage related fixups

Step 1: Move Disk to Target Storage

In case you want to move the disk also to a different storage, the easiest wayis to start with that, as you can do this via the GUI.

If the target storage happens to not be available on the PVE host because youwant to move the disk to a different cluster member, you'll want to start bymoving the disk to a shared storage, then perform the remaining steps here, thenuse the GUI again to move the disk to the final target storage. You can even dothis if the target host is not part of the same cluster, provided it is possibleto use some shared storage in between.Note that using the same storage on multiple clusters is not recommended andshould only be done as a temporary measure, and care has to be taken to avoidclashing VMIDs on the storage.

If the above does not work for you the easiest path is to move the disk to adirectory based storage in .qcow2 format and manually move that to a directorystorage on the target host, add it to the target VM and move it to the targetstorage at the end.

The steps below assume the disk is on the same host.

Step 2: Find the disk config entry in the old VM

Find the configuration line of the disk you want to move, remember it, we'llwant to move it to a different file later in step 4.

Assuming you want to move the SCSI-1 disk from VM 400 to VM 2300, open/etc/pve/qemu-server/400.conf, and find the following line:

scsi1: tank:vm-400-disk-1,discard=on,size=16G

Step 3: Rename/Move the disk

This step is only necessary if the disk contains the VM ID, which includes moststorage types (iSCSI-Direct is an example where you can skip this step).

All of the examples below assume there's no disk on the target storage for thatVM already. If there is, increase the trailing number so that the name isunique. Eg. if you already have a vm-2300-disk-1 andvm-2300-disk-2, thenuse vm-2300-disk-3 instead.

For directory based storages (Directory, NFS, Gluster):

Find the path and rename the file.For example, assuming the disk line was: local:400/vm-400-disk-1.qcow2:

# pvesm path 'local:400/vm-400-disk-1.qcow2'/var/lib/vz/images/400/vm-400-disk-1.qcow2# mkdir -p /var/lib/vz/images/2300# mv /var/lib/vz/images/400/vm-400-disk-1.qcow2 /var/lib/vz/images/2300/vm-2300-disk-1.qcow2

For LVM (thin) storages:

Use

# lvs(...)vm-400-disk-1 pve Vwi-aotz-- 42.00g

to find the disk's name on the host (mala in this example). It must appear in the source VM's config as well. Thus, the following command should give a similar result.

# cat /etc/pve/nodes/mala/qemu-server/400.conf | grep lvmscsi1: local-lvm:vm-400-disk-1,size=42G

There are two crucial steps to move the disk. The first is renaming the logical volume according to the target VM.

# lvrename pve/vm-400-disk-1 pve/vm-2300-disk-1Renamed "vm-400-disk-1" to "vm-2300-disk-1" in volume group "pve"

The second is to adapt the VM config files. Delete the line for this disk from the source VM config

# sed -i.backup '/vm-400-disk-1/d' /etc/pve/nodes/mala/qemu-server/400.conf

and add it to the one of of the target VM 2300, with changes according to lvrename. This means

# echo "scsi1: local-lvm:vm-2300-disk-1,size=42G" >> /etc/pve/nodes/mala/qemu-server/2300.conf

For ZFS:

Assuming the storage is named tank, and the pool property istank/host/vms, and the disk line was: tank:vm-400-disk-1:

# zfs rename tank/host/vms/vm-400-disk-1 tank/host/vms/vm-2300-disk-1

For ceph:

Assuming the pool is named rbd and the disk line was:myceph:vm-400-disk-1, and there's a monitor at the address 1.2.3.4, weuse following command:

# rbd -m 1.2.3.4 -n client.admin --keyring /etc/pve/priv/ceph/myceph.keyring --auth_supported cephx mv rbd/vm-400-disk-1 rbd/vm-2300-disk-1

If you only have one ceph storage, local to your PVE cluster, or have a localceph configuration for easier maintenance you might be able to shorten thiscommand to just:

# rbd mv rbd/vm-400-disk-1 rbd/vm-2300-disk-1

Step 4: Update the configuration

Find the configuration line from Step 1 again and delete it from there, then addit to the new VM with the VMID updated.

As in step 1 we're assuming we're trying to move SCSI-1 disk from VM 400 to VM 2300.So we delete the following from /etc/pve/qemu-server/400.conf:

scsi1: tank:vm-400-disk-1,discard=on,size=16G

Now figure out a free storage slot on VM 2300 (by reading ide/scsi/virtio/satakeys of the config and finding an unused number - beware of the limits on eachof them, which you can find in the vm.conf(5) manpage or by simply testing itout in the GUI).

Assuming we want to add it as virtio-3 disk, add the following line:

virtio3: tank:vm-400-disk-1,discard=on,size=16G

Step 5: Storage related fixups

When using an LVM storage, there's the option to make use of LVM tags. If you'reusing this option (tagged_only in the storage's section in/etc/pve/storage.cfg), then you have to update the disk's tag.

For instance, if like above you moved vm-400-disk-1 to becomevm-2300-disk-1, you have to remove tag pve-vm-400 and add tagpve-vm-2300to the LV.Assuming your storage is named pve you can accomplish this with thefollowing command:

# lvchange --deltag pve-vm-400 --addtag pve-vm-2300 pve/vm-2300-disk-1
Moving disk image from one KVM machine to another (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Kelle Weber

Last Updated:

Views: 6426

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.