This is a collection of several Howto's from different sites to archive a Virtual Machine System on Ubuntu for whatever use you may see fit.

Check if your CPU and or Machine Support a KVM Setup!#

Install necessary components:

 

 
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients virtinst libguestfs-tools libosinfo-bin bridge-utils

 

add your user to use the kvm:

 

sudo adduser "youruser" libvirt
sudo adduser "youruser kvm

Networking setup

Run ip add and note the name of your Ethernet interface. In my case, it’s enp0s31f6.

Examine the contents of /etc/netplan. In my case, there was one file, with these contents:

network:
  ethernets:
    enp0s31f6:
      dhcp4: true
  version: 2

If yours differs substantially, take care to understand what this file is doing! Some of the reference links below might help.

Back up the YAML file from /etc/netplan, then edit it. Add a bridges section, so the result looks like the following code sample. Note that enp0s31f6 should be replaced by the name of your Ethernet interface:

network:
  version: 2
  ethernets:
    enp0s31f6:
      dhcp4: true
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp0s31f6

Test it with sudo netplan try. This allows you to test the configuration and make sure it’s working properly. It will offer to make the changes permanent for you, and if you don’t accept that prompt within a minute or two the changes will be reverted automatically.

Assuming that it worked, br0 is now assigned an IP address by your local DHCP server. You can verify this by running ip add.

You’ll need to update DHCP reservations for the host, if you have any, to use the MAC address of the bridge interface. ip add will show you this MAC address.

Finally, create a file called kvm-hostbridge.xml in a location of your choice, with the following content:

<network>
  <name>hostbridge</name>
  <forward mode="bridge"/>
  <bridge name="br0"/>
</network>

Create and enable this network by running:

virsh net-define /path/to/my/kvm-hostbridge.xml
virsh net-start hostbridge
virsh net-autostart hostbridge



To transfer a KVM virtual machine (VM) from one host to another, you can follow the steps below:

  1. Make sure you have the same version of KVM on both hosts. You can verify this by running the kvm –version command.
  2. Stop the VM you want to transfer. You can do this using the command virsh shutdown vm_name.
  3. Export the VM definition XML to the old host using the command virsh dumpxml vm_name > file_name.xml.
  4. Check where the VM files are stored. You can do this using the command virsh domblklist vm_name.
  5. Copy the VM files from the old host to the new host, including the xml definition file. You can use the scp command to do this.
  6. Check the contents of the VM xml definition file to correct the physical path of where the disk files are physically and correct the network
  7. adapter names if necessary.
  8. Import the VM to the new host using the command virsh define /path/to/vm_xml_file.
  9. Start the VM on the new host using the virsh start vm_name command.

Make sure you have properly configured networking and storage on the new host so that the VM can work properly. Also, if you’ve been using pass-through virtualization for your devices, make sure you’re configuring those on the new host correctly as well.

A lot of useful information on how to manage KVM virtualization systems can also be found on the blog: https://frontpagelinux.com/tutorials/getting-started-with-kvm-hypervisor-virtual-machines-the-right-way/

 

** Credits: https://synaptica.info/2023/05/09/kvm-howto-move-or-copy-a-vm-from-host-to-onther-host/ , https://www.dzombak.com/blog/2024/02/Setting-up-KVM-virtual-machines-using-a-bridged-network.html , https://www.tecmint.com/install-qemu-kvm-ubuntu-create-virtual-machines/

Kommentar schreiben

Senden