Objective

The following instruction will explain how to completely remove KVM-based Virtual Machines on Redhat Linux from command line using virsh command.

Operating System and Software Versions

  • Operating System: - Redhat 7.3
  • Software: - libvirtd (libvirt) 2.0.0

Requirements

Privileged access to your Redhat Linux installation will be required.

Difficulty

EASY

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Obtain Virtual Machine's name

First obtain domain name of the virtual machine you wish to remove. This can be done by using a following linux command:
# virsh list
 Id    Name                           State
----------------------------------------------------
 3     linuxconfig                    running

Destroy Virtual machine

Once we have Virtual Machine name we wish to delete we first disassociate it from Virtual Manager:
# virsh destroy linuxconfig
Domain linuxconfig destroyed
After execution of the above command the virtual machine no longer exists within virtual manager inventory:
# virsh list
 Id    Name                           State
----------------------------------------------------

Undefine Virtual Machine

After destroying the above Virtual Machine its XML configuration file within /etc/libvirt/qemu directory and virtual disk(s) located in /var/lib/libvirt/images still exists.

To completely remove virtual machine and all its associated files we need to execute:
# virsh undefine linuxconfig --remove-all-storage
Domain linuxconfig has been undefined
Volume 'vda'(/var/lib/libvirt/images/linuxconfig.img) removed.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: