User Tools

Site Tools


linux:apps:kvm

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
linux:apps:kvm [2023/08/06 12:17] – [Error Access ISO files, etc.] oscarlinux:apps:kvm [2025/10/21 20:15] (current) oscar
Line 1: Line 1:
 ====== KVM ====== ====== KVM ======
 +
 +----
  
 ===== Installation ===== ===== Installation =====
Line 55: Line 57:
 In order to manage virtual machines as a regular user, that user needs to be added to the libvirt group: In order to manage virtual machines as a regular user, that user needs to be added to the libvirt group:
  
-  # usermod -aG libvirt,kvm USERNAME+  # adduser <username> libvirt 
 +       or  (not sure if kvm group is needed) 
 +  # usermod -aG libvirt,kvm <username>
  
 === User-specific and system-wide VMs === === User-specific and system-wide VMs ===
-By default, if virsh is run as a normal user it will connect to libvirt using qemu:///session URI string. This URI allows virsh to manage only the set of VMs belonging to this particular user. To manage the system set of VMs (i.e., VMs belonging to root) virsh should be run as root or with qemu:///system URI:+By default, if virsh is run as a normal user it will connect to libvirt using: **qemu:%%///%%session** URI string. This URI allows virsh to manage only the set of VMs belonging to this particular user.  
 + 
 +To manage the system set of VMs (i.e., VMs belonging to root) virsh should be run as root or with: **qemu:%%///%%system** URI:
  
   $ virsh --connect qemu:///system list --all   $ virsh --connect qemu:///system list --all
Line 65: Line 71:
  
   $ export LIBVIRT_DEFAULT_URI='qemu:///system'   $ export LIBVIRT_DEFAULT_URI='qemu:///system'
 +
 +===== Libvirt default network =====
 +If you use libvirt to manage your VMs, libvirt provides a NATed bridged network named "default/virbr0" that allows the host to communicate with the guests. 
 +<code>
 +3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
 +    link/ether 52:54:00:f5:c4:41 brd ff:ff:ff:ff:ff:ff
 +    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
 +       valid_lft forever preferred_lft forever
 +</code>
 +This network is available only for the system domains (that is VMs created by root or using the "qemu:system" connection URI). VMs using this network end up in 192.168.122.1/24 and DHCP is provided to them via dnsmasq. This network is not automatically started. To start it use:
 +  virsh --connect=qemu:///system net-start default
 +
 +To make the default network start automatically use:
 +
 +  virsh --connect=qemu:///system net-autostart default
 +
 +===== Change XML configuration =====
 +Extract the xml from an existing qcow2 image by:
 +  virsh dumpxml Windows-11 > Windows-11.xml
 +Edit and modify the tags in the XML file.
 +Undefine the XML config from the old vm to prevent an error because of a duplicate UUID:
 +  virsh undefine --nvram Windows-11
 +  or
 +  virsh undefine Windows-11
 +Import / define the new XML file:
 +  virsh define Windows-11.xml
 +Of course you will have to stop and start the vm for the changes to take effect:
 +  virsh destroy name_of_vm
 +  virsh start name_of_vm
  
  
Line 78: Line 113:
 Or any other paths that have full r others rights. Or any other paths that have full r others rights.
  
 +===== Convert VirtualBox to KVM =====
 +  qemu-img convert -f vdi -O qcow2 virtualbox-name.vdi kvm-name.qcow2
 +===== Shrink KVM  qcow2 image =====
 +  qemu-img convert -O qcow2 source.qcow2 shrunk.qcow2
 +===== Make SATA disk available in Windows Client =====  
 +To make a SATA disk partition available in a Windows VM add the disk to the domain’s xml config file by hand. First find the id of the partition that you want to add. Rather than using /dev/sda you should use /dev/disk/by-id/ where you get from
  
-===== Links =====+   ls -l /dev/disk/by-id
  
 +Now edit the ///etc/libvirt/qemu/${YOUR_VM}.xml// file and add a <disk> section to the <devices> section:
 +<code>
 +# nano /etc/libvirt/qemu/${YOUR_VM}.xml
 +
 +or 
 +
 +virsh edit ${YOUR_VM}
 +----------------------------------------------
 +<disk type='block' device='disk'>
 +    <driver name='qemu' type='raw'/>
 +    <source dev='/dev/disk/by-id/{the-partition-id}'/>
 +    <target dev='vdb' bus='virtio'/>
 +</disk>
 +</code>
 +This will make the host’s partition available in the guest as /dev/vdb (D:). After changing a domain’s config by hand, you have to reload the config by hand. Log in to your host and issue this command:
 +
 +  # virsh define /etc/libvirt/qemu/${YOUR_VM}.xml
 +  
 +  Domain YOUR_VM defined from /etc/libvirt/qemu/${YOUR_VM}.xml
 +  
 +===== Links =====
   * [[https://wiki.debian.org/KVM#Installation]]   * [[https://wiki.debian.org/KVM#Installation]]
  
linux/apps/kvm.1691324231.txt.gz · Last modified: by oscar