Libvirt/QEMU guest
From Gentoo Wiki
< Libvirt
Jump to:navigation
Jump to:search
This article covers libvirt and its creation of a virtual machine (VM) for use under the soft-emulation mode QEMU hypervisor Type-2, notably using virsh command.
The virsh command and its configuration toward the creation of an strict-emulation-mode virtual machine that an QEMU-capable operating system to be installed on.
Installation
Note
Use QEMU to install app-emulation/qemu and Libvirt to install app-emulation/libvirt. Once installed, return to this guide.
Use QEMU to install app-emulation/qemu and Libvirt to install app-emulation/libvirt. Once installed, return to this guide.
Verify system is capable of being a virtualization host.
root #
virt-host-validate
QEMU: Checking for hardware virtualization : PASS QEMU: Checking if device /dev/kvm exists : PASS QEMU: Checking if device /dev/kvm is accessible : PASS QEMU: Checking if device /dev/vhost-net exists : PASS QEMU: Checking if device /dev/net/tun exists : PASS QEMU: Checking for cgroup 'cpu' controller support : PASS QEMU: Checking for cgroup 'cpuacct' controller support : PASS QEMU: Checking for cgroup 'cpuset' controller support : PASS QEMU: Checking for cgroup 'memory' controller support : PASS QEMU: Checking for cgroup 'devices' controller support : PASS QEMU: Checking for cgroup 'blkio' controller support : PASS QEMU: Checking for device assignment IOMMU support : PASS QEMU: Checking if IOMMU is enabled by kernel : PASS QEMU: Checking for secure guest support : WARN (Unknown if this platform has Secure Guest support) CH: Checking for hardware virtualization : PASS CH: Checking if device /dev/kvm exists : PASS CH: Checking if device /dev/kvm is accessible : PASS
Usage
List virtual machines (domains)
root #
virsh list --all
Id Name State ------------------------------------- 1 gentoo running
Creating a virtual machine
Note
app-emulation/virt-manager includes
app-emulation/virt-manager includes
virt-installer
. Therefore, with only app-emulation/libvirt the VM xml must be created first, then either imported with virsh edit /path/to/vm.xml
or virsh define /path/to/vm.xml
Sample VM for Gentoo below. Note, view wiki code for full xml, as below does not view correctly...
<domain type='kvm'>
<seclabel type='dynamic' model='selinux'>
<baselabel>system_u:system_r:svirt_t:s0</baselabel>
</seclabel>
<name>gentoo</name>
<uuid>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</uuid>
<title>Gentoo VM</title>
<description>Gentoo Description Here</description>
<features>
<acpi/>
<smm state='on'/>
</features>
<os>
<type arch='x86_64' machine='pc-q35-3.0'>hvm</type>
<loader readonly='yes' secure='yes' type='pflash'>/usr/share/edk2-ovmf/OVMF_CODE.fd</loader>
<nvram template='/usr/share/edk2-ovmf/OVMF_VARS.fd'>/var/lib/libvirt/qemu/nvram/media_VARS.fd</nvram>
<boot dev='cdrom'/>
<boot dev='hd'/>
</os>
<vcpu>2</vcpu>
<memory unit='GiB'>6</memory>
<clock sync="localtime"/>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
'"`UNIQ--source-00000006-QINU`"'
<target dev='sda' bus='sata' tray='open'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
'"`UNIQ--source-00000008-QINU`"'
<target dev='vda' bus='virtio'/>
</disk>
<interface type='bridge'>
<mac address='XX:XX:XX:XX:XX:XX'/>
'"`UNIQ--source-0000000A-QINU`"'
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
<tartget port='0'/>
</serial>
<console type='pty'>
<tartget port='0'/>
</console>
<graphics type='vnc' port='-1' autoport='yes' passwd='password here' keymap='en-us'/>
</devices>
</domain>
root #
virsh define gentoo-vm.xml
Domain 'gentoo' defined from gentoo-vm.xml
root #
virsh list --all
Id Name State ------------------------ - gentoo shut off
Starting a virtual machine
root #
virsh start <vm-id>
Enabling autostart.
root #
virsh autostart <vm-id>
Shutdown a virtual machine
Graceful shutdown, similar to pressing the power button on a physical machine.
root #
virsh shutdown <vm-id>
Hard shutdown, similar to pulling the power cord on a physical machine.
root #
virsh destroy <vm-id>
See also
- Virtualization — the concept and technique that permits running software in an environment separate from a computer operating system.
- QEMU — a generic, open source hardware emulator and virtualization suite.
- QEMU/Front-ends — facilitate VM management and use
- Libvirt — a virtualization management toolkit.
- Libvirt/QEMU_networking — details the setup of Gentoo networking by Libvirt for use by guest containers and QEMU-based virtual machines.
- Virt-manager — desktop user interface for management of virtual machines and containers through the libvirt library
- Virt-manager/QEMU_guest — QEMU creation of a guest (VM or container)
- QEMU/Linux guest — describes the setup of a Gentoo Linux guest in QEMU using Gentoo bootable media.