Sunday, November 8, 2015

Virtualization: virsh basic commands


The 
virsh program is the main interface for managing virsh guest domains (or virtual machines). The program can be used to create, pause, and shutdown domains. It can also be used to list current domains. On my PC, I started off with managing new VMs using the Virtual Machine Manager GUI but when it comes to managing VMs on a headless remote server, its easier done using the text-only virsh. I find creating a fresh guest VM is the easiest using a modified xml dump from an existing VM(if one exists)

Following are some basic virsh commands I've been used to using over time-

To execute the following commands 'libvirtd' daemon should be running.

1. To see what guests are there on a particular host
virsh list 
virsh list --all

2. To define the guest
virsh define

3. To start the guest
virsh start
virsh console
or
virsh start --console

4. To shutdown the guest
virsh shutdown
forcefully
virsh destroy

5. Get the libvirt xml
virsh dumpxml > filename.xml

6. Edit libvirt xml, with this command if there are any changes then no need to 'undefine' and 'define' the domain
virsh edit

7. To undefine the guest, CAUTION: if you want your domain back, then have domainxml back up.
virsh undefine


Cues to what basic changes are to be made to create a new VM from an existing xml-dump can be taken from the following sample xml dump:
Changes to be made are highlighted (name and UUID should be changed since they should be unique on a host, UUID tag can also be omitted altogether and a fresh one will be allotted; network highlights should match):
http://pastebin.com/08032vEC

That's all in this primer! More on virsh and other domain commands can be read from virsh man page.

No comments:

Post a Comment

Featured Post

interviewBit Medium: Palindrome Partitioning II

Problem Name:  Palindrome Partitioning II Problem Description : https://www.interviewbit.com/problems/palindrome-partitioning-ii/ Problem Ap...