Fedora libvirt family tools for virtualization solution

Fedora 22 to current:

For Fedora 21 or previous installations, replace "dnf" with "yum." Yum is now a deprecated package manager and is replaced by DNF on installations of Fedora 22 and onward.

su -c "dnf install @virtualization"

This will install below Mandatory and Default packages.

$ dnf groupinfo virtualization

Group: Virtualisation
 Group-Id: virtualization
 Description: These packages provide a virtualisation environment.
 Mandatory Packages:
   =virt-install
 Default Packages:
   =libvirt-daemon-config-network
   =libvirt-daemon-kvm
   =qemu-kvm
   =virt-manager
   =virt-viewer
 Optional Packages:
   guestfs-browser
   libguestfs-tools
   python-libguestfs
   virt-top

This will install Mandatory, Default and Optional Packages.

su -c "dnf group install with-optional virtualization"

To start the service:

su -c "systemctl start libvirtd"

To start the service on boot:

su -c "systemctl enable libvirtd"

Verify that the kvm kernel modules were properly loaded:

$ lsmod | grep kvm
kvm_amd                55563  0 
kvm                   419458  1 kvm_amd

If that command did not list kvm_intel or kvm_amd, KVM is not properly configured. See Ensuring system is KVM capable for troubleshooting tips.

Networking Support

By default libvirt will create a private network for your guests on the host machine. This private network will use a 192.168.x.x subnet and not be reachable directly from the network the host machine is on, but virtual guests can use the host machine as a gateway and can connect out via it. If you need to provide services on your guests that are reachable via other machines on your host network you can use iptables DNAT rules to forward in specific ports, or you can setup a Bridged env.

Creating a Fedora guest

The installation of Fedora guests using anaconda is supported. The installation can be started on the command line via the virt-install program or in the GUI program virt-manager.

Creating a guest with virt-install

virt-install is a command line based tool for creating virtualized guests. Refer to http://virt-tools.org/learning/install-with-command-line/ for understanding how to use this tool. Execute virt-install --help for command line help.

virt-install can use kickstart files, for example virt-install -x ks=kickstart-file-name.ks.

If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, a text installer will appear. Proceed with the fedora installation.

Creating a guest with virt-manager

Start the GUI Virtual Machine Manager by selecting it from the "Applications–>System Tools" menu, or by running the following command:

su -c "virt-manager"

If you encounter an error along the lines of "Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash", trying running virt-manager not as root (without the su -c). The GUI will prompt for the root password.

  1. Open a connection to a hypervisor by choosing File–>Add connection…
  2. Choose "qemu" for KVM, or "Xen" for Xen.
  3. Choose "local" or select a method to connect to a remote hypervisor
  4. After a connection is opened, click the new icon next to the hypervisor, or right click on the active hypervisor and select "New" (Note – the new icon is going to be improved to make it easier to see)
  5. A wizard will present the same questions as appear with the virt-install command-line utility (see descriptions above). The wizard assumes that a graphical installation is desired and does not prompt for this option.
  6. On the last page of the wizard there is a "Finish" button. When this is clicked, the guest OS is provisioned. After a few moments a VNC window should appear. Proceed with the installation as normal.

Managing guests with virsh

The virsh command line utility that allows you to manage virtual machines. Guests can be managed on the command line with the virsh utility. The virsh utility is built around the libvirt management APIl:

  • virsh has a stable set of commands whose syntax and semantics are preserved across updates to the underlying virtualization platform.
  • virsh can be used as an unprivileged user for read-only operations (e.g. listing domains, listing domain statistics).
  • virsh can manage domains running under Xen, Qemu/KVM, esx or other backends with no perceptible difference to the user

To start a virtual machine:

su -c "virsh create <name of virtual machine>"

To list the virtual machines currently running:

su -c "virsh list"

To list all virtual machines, running or not:

su -c "virsh list --all"

To gracefully power off a guest:

su -c "virsh shutdown <virtual machine (name | id | uuid)>"

To non gracefully power off a guest:

su -c "virsh destroy <virtual machine (name | id | uuid)>"

To save a snapshot of the machine to a file:

su -c "virsh save <virtual machine (name | id | uuid)> <filename>"

To restore a previously saved snapshot:

su -c "virsh restore <filename>"

To export the configuration file of a virtual machine:

su -c "virsh dumpxml <virtual machine (name | id | uuid)"

For a complete list of commands available for use with virsh:

su -c "virsh help"

Credits

Linux list a KVM vm guest using virsh command

Use the following command to list a kvm vm on Linux based server:
# virsh list

To list inactive & active VM/domains:
# virsh list --all
Here are all other options:

Option Description
--inactive list inactive domains
--all list inactive & active domains
--transient list transient domains
--persistent list persistent domains
--with-snapshot list domains with existing snapshot
--without-snapshot list domains without a snapshot
--state-running list domains in running state
--state-paused list domains in paused state
--state-shutoff list domains in shutoff state
--state-other list domains in other states
--autostart list domains with autostart enabled
--no-autostart list domains with autostart disabled
--with-managed-save list domains with managed save state
--without-managed-save list domains without managed save
--uuid list uuid’s only
--name list domain names only
--table list table (default)
--managed-save mark inactive domains with managed save state
--title show domain title

Credits

KVM (virt-manager) take a snapshot of qcow2 disk.

Take A Snapshot

 To list a kvm vm on Linux based server [VM ID], more info

virsh list 

If your KVM guests are now running with Qcow2 disk images, you can take an internal snapshot of the guest with the following command:

virsh snapshot-create [VM ID]  

Alternatively, you can create a file with the following contents

<domainsnapshot>
    <name>Name for the snapshot</name>
    <description>Description for the snapshot</description>
</domainsnapshot>

Then pass it to the snapshotting command.

virsh snapshot-create [VM ID] [filepath]  

You can take snapshots of guests whilst they are running. Whilst the snapshot is being taken, the guest will be "paused". The "state" of the guest is also saved.

List Snapshots
One can list a virtual machine's snapshots with

sudo virsh snapshot-list [VM ID]  

Which will output something like:

 Name                 Creation Time             State
————————————————————
 1422179589           2015-01-25 09:53:09 +0000 running

Restore Snapshot

If you want to "revert", "go to", or "restore" a previous snapshot, then execute the following command:

virsh snapshot-revert [VM ID] [Snapshot Name]  

Delete Snapshot

virsh snapshot-delete [VM ID] [Snapshot Name] 

Credits | Tips