How to import a QCOW2 file to Proxmox

Background

At times you will have a QCOW2 file that you want to import into Proxmox. Although this is a fairly trivial process, if you only do it every now and again you’ll probably need some kind of playbook. In this article, we attempt to create a playbook, with some references if it’s not enough.

This process assumes you’ll be using FTP to get the remote QCOW2 file on the local box. This could be problematic if you don’t have the correct size of disk space available locally on the Proxmox server. But bear in mind if your remote QCOW file is 200GB, but you only use 50GB of disk space, the resultant file will be 50GB so you should be fine. The long term solution to this problem might be when installing Proxmox to ensure that the default 100 GB pve-root is made to something that will cater for future imports, perhaps 200 GB or so.

How to import a QCOW2 file to Proxmox

Procedure

  1. SSH to the Proxmox server
  2. Check disk space on pve-root using df -h
  3. pwd to make sure you’re in root
  4. A temporary directory /root/vm.import will be used. Create it, and make sure it’s cleaned afterwards once you’re 100% the import was a success
  5. Ftp / bin / hash
  6. get remotefilename.qcow2

At this point the remote QCOW2 backup file is on the Proxmox server on pve-root in the /root/vm.import folder.

From here we have to convert it to a VM, but first make sure the VM is created and find the unique ID. In the example below, the unique ID is 106. Also note that when you create a new VM, it will automatically have a disk. Since we’re not going to be using this disk, it can be safely deleted afterwards by using the UI’s “remove” option. As with anything else to do with deletions, double check before pressing confirm.

Information required to complete this operation:

  1. CPU and memory of previous VM
  2. Enough disk space on the local root as it will be a temporary store for the FTP’ed file
  3. The Unique ID assigned when creating a VM in Proxmox
  4. New IP address to be assigned to the VM, subnet mask, and default gateway.
    • You need this as once the VM is transferred the network configuration needs to be updated

Example of disk transfer statistics:

226-File successfully transferred
226 243.912 seconds (measured here), 11.10 Mbytes per second
2839448660 bytes received in 243.99 secs (11.0985 MB/s)

Once the file is local, you can import the disk.

Import the disk

qm importdisk 106 harddisk.qcow2 local-lvm|raid1|raid0

The local-lvm|raid1|raid0 is a collection of disks we have on our system, substitute that with whichever disk you want to import file to go to. You could try the lsblk command to see your disk layout if you’re using the default thin provisioning.

Once the import is complete, the final lines of the output will look similar to this (note ` unused0:raid1:vm-106-disk-1` as part of that will be used next).

transferred: 161061273600 bytes remaining: 0 bytes total: 161061273600 bytes progression: 100.00 %
Successfully imported disk as 'unused0:raid1:vm-106-disk-1'

Associate the disk

There are probably ways of associating the disk using the UI, but the command below will do the same. Remember when you set up a new VM with the CPU and memory, a default disk was created that can be deleted. The command below associates the newly imported disk with the VM and marks the newly created disk as Unused.

root@proxmox1:~/vm.import# qm set 106 --scsi0 raid1:vm-106-disk-1
update VM 106: -scsi0 raid1:vm-106-disk-1

That’s it! Now you can start the VM and reconfigure the IP address, subnet mask, and default gateway, and you should be good to go.

Hotplug Problem

If you encounter this issue associating the disk:

qm set 101 --scsi0 large-nfs-cacce2:101/vm-101-disk-0.raw
update VM 101: -scsi0 large-nfs-cache2:101/vm-101-disk-0.raw
400 Parameter verification failed.
scsi0: hotplug problem - can't unplug bootdisk 'scsi0'

This means you might have an existing scsi0 disk and you need to pick another ID, e.g. scsi1.

References

Share this article

1 thought on “How to import a QCOW2 file to Proxmox”

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top