Backup VM

Select Target VM

# sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     win10                          shut off


Backup VM XML (meta data)

# sudo virsh dumpxml win10 > win10.xml.20201104


Check VM Image

# cat win10.xml | grep file
    <disk type='file' device='disk'>
      <source file='/var/lib/libvirt/images/win10.qcow2'/>
    <disk type='file' device='cdrom'>
      <source file='/ISOs/Win10_1909_Korean_x64.iso'/>


Shirink Image Size (if needed)

12,656MB → 12,552MB

# cd /var/lib/libvirt/images/

# qemu-img convert -O qcow2 win10.qcow2 win10.qcow2.20201104

# ls -l win10.qcow2*
-rw-r--r--. 1 root    root    13270974464 2020-11-04 15:59 win10.qcow2
-rw-r--r--. 1 root    root    13162053632 2020-11-04 15:55 win10.qcow2.20201104


Restore VM

Copy xml and image (qcow2)

# cp win10.xml.20201104 /var/lib/libvirt/images/
# cp win10.qcow2.20201104 /var/lib/libvirt/images/win10.qcow2


Remove Previous VM / Undefine VM (if needed)

# sudo virsh undefine win10


Modify XML (if needed)

change name, cpu, memory, network, etc ... if needed

win10.xml.20201104
<domain type='kvm'>
  <name>win10</name>
  <uuid>7bc4c0c4-a266-43f9-9188-4983cf9c3a23</uuid>
  ...
  <memory unit='KiB'>8388608</memory>
  <currentMemory unit='KiB'>8388608</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  ...
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/win10.qcow2'/>
      <target dev='sda' bus='sata'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    ...
    <interface type='bridge'>
      <mac address='52:54:00:3b:d9:a6'/>
      <source bridge='br0'/>
      <model type='e1000e'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>
   ...
  </devices>
</domain>


Restore / Define VM (if needed)

# cd /var/lib/libvirt/images/
# sudo virsh define win10.xml.20201104
  • 레이블 없음