Create VM from existing qcow2 image ?

Discussion in 'Proxmox VE: Installation and configuration' started by niuk, Mar 1, 2017.

Tags:
  1. niuk

    niuk New Member

    Joined:
    Feb 20, 2017
    Messages:
    27
    Likes Received:
    0
    I have qcow2 image below and want to create VM using this image ..How do I do this from GUI ? If not then from CLI. I tried to google it but hasn't found straight answer yet , same on Proxmox support pages

    root@pve:/var/lib/vz/template/iso# ls -l /var/lib/vz/images/
    total 1940868
    -rw-r--r-- 1 root root 1987444736 Mar 1 10:10 PA-VM-KVM-8.0.0.qcow2
     
  2. Mike_TBF

    Mike_TBF New Member

    Joined:
    Feb 24, 2017
    Messages:
    9
    Likes Received:
    1
    Hi,

    Proxmox is very "protective" when it comes to virtual disks. Depending on your storage, you cannot simply replace them with something else.
    On some storage adapters there will be easier / faster ways, but this should work in any case:
    • Create a new VM and add a virtual disk to it that has the same (virtual) size as the disk you want to import.
    • In the hardware tab of your VM, note the name of the virtual disk file.
    • Open a CLI and use qemu-img's "convert" function to read the qcow2-file and export directly into the virtual disk. The exact parameters will depend on your storage and the target image format. If in doubt, read "man qemu-img" for details.
    example: to import the image "source.qcow2" into the first virtual disk of VM 101 in a Ceph storage pool called "vmpool" in "raw" format, you would issue the following command:
    qemu-img convert -O raw -p -n source.qcow2 rbd:vmpool/vm-101-disk-1
    The parameter "-p" shows the progress, and "-n" tells qemu-img to write into an existing image instead of creating a new one.
     
    niuk likes this.
  3. niuk

    niuk New Member

    Joined:
    Feb 20, 2017
    Messages:
    27
    Likes Received:
    0
    Appreciate, meantime I added storage in Datacenter , named it 'images' and pointed to /mnt for disk images. Then for VM's (id 102) hard disk I pointed to that storage with qcow2 format. And finally copied my qcow2 image into default VM image of vm-102-disk-1.qcow2. It works just fine, I was able to complet emy setup and boot OS

    root@pve:/mnt/images/102# ls -l
    total 1946192
    -rw-r--r-- 1 root root 1987444736 Mar 1 12:17 PA-VM-KVM-8.0.0.qcow2
    -rw-r----- 1 root root 34365243392 Mar 1 12:07 vm-102-disk-1.qcow2
    root@pve:/mnt/images/102# chmod o-r PA-VM-KVM-8.0.0.qcow2
    root@pve:/mnt/images/102# ls -l
    total 1946192
    -rw-r----- 1 root root 1987444736 Mar 1 12:17 PA-VM-KVM-8.0.0.qcow2
    -rw-r----- 1 root root 34365243392 Mar 1 12:07 vm-102-disk-1.qcow2
    root@pve:/mnt/images/102# cp PA-VM-KVM-8.0.0.qcow2 vm-102-disk-1.qcow2
    root@pve:/mnt/images/102# ls -l
    total 3881736
    -rw-r----- 1 root root 1987444736 Mar 1 12:17 PA-VM-KVM-8.0.0.qcow2
    -rw-r----- 1 root root 1987444736 Mar 1 12:18 vm-102-disk-1.qcow2
     
  4. udo

    udo Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 22, 2009
    Messages:
    5,584
    Likes Received:
    135
    Hi,
    I think that's not right in all cases... if you have local storage on the normal filesystem (and enough space here - which is so in this case, because the qcow2-file is allready on this partition) you can simply overwrite an vm-disk with the right one.
    Create an VM with an qcow2-disk on local storage and move the file like
    Code:
    mv /var/lib/vz/images/PA-VM-KVM-8.0.0.qcow2 /var/lib/vz/images/123/vm-123-disk-1.qcow2
    
    start VM and if all right, you can move the vmdisk to another storage, if you want.

    Udo
     
    niuk likes this.
  5. niuk

    niuk New Member

    Joined:
    Feb 20, 2017
    Messages:
    27
    Likes Received:
    0
    Now I created another VM , this time in local-lvm (pve) storage and neither can copy, move nor qemu-img convert ?

    root@pve:/var/lib/vz/images# qemu-img convert -O raw -p -n PA-VM-KVM-8.0.0.qcow2 /dev/pve/vm-101-disk-1
    qemu-img: output file is smaller than input file
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice