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.
Procedure
- SSH to the Proxmox server
- Check disk space on
pve-root
usingdf -h
pwd
to make sure you’re in root- 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 - Ftp / bin / hash
- 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:
- CPU and memory of previous VM
- Enough disk space on the local root as it will be a temporary store for the FTP’ed file
- The Unique ID assigned when creating a VM in Proxmox
- 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 slow disk transfer statistics (probably 100 mbit/s host link):
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)
Example of faster disk transfer statistics (1000 mbit/s LAN link):
# scp example.com.qcow2 [email protected]:/home/user/vm.import # [email protected]'s password: # example.com.qcow2 100% 26GB 90.5MB/s 04:57
Why are we so pedantic about time? Because you may be looking at downtime that should always be minimized.
Once the file is local, you can import the disk.
Import the disk
qm importdisk 106 harddisk.qcow2 nasX|local-lvm|raid1|raid0
The nasX|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.
What we concern ourselves with performance is how long does this process take? For example, how long does it take to import a 637 GiB disk? Here are some timings:
- 2 hours to copy over slow magnetic
- around 1 hour to import disk to RAIDZ1 over 10 Gbps PCI-2 1000 mbit/s
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
.
1 thought on “How to import a QCOW2 file to Proxmox”
This worked perfect for importing a qcow2 file in my proxmox vm. thanks for sharing!