Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
home_server:home_server_setup:kvm [2024-02-18 Sun wk07 18:07] – [Change the Disk Allocated Size] baumkphome_server:home_server_setup:kvm [2025-02-08 Sat wk06 17:11] (current) – [kvm back-up links] baumkp
Line 5: Line 5:
   *[[https://www.ostechnix.com/install-and-configure-kvm-in-ubuntu-20-04-headless-server/|Install And Configure KVM In Ubuntu 20.04 Headless Server]]   *[[https://www.ostechnix.com/install-and-configure-kvm-in-ubuntu-20-04-headless-server/|Install And Configure KVM In Ubuntu 20.04 Headless Server]]
   *[[https://linuxhint.com/install_kvm_debian_10/|Installing KVM on Debian 10]]   *[[https://linuxhint.com/install_kvm_debian_10/|Installing KVM on Debian 10]]
-  *[[https://computingforgeeks.com/how-to-install-kvm-virtualization-on-debian/|How To Install KVM Hypervisor on Debian 11|10]]+  *[[https://computingforgeeks.com/how-to-install-kvm-virtualization-on-debian/|How To Install KVM Hypervisor on Debian 12|11|10]]
   *[[https://www.cyberciti.biz/faq/install-kvm-server-debian-linux-9-headless-server/|How to install KVM server on Debian 9/10 Headless Server]]   *[[https://www.cyberciti.biz/faq/install-kvm-server-debian-linux-9-headless-server/|How to install KVM server on Debian 9/10 Headless Server]]
 Basically to install the KVM Hypervisor: ''sudo apt install qemu-kvm qemu-system qemu-utils libvirt-clients libvirt-daemon-system virtinst bridge-utils'' bridge-utils is optional. Basically to install the KVM Hypervisor: ''sudo apt install qemu-kvm qemu-system qemu-utils libvirt-clients libvirt-daemon-system virtinst bridge-utils'' bridge-utils is optional.
Line 64: Line 64:
 ---- ----
 =====KVM Backup===== =====KVM Backup=====
-There seems to be main ways to backup a KVM virual machine +There seems to be main ways to backup a KVM virual machine:
-  - Copy the main file(s) while the VM is running +
-    -  Not recommended as file corruption will probably occur as the VM operation may and probably will modify the file during the copy process+
   - Shutdown the VM first and then copy the file.  Start the VM again after the copy is completed.   - Shutdown the VM first and then copy the file.  Start the VM again after the copy is completed.
   - Use virsh backup-begin command to allow live full backup   - Use virsh backup-begin command to allow live full backup
Line 72: Line 70:
     - Create a snapshot of the VM and direct all changes to the snapshot allowing safe backup of main VM file     - Create a snapshot of the VM and direct all changes to the snapshot allowing safe backup of main VM file
     - Active back commit the snapshot and verify back commit worked     - Active back commit the snapshot and verify back commit worked
 +  * Copy the main file(s) while the VM is running 
 +    -  <fc #ff0000>Not recommended</fc>, as file corruption will probably occur as the VM operation may and probably will modify the file during the copy process
 ====KVM Offline Backup==== ====KVM Offline Backup====
 <fc #ff0000>Note this only works on VMs that are shut down</fc> <fc #ff0000>Note this only works on VMs that are shut down</fc>
Line 82: Line 81:
   -''sudo virsh define --file <path-to-xml-file>'' to import (define) a VM from an XML file.   -''sudo virsh define --file <path-to-xml-file>'' to import (define) a VM from an XML file.
  
 +
 +  *[[https://poweradm.com/backup-kvm-virtual-machine/How to Backup a Virtual Machine on KVM?]]
  
 References: References:
   *[[https://ostechnix.com/export-import-kvm-virtual-machines-linux/|How To Export And Import KVM Virtual Machines In Linux]]   *[[https://ostechnix.com/export-import-kvm-virtual-machines-linux/|How To Export And Import KVM Virtual Machines In Linux]]
 ====kvm back-up links==== ====kvm back-up links====
-  *[[https://schh.medium.com/backup-and-restore-kvm-vms-21c049e707c1|Backup and Restore KVM Vms]] +  *[[https://schh.medium.com/backup-and-restore-kvm-vms-21c049e707c1|Backup and Restore KVM VMs]] - Shutdown VM method 
-  *[[https://www.bacula.org/kvm-backup-vm/|Backula Technical Considerations of a KVM Backup Process]]+  *[[https://www.bacula.org/kvm-backup-vm/|Backula Technical Considerations of a KVM Backup Process]] - Shutdown VM method
   *[[https://www.virtkick.com/docs/how-to-perform-a-live-backup-on-your-kvm-virtual-machines.html|Virtkick - How to Perform a Live Backup on your KVM Virtual Machines]]   *[[https://www.virtkick.com/docs/how-to-perform-a-live-backup-on-your-kvm-virtual-machines.html|Virtkick - How to Perform a Live Backup on your KVM Virtual Machines]]
   *[[https://libvirt.org/kbase/live_full_disk_backup.html|Libvirt.org - Efficient live full disk backup]]   *[[https://libvirt.org/kbase/live_full_disk_backup.html|Libvirt.org - Efficient live full disk backup]]
Line 105: Line 106:
   * ''sudo virsh pool-list'' : List storage pools   * ''sudo virsh pool-list'' : List storage pools
     * ''%%sudo virsh vol-list --pool pool-name%%'' : List volumes in ''pool-name''     * ''%%sudo virsh vol-list --pool pool-name%%'' : List volumes in ''pool-name''
 +  * ''sudo virsh undefine domain-name'' : To remove the VM definition
   * virsh : start, shutdown, destroy, reboot, or pause (suspend / resume)   * virsh : start, shutdown, destroy, reboot, or pause (suspend / resume)
     * ''sudo virsh start domain-name'' : To start a virtual machine of domain ''domain-name''     * ''sudo virsh start domain-name'' : To start a virtual machine of domain ''domain-name''
Line 123: Line 125:
 ====Change the Disk Allocated Size==== ====Change the Disk Allocated Size====
 How to change the amount of disk space assigned to a KVM  *[[https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/|How to Resize a qcow2 Image and Filesystem with Virt-Resize]] How to change the amount of disk space assigned to a KVM  *[[https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/|How to Resize a qcow2 Image and Filesystem with Virt-Resize]]
-  *First turn off the virtual machine to be checked+  *First, **turn off the virtual machine** to be checked
   *Next find the file location of the virtual machine to be checked   *Next find the file location of the virtual machine to be checked
     *Next query the file: ''sudo qemu-img info /path_vm/vm_name.img''     *Next query the file: ''sudo qemu-img info /path_vm/vm_name.img''
     *Next increase the allowed size of the vm disk: ''sudo qemu-img resize /path_vm/vm_name.img +20G''     *Next increase the allowed size of the vm disk: ''sudo qemu-img resize /path_vm/vm_name.img +20G''
     *We need to make a backup of the VM disk: ''sudo cp /path_vm/vm_name.img /path_vm/vm_name_backup.img''     *We need to make a backup of the VM disk: ''sudo cp /path_vm/vm_name.img /path_vm/vm_name_backup.img''
-    *We can check the file system on the VM: ''%%virt-filesystems --long -h --all -a /path_vm/vm_name.img%%''+    *We can check the file system on the VM: ''%%virt-filesystems --long -h --all -a /path_vm/vm_name.img%%'', <fc #ff0000>//**we can also use this to confirm the correct partition to expand**//</fc>.
     *We the backup VM disk to create a new expanded drive: ''%%sudo virt-resize --expand /dev/sda1 /path_vm/vm_name_backup.img /path_vm/vm_name.img%%''     *We the backup VM disk to create a new expanded drive: ''%%sudo virt-resize --expand /dev/sda1 /path_vm/vm_name_backup.img /path_vm/vm_name.img%%''
  
Line 136: Line 138:
 ====Shrink the Disk File==== ====Shrink the Disk File====
   *Locate the QEMU disk file   *Locate the QEMU disk file
-  *Shut down the VM.+  ***Shut down the VM.**
     *Copy the VM file to a back-up: ''cp image.qcow2 image.qcow2_backup''     *Copy the VM file to a back-up: ''cp image.qcow2 image.qcow2_backup''
   *Option #1: Shrink your disk without compression (better performance, larger disk size):   *Option #1: Shrink your disk without compression (better performance, larger disk size):