https://wiki.archlinux.org/api.php?action=feedcontributions&user=Mohan43u&feedformat=atomArchWiki - User contributions [en]2024-03-28T14:47:12ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Libvirt&diff=448041Libvirt2016-08-26T11:11:14Z<p>Mohan43u: added fix to qemu path issue</p>
<hr />
<div>{{DISPLAYTITLE:libvirt}}<br />
[[Category:Virtualization]]<br />
[[ja:libvirt]]<br />
[[zh-CN:Libvirt]]<br />
[[zh-TW:Libvirt]]<br />
{{Related articles start}}<br />
{{Related|:Category:Hypervisors}}<br />
{{Related|:PCI passthrough via OVMF}}<br />
{{Related articles end}}<br />
<br />
Libvirt is collection of software that provides a convenient way to manage virtual machines and other virtualization functionality, such as storage and network interface management. These software pieces include a long term stable C API, a daemon (libvirtd), and a command line utility (virsh). A primary goal of libvirt is to provide a single way to manage multiple different virtualization providers/hypervisors, such as the [[QEMU|KVM/QEMU]], [[Xen]], [[LXC]], [http://openvz.org OpenVZ] or [[VirtualBox]] [[:Category:Hypervisors|hypervisors]] ([http://libvirt.org/drivers.html among others]).<br />
<br />
Some of the major libvirt features are:<br />
*'''VM management''': Various domain lifecycle operations such as start, stop, pause, save, restore, and migrate. Hotplug operations for many device types including disk and network interfaces, memory, and cpus.<br />
*'''Remote machine support''': All libvirt functionality is accessible on any machine running the libvirt daemon, including remote machines. A variety of network transports are supported for connecting remotely, with the simplest being SSH, which requires no extra explicit configuration.<br />
*'''Storage management''': Any host running the libvirt daemon can be used to manage various types of storage: create file images of various formats (qcow2, vmdk, raw, ...), mount NFS shares, enumerate existing LVM volume groups, create new LVM volume groups and logical volumes, partition raw disk devices, mount iSCSI shares, and much more.<br />
*'''Network interface management''': Any host running the libvirt daemon can be used to manage physical and logical network interfaces. Enumerate existing interfaces, as well as configure (and create) interfaces, bridges, vlans, and bond devices.<br />
*'''Virtual NAT and Route based networking''': Any host running the libvirt daemon can manage and create virtual networks. Libvirt virtual networks use firewall rules to act as a router, providing VMs transparent access to the host machines network.<br />
<br />
== Installation ==<br />
<br />
Because of its daemon/client architecture, libvirt needs only be installed on the machine which will host the virtualized system. Note that the server and client can be the same physical machine.<br />
<br />
=== Server ===<br />
<br />
[[Install]] the {{pkg|libvirt}} package, as well as at least one hypervisor:<br />
<br />
* The [http://libvirt.org/drvqemu.html libvirt KVM/QEMU driver] is the primary ''libvirt'' driver and if [[QEMU#Enabling_KVM|KVM is enabled]], fully virtualized, hardware accelerated guests will be available. See the [[QEMU]] article for more informations.<br />
<br />
* Other [http://libvirt.org/drivers.html supported hypervisors] include [[LXC]], [[VirtualBox]] and [[Xen]]. See the respective articles for installation instructions. With respect to {{ic|libvirtd}} installation note: <br />
** The [http://libvirt.org/drvlxc.html libvirt LXC driver] has no dependency on the [[LXC]] userspace tools provided by {{Pkg|lxc}}, therefore there is no need to install the package if planning on using the driver.<br />
** [[Xen]] support is available, but not by default. You need to use the [[ABS]] to modify {{Pkg|libvirt}}'s [[PKGBUILD]] and build it without the {{ic|--without-xen}} option. As VirtualBox in turn has no planned stable support for Xen, you might as well replace it with {{ic|--without-vbox}}.<br />
<br />
For network connectivity, install: <br />
<br />
* {{Pkg|ebtables}} '''and''' {{Pkg|dnsmasq}} for the [http://wiki.libvirt.org/page/VirtualNetworking#The_default_configuration default] NAT/DHCP networking.<br />
* {{Pkg|bridge-utils}} for bridged networking.<br />
* {{Pkg|openbsd-netcat}} for remote management over [[SSH]].<br />
<br />
=== Client ===<br />
<br />
The client is the user interface that will be used to manage and access the virtual machines.<br />
<br />
* ''virsh'' is a command line program for managing and configuring domains; it is included in the {{Pkg|libvirt}} package.<br />
* {{Pkg|virt-manager}} is a graphical user interface for managing virtual machines.<br />
* {{Pkg|virtviewer}} is a lightweight interface for interacting with the graphical display of virtualized guest OS.<br />
* {{Pkg|gnome-boxes}} is a simple GNOME 3 application to access remote or virtual systems.<br />
* {{AUR|virt-manager-qt5}}<br />
* {{AUR|libvirt-sandbox}} is an application sandbox toolkit.<br />
<br />
A list of libvirt-compatible software can be found [http://libvirt.org/apps.html here].<br />
<br />
== Configuration ==<br />
<br />
For '''''system'''''-level administration (i.e. global settings and image-''volume'' location), libvirt minimally requires [[#Set up authentication|setting up authorization]], and [[#Daemon|starting the daemon]].<br />
<br />
{{Note|For user-'''''session''''' administration, daemon setup and configuration is ''not'' required; authorization, however, is limited to local abilities; the front-end will launch a local instance of the '''libvirtd''' daemon.}}<br />
<br />
=== Set up authentication ===<br />
<br />
From [http://libvirt.org/auth.html#ACL_server_config libvirt: Connection authentication]:<br />
:The libvirt daemon allows the administrator to choose the authentication mechanisms used for client connections on each network socket independently. This is primarily controlled via the libvirt daemon master config file in {{ic|/etc/libvirt/libvirtd.conf}}. Each of the libvirt sockets can have its authentication mechanism configured independently. There is currently a choice of {{ic|none}}, {{ic|polkit}} and {{ic|sasl}}. <br />
<br />
Because {{Pkg|libvirt}} pulls {{Pkg|polkit}} as a dependency during installation, [[#Using polkit|polkit]] is used as the default value for the {{ic|unix_sock_auth}} parameter ([http://libvirt.org/auth.html#ACL_server_polkit source]). [[#Authenticate with file-based permissions|File-based permissions]] remain nevertheless available.<br />
<br />
==== Using polkit ====<br />
{{Note|A system reboot may be required before authenticating with {{ic|polkit}} works correctly.}}<br />
<br />
The ''libvirt'' daemon provides two [[Polkit#Actions|polkit actions]] in {{ic|/usr/share/polkit-1/actions/org.libvirt.unix.policy}}:<br />
* {{ic|org.libvirt.unix.manage}} for full management access (RW daemon socket), and<br />
* {{ic|org.libvirt.unix.monitor}} for monitoring only access (read-only socket).<br />
<br />
The default policy for the RW daemon socket will require to authenticate as an admin. This is akin to [[sudo]] auth, but does not require that the client application ultimately run as root. Default policy will still allow any application to connect to the RO socket.<br />
<br />
Arch defaults to consider anybody in the {{ic|wheel}} group as an administrator: this is defined in {{ic|/etc/polkit-1/rules.d/50-default.rules}} (see [[Polkit#Administrator identities]]). Therefore there is no need to create a new group and rule file '''if your user is a member of the {{ic|wheel}} group''': upon connection to the RW socket (e.g. via {{Pkg|virt-manager}}) you will be prompted for your user's password.<br />
<br />
{{Note|Prompting for a password relies on the presence of an [[Polkit#Authentication_agents|authentication agent]] on the system. Console users may face an issue with the default {{ic|pkttyagent}} agent which may or may not work properly.}}<br />
<br />
{{Tip|If you want to configure passwordless authentication, see [[Polkit#Bypass password prompt]].}}<br />
<br />
As of libvirt 1.2.16 (commit:[http://libvirt.org/git/?p=libvirt.git;a=commit;h=e94979e901517af9fdde358d7b7c92cc055dd50c]), members of the {{ic|libvirt}} group have passwordless access to the RW daemon socket by default. The easiest way to ensure your user has access is to ensure the libvirt group exists and they are a member of it. If you wish to change the group authorized to access the RW daemon socket to be the kvm group, create the following file:<br />
<br />
{{hc|/etc/polkit-1/rules.d/50-libvirt.rules|<nowiki><br />
/* Allow users in kvm group to manage the libvirt<br />
daemon without authentication */<br />
polkit.addRule(function(action, subject) {<br />
if (action.id == "org.libvirt.unix.manage" &&<br />
subject.isInGroup("kvm")) {<br />
return polkit.Result.YES;<br />
}<br />
});</nowiki><br />
}}<br />
<br />
Then [[Users_and_groups#Other_examples_of_user_management|add yourself]] to the {{ic|kvm}} group and relogin. Replace ''kvm'' with any group of your preference just make sure it exists and that your user is a member of it (see [[Users and groups]] for more information).<br />
<br />
Do not forget to relogin for group changes to take effect.<br />
<br />
==== Authenticate with file-based permissions ====<br />
<br />
To define file-based permissions for users in the ''libvirt'' group to manage virtual machines, uncomment and define:<br />
<br />
{{hc|/etc/libvirt/libvirtd.conf|<nowiki><br />
#unix_sock_group = "libvirt"<br />
#unix_sock_ro_perms = "0777" # set to 0770 to deny non-group libvirt users<br />
#unix_sock_rw_perms = "0770"<br />
#auth_unix_ro = "none"<br />
#auth_unix_rw = "none"<br />
</nowiki>}}<br />
<br />
While some guides mention changed permissions of certain libvirt directories to ease management, keep in mind permissions are lost on package update. To edit these system directories, root user is expected.<br />
<br />
=== Daemon ===<br />
<br />
[[Start]] both {{ic|libvirtd.service}} and {{ic|virtlogd.service}}. Optionally [[enable]] {{ic|libvirtd.service}}. There is no need to enable {{ic|virtlogd.service}}, since {{ic|libvirtd.service}}, when enabled, also enables the {{ic|virtlogd.socket}} and {{ic|virtlockd.socket}} [[Systemd#Using_units|units]].<br />
<br />
=== Unencrypt TCP/IP sockets ===<br />
<br />
{{Warning|This method is used to help remote domain, connection speed for trusted networks. This is the least secure connection method. This should ''only'' be used for testing or use over a secure, private, and trusted network. SASL is not enabled here, so all TCP traffic is ''cleartext''. For real world ''always'' use enable SASL.}}<br />
<br />
Edit {{ic|/etc/libvirt/libvirtd.conf}}:<br />
{{hc|/etc/libvirt/libvirtd.conf|<nowiki><br />
listen_tls = 0<br />
listen_tcp = 1<br />
auth_tcp=none<br />
</nowiki>}}<br />
<br />
It is also necessary to start the server in listening mode by editing {{ic|/etc/conf.d/libvirtd}}:<br />
<br />
{{hc|/etc/conf.d/libvirtd|2=LIBVIRTD_ARGS="--listen"}}<br />
<br />
=== Access virtual machines using their hostnames ===<br />
<br />
For host access to guests on non-isolated, bridged networks, enable the {{ic|libvirt}} NSS module provided by {{Pkg|libvirt}}.<br />
<br />
Edit {{ic|/etc/nsswitch.conf}}:<br />
{{hc|/etc/nsswitch.conf|<nowiki><br />
hosts: files libvirt dns myhostname<br />
</nowiki>}}<br />
<br />
{{Note|While commands such as {{ic|ping}} and {{ic|ssh}} should work with virtual machine hostnames, commands such as {{ic|host}} and {{ic|nslookup}} may fail or produce unexpected results because they rely on DNS. Use {{ic|getent hosts <vm-hostname>}} instead.}}<br />
<br />
== Test ==<br />
<br />
To test if libvirt is working properly on a ''system'' level:<br />
<br />
$ virsh -c qemu:///system<br />
<br />
To test if libvirt is working properly for a user-''session'':<br />
<br />
$ virsh -c qemu:///session<br />
<br />
== Management ==<br />
<br />
Libvirt management is done mostly with three tools: {{Pkg|virt-manager}} (GUI), {{ic|virsh}}, and {{ic|guestfish}} (which is part of {{AUR|libguestfs}}).<br />
<br />
=== virsh ===<br />
<br />
The virsh program is for managing guest ''domains'' (virtual machines) and works well for scripting, virtualization administration. Though most virsh commands require root privileges to run due to the communication channels used to talk to the hypervisor, typical management, creation, and running of domains (like that done with VirtualBox) can be done as a regular user.<br />
<br />
Virsh includes an interactive terminal that can be entered if no commands are passed (options are allowed though): {{ic|virsh}}. The interactive terminal has support for tab completion.<br />
<br />
From the command line:<br />
<br />
$ virsh [option] <command> [argument]...<br />
<br />
From the interactive terminal:<br />
<br />
virsh # <command> [argument]...<br />
<br />
Help is available:<br />
<br />
$ virsh help [option*] or [group-keyword*]<br />
<br />
=== Storage pools ===<br />
<br />
A pool is a location where storage ''volumes'' can be kept. What libvirt defines as ''volumes'' others may define as "virtual disks" or "virtual machine images". Pool locations may be a directory, a network filesystem, or partition (this includes a [[LVM]]). Pools can be toggled active or inactive and allocated for space.<br />
<br />
On the ''system''-level, {{ic|/var/lib/libvirt/images/}} will be activated by default; on a user-''session'', {{ic|virt-manager}} creates {{ic|$HOME/VirtualMachines}}.<br />
<br />
Print active and inactive storage pools:<br />
<br />
$ virsh pool-list --all<br />
<br />
==== Create a new pool using virsh ====<br />
<br />
If wanted to ''add'' a storage pool, here are examples of the command form, adding a directory, and adding a LVM volume:<br />
<br />
$ virsh pool-define-as name type [source-host] [source-path] [source-dev] [source-name] [<target>] [--source-format format]<br />
$ virsh pool-define-as ''poolname'' dir - - - - /home/''username''/.local/libvirt/images<br />
$ virsh pool-define-as ''poolname'' fs - - ''/dev/vg0/images'' - ''mntpoint''<br />
<br />
The above command defines the information for the pool, to build it:<br />
<br />
$ virsh pool-build ''poolname''<br />
$ virsh pool-start ''poolname''<br />
$ virsh pool-autostart ''poolname''<br />
<br />
To remove it:<br />
<br />
$ virsh pool-undefine ''poolname''<br />
<br />
{{Tip|For LVM storage pools:<br />
* It is a good practice to dedicate a volume group to the storage pool only. <br />
* Choose a LVM volume group that differs from the pool name, otherwise when the storage pool is deleted the LVM group will be too.<br />
}}<br />
<br />
==== Create a new pool using virt-manager ====<br />
<br />
First, connect to a hypervisor (e.g. QEMU/KVM ''system'', or user-''session''). Then, right-click on a connection and select ''Details''; select the ''Storage'' tab, push the ''+'' button on the lower-left, and follow the wizard.<br />
<br />
=== Storage volumes ===<br />
<br />
Once the pool has been created, volumes can be created inside the pool. ''If building a new domain (virtual machine), this step can be skipped as a volume can be created in the domain creation process.''<br />
<br />
==== Create a new volume with virsh ====<br />
<br />
Create volume, list volumes, resize, and delete:<br />
$ virsh vol-create-as ''poolname'' ''volumename'' 10GiB --format aw|bochs|raw|qcow|qcow2|vmdk<br />
$ virsh vol-upload --pool ''poolname'' ''volumename'' ''volumepath''<br />
$ virsh vol-list ''poolname''<br />
$ virsh vol-resize --pool ''poolname'' ''volumename'' 12GiB<br />
$ virsh vol-delete --pool ''poolname'' ''volumename''<br />
$ virsh vol-dumpxml --pool ''poolname'' ''volumename'' # for details.<br />
<br />
==== virt-manager backing store type bug ====<br />
<br />
On newer versions of {{ic|virt-manager}} you can now specify a backing store to use when creating a new disk. This is very useful, in that you can have new domains be based on base images saving you both time and disk space when provisioning new virtual systems. There is a bug (https://bugzilla.redhat.com/show_bug.cgi?id=1235406) in the current version of {{ic|virt-manager}} which causes {{ic|virt-manager}} to choose the wrong type of the backing image in the case where the backing image is a {{ic|qcow2}} type. In this case, it will errantly pick the backing type as {{ic|raw}}. This will cause the new image to be unable to read from the backing store, and effectively remove the utility of having a backing store at all.<br />
<br />
There is a workaround for this issue. {{ic|qemu-img}} has long been able to do this operation directly. If you wish to have a backing store for your new domain before this bug is fixed, you may use the following command.<br />
<br />
$ qemu-img create -f qcow2 -o backing_file=<path to backing image>,backing_fmt=qcow2 <disk name> <disk size><br />
<br />
Then you can use this image as the base for your new domain and it will use the backing store as a COW volume saving you time and disk space.<br />
<br />
=== Domains ===<br />
<br />
Virtual machines are called ''domains''. If working from the command line, use {{ic|virsh}} to list, create, pause, shutdown domains, etc. {{ic|virt-viewer}} can be used to view domains started with {{ic|virsh}}. Creation of domains is typically done either graphically with {{ic|virt-manager}} or with {{ic|virt-install}} (a command line program that is part of the {{pkg|virt-manager}} package).<br />
<br />
Creating a new domain typically involves using some installation media, such as an {{ic|.iso}} from the storage pool or an optical drive.<br />
<br />
Print active and inactive domains:<br />
<br />
# virsh list --all<br />
<br />
{{note|[[SELinux]] has a built-in exemption for libvirt that allows volumes in {{ic|/var/lib/libvirt/images/}} to be accessed. If using SELinux and there are issues with the volumes, ensure that volumes are in that directory, or ensure that other storage pools are correctly labeled.}}<br />
<br />
==== Create a new domain using virt-install ====<br />
<br />
For an extremely detailed domain (virtual machine) setup, it is easier to [[#Create a new domain using virt-manager]]. However, basics can easily be done with {{ic|virt-install}} and still run quite well. Minimum specifications are {{ic|--name}}, {{ic|--memory}}, guest storage ({{ic|--disk}}, {{ic|--filesystem}}, or {{ic|--nodisks}}), and an install method (generally an {{ic|.iso}} or CD). See {{ic|man virt-install}} for more details and information about unlisted options.<br />
<br />
Arch Linux install (two GiB, qcow2 format volume create; user-networking):<br />
<br />
$ virt-install \<br />
--name arch-linux_testing \<br />
--memory 1024 \ <br />
--vcpus=2,maxvcpus=4 \<br />
--cpu host \<br />
--cdrom $HOME/Downloads/arch-linux_install.iso \<br />
--disk size=2,format=qcow2 \<br />
--network user \<br />
--virt-type kvm<br />
<br />
Fedora testing (Xen hypervisor, non-default pool, do not originally view):<br />
<br />
$ virt-install \<br />
--connect xen:/// \<br />
--name fedora-testing \<br />
--memory 2048 \<br />
--vcpus=2 \<br />
--cpu=host \<br />
--cdrom /tmp/fedora20_x84-64.iso \<br />
--os-type=linux --os-variant=fedora20 \<br />
--disk pool=testing,size=4 \<br />
--network bridge=br0 \<br />
--graphics=vnc \<br />
--noautoconsole<br />
$ virt-viewer --connect xen:/// fedora-testing<br />
<br />
Windows:<br />
<br />
$ virt-install \<br />
--name=windows7 \<br />
--memory 2048 \<br />
--cdrom /dev/sr0 \<br />
--os-variant=win7 \<br />
--disk /mnt/storage/domains/windows7.qcow2,size=20GiB \<br />
--network network=vm-net \<br />
--graphics spice<br />
<br />
{{Tip|Run {{ic|1=osinfo-query --fields=name,short-id,version os}} to get argument for {{ic|--os-variant}}; this will help define some specifications for the domain. However, {{ic|--memory}} and {{ic|--disk}} will need to be entered; one can look within the appropriate {{ic|/usr/share/libosinfo/db/oses/''os''.xml}} if needing these specifications. After installing, it will likely be preferable to install the [http://www.spice-space.org/download.html Spice Guest Tools] that include the [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Mounting_the_image_with_virt_manager.html VirtIO drivers]. For a Windows VirtIO network driver there is also {{Aur|virtio-win}}. These drivers are referenced by a {{ic|1=<model type='virtio' />}} in the guest's {{ic|.xml}} configuration section for the device. A bit more information can also be found on the [[QEMU#Preparing_a_Windows_guest|QEMU article]].}}<br />
<br />
Import existing volume:<br />
<br />
$ virt-install \<br />
--name demo \<br />
--memory 512 \<br />
--disk /home/user/VMs/mydisk.img \<br />
--import<br />
<br />
==== Create a new domain using virt-manager ====<br />
<br />
First, connect to the hypervisor (e.g. QEMU/KVM ''system'' or user ''session''), right click on a connection and select ''New'', and follow the wizard.<br />
<br />
* On the ''fourth step'', de-selecting ''Allocate entire disk now'' will make setup quicker and can save disk space in the interum; ''however'', it may cause volume fragmentation over time.<br />
* On the ''fifth step'', open ''Advanced options'' and make sure that ''Virt Type'' is set to ''kvm'' (this is usually the preferred method). If additional hardware setup is required, select the ''Customize configuration before install'' option.<br />
<br />
==== Manage a domain ====<br />
<br />
Start a domain:<br />
<br />
$ virsh start ''domain''<br />
$ virt-viewer --connect qemu:///session ''domain''<br />
<br />
Gracefully attempt to shutdown a domain; force off a domain:<br />
<br />
$ virsh shutdown ''domain''<br />
$ virsh destroy ''domain''<br />
<br />
Autostart domain on libvirtd start:<br />
<br />
$ virsh autostart ''domain''<br />
$ virsh autostart ''domain'' --disable<br />
<br />
Shutdown domain on host shutdown:<br />
<br />
: Running domains can be automatically suspended/shutdown at host shutdown using the {{ic|libvirt-guests.service}} systemd service. This same service will resume/startup the suspended/shutdown domain automatically at host startup. Read {{ic|/etc/conf.d/libvirt-guests}} for service options.<br />
<br />
Edit a domain's XML configuration:<br />
<br />
$ virsh edit ''domain''<br />
<br />
{{note|Virtual Machines started directly by QEMU are not managable by libvirt tools.}}<br />
<br />
=== Networks ===<br />
<br />
A [https://jamielinux.com/docs/libvirt-networking-handbook/ decent overview of libvirt networking].<br />
<br />
By default, when the {{ic|libvirtd}} systemd service is started, a NAT bridge is created called ''default'' to allow external network connectivity (warning see: [[#"default" network bug]]{{Broken section link}}). For other network connectivity needs, four network types exist that can be created to connect a domain to:<br />
<br />
* bridge — a virtual device; shares data directly with a physical interface. Use this if the host has ''static'' networking, it does not need to connect other domains, the domain requires full inbound and outbound trafficking, and the domain is running on a ''system''-level. See [[Network bridge]] on how to add a bridge additional to the default one. After creation, it needs to be specified in the respective guest's {{ic|.xml}} configuration file. <br />
* network — a virtual network; has ability to share with other domains. Use a virtual network if the host has ''dynamic'' networking (e.g. NetworkManager), or using wireless.<br />
* macvtap — connect directly to a host physical interface.<br />
* user — local ability networking. Use this only for a user ''session''.<br />
<br />
{{ic|virsh}} has the ability to create networking with numerous options for most users, however, it is easier to create network connectivity with a graphic user interface (like {{ic|virt-manager}}), or to do so on [[#Create a new domain using virt-install|creation with virt-install]].<br />
<br />
{{note|libvirt handles DHCP and DNS with {{pkg|dnsmasq}}, launching a separate instance for every virtual network. It also adds iptables rules for proper routing, and enables the {{ic|ip_forward}} kernel parameter.}}<br />
<br />
=== Snapshots ===<br />
<br />
Snapshots take the disk, memory, and device state of a domain at a point-of-time, and save it for future use. They have many uses, from saving a "clean" copy of an OS image to saving a domain's state before a potentially destructive operation. Snapshots are identified with a unique name.<br />
<br />
Snapshots are saved within the volume itself and the volume must be the format: qcow2 or raw. Snapshots use deltas so they have the potentiality to not take much space.<br />
<br />
==== Create a snapshot ====<br />
<br />
{{Out of date|Some of this data appears to be dated.}}<br />
<br />
Once a snapshot is taken it is saved as a new block device and the original snapshot is taken offline. Snapshots can be chosen from and also merged into another (even without shutting down the domain).<br />
<br />
Print a running domain's volumes (running domains can be printed with {{ic|virsh list}}):<br />
<br />
{{hc|# virsh domblklist ''domain''|<nowiki><br />
Target Source<br />
------------------------------------------------<br />
vda /vms/domain.img<br />
</nowiki>}}<br />
<br />
To see a volume's physical properties:<br />
<br />
{{hc|# qemu-img info /vms/domain.img|<nowiki><br />
image: /vms/domain.img<br />
file format: qcow2<br />
virtual size: 50G (53687091200 bytes)<br />
disk size: 2.1G<br />
cluster_size: 65536<br />
</nowiki>}}<br />
<br />
Create a disk-only snapshot (the option {{ic|--atomic}} will prevent the volume from being modified if snapshot creation fails):<br />
<br />
# virsh snapshot-create-as ''domain'' snapshot1 --disk-only --atomic<br />
<br />
List snapshots:<br />
<br />
{{hc|# virsh snapshot-list ''domain''|<nowiki><br />
Name Creation Time State<br />
------------------------------------------------------------<br />
snapshot1 2012-10-21 17:12:57 -0700 disk-snapshot<br />
</nowiki>}}<br />
<br />
One can they copy the original image with {{ic|1=cp --sparse=true}} or {{ic|rsync -S}} and then merge the the original back into snapshot:<br />
<br />
# virsh blockpull --domain ''domain'' --path /vms/''domain''.snapshot1<br />
<br />
{{ic|domain.snapshot1}} becomes a new volume. After this is done the original volume ({{ic|domain.img}} and snapshot metadata can be deleted. The {{ic|virsh blockcommit}} would work opposite to {{ic|blockpull}} but it seems to be currently under development (including {{ic|snapshot-revert feature}}, scheduled to be released sometime next year.<br />
<br />
=== Other management ===<br />
<br />
Connect to non-default hypervisor:<br />
<br />
$ virsh --connect xen:///<br />
virsh # uri<br />
xen:///<br />
<br />
Connect to the QEMU hypervisor over SSH; and the same with logging:<br />
<br />
$ virsh --connect qemu+ssh://''username''@''host''/system<br />
$ LIBVIRT_DEBUG=1 virsh --connect qemu+ssh://''username''@''host''/system<br />
<br />
Connect a graphic console over SSH:<br />
<br />
$ virt-viewer --connect qemu+ssh://''username''@''host''/system ''domain''<br />
$ virt-manager --connect qemu+ssh://''username''@''host''/system ''domain''<br />
<br />
{{Note|If you are having problems connecting to a remote RHEL server (or anything other than Arch, really), try the two workarounds mentioned in {{bug|30748}} and {{bug|22068}}.}}<br />
<br />
Connect to the VirtualBox hypervisor (''VirtualBox support in libvirt is not stable yet and may cause libvirtd to crash''):<br />
<br />
$ virsh --connect vbox:///system<br />
<br />
Network configurations:<br />
<br />
$ virsh -c qemu:///system net-list --all<br />
$ virsh -c qemu:///system net-dumpxml default<br />
<br />
== Python connectivity code ==<br />
<br />
The {{Pkg|libvirt-python}} package provides a {{Pkg|python2}} API in {{ic|/usr/lib/python2.7/site-packages/libvirt.py}}.<br />
<br />
General examples are given in {{ic|/usr/share/doc/libvirt-python-''your_libvirt_version''/examples/}}<br />
<br />
Unofficial example using {{Pkg|qemu}} and {{Pkg|openssh}}:<br />
<br />
#! /usr/bin/env python2<br />
# -*- coding: utf-8 -*-<br />
import socket<br />
import sys<br />
import libvirt<br />
if (__name__ == "__main__"):<br />
<nowiki>conn = libvirt.open("qemu+ssh://xxx/system")</nowiki><br />
print "Trying to find node on xxx"<br />
domains = conn.listDomainsID()<br />
for domainID in domains:<br />
domConnect = conn.lookupByID(domainID)<br />
if domConnect.name() == 'xxx-node':<br />
print "Found shared node on xxx with ID " + str(domainID)<br />
domServ = domConnect<br />
break<br />
<br />
== UEFI Support ==<br />
<br />
{{Accuracy|Packages from different distribution. We have {{pkg|ovmf}}.}}<br />
<br />
For UEFI support you need to install the OVMF packages [https://www.kraxel.org/repos/jenkins/edk2/ Gerd Hoffman's repository].<br />
<br />
Download and extract edk2.git-ovmf-x64 to /usr.<br />
<br />
[[Install]] {{Pkg|rpmextract}}.<br />
<br />
{{bc|# rpmextract.sh edk2.git-ovmf-x64-0-20150223.b877.ga8577b3.noarch.rpm<br />
# cp -R ./usr/share/* /usr/share}}<br />
<br />
Then you will have to source the OVMF files in {{ic|1=/etc/libvirt/qemu.conf}}.<br />
Set the following details:<br />
nvram = [<br />
"/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd:/usr/share/edk2.git/ovmf-x64/OVMF_VARS-pure-efi.fd",<br />
]<br />
Then restart libvirtd:<br />
systemctl restart libvirtd.service<br />
<br />
= TroubleShooting =<br />
<br />
==== Qemu domains not available ====<br />
<br />
{{pkg|qemu}} update 2.6.0-1 breaks qemu domain configuration because domain xml files (available in /etc/libvirt/qemu/ directory) contains emulator path as /usr/sbin/qemu-system-x86_64 but update 2.6.0-1 put qemu-system-x86_64 in /usr/bin/ directory. replacing the path in xml files will fix this issue.<br />
<br />
== See also ==<br />
<br />
* [http://libvirt.org/drvqemu.html Official libvirt web site]<br />
* [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/index.html Red Hat Virtualization Deployment and Administration Guide]<br />
* [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Tuning_and_Optimization_Guide/index.html Red Hat Virtualization Tuning and Optimization Guide]<br />
* [http://docs.slackware.com/howtos:general_admin:kvm_libvirt Slackware KVM and libvirt]<br />
* [http://www-01.ibm.com/support/knowledgecenter/linuxonibm/liaat/liaatkvm.htm IBM KVM]<br />
* [https://jamielinux.com/docs/libvirt-networking-handbook/ libvirt Networking Handbook]</div>Mohan43u