Up and Running with KVM Ubuntu Style: Part Two

Continue your dive into KVM virtualization, Ubuntu style.

Last week, you tested your Ubuntu system for KVM compatibility, installed KVM on your host server and installed a guest operating system into a virtual machine. This week you’ll learn some KVM-oriented terminology and will continue your dive into KVM Ubuntu style by working with virtual machines via the virsh command.

Terminology Basics

Every technology, and sub-technology, has its own jargon and virtualization falls in line with this jargonized culture. You need to learn the KVM’s language so that you can understand the documentation and discuss KVM with other users in a meaningful way.

KVM Terminology

  • Domain – A virtual machine (VM).
  • State – VM Status: running, paused, shut off, crashed, dying, blocked.
  • State-file – A snapshot file.
  • Destroy – Shutdown a Domain (VM) ungracefully (i.e., Pull the plug).
  • Autostart – Setup a Domain to start at host boot time.
  • Undefine – Removes the Domain definition.

Virtual Machine Management

Most of your command line interaction with KVM will occur through virsh, the management user interface as it’s called. It’s really the KVM virtualization shell used to interact with your virtual machines (VMs). Virsh works interactively, as a shell, or in single non-interactive command mode, which makes it easier to include in other scripts so that you can create automated applications.

Before beginning this discussion, some assumptions have to be made. One is that you have your fully functioning KVM host system running as described in Part One of this series. And, you have one or more “disposable” VMs with which you can work without any fear of data loss or destruction of valuable computing resources.

Turn your focus now to a VM that is in a shut off or powered down state so that you can start using a few basic virshcommands. Virsh has the general syntax of:

sudo virsh <command> <domain> [OPTIONS]

To start a VM, issue the following command. Replace “Ubuntu_10.04″ with the name of your target VM. This command will power on and boot your VM. Note that you won’t see the console when you use this command.

 $ sudo virsh start Ubuntu_10.04

Connecting to uri: qemu:///system
Domain Ubuntu_10.04 started

You may gracefully shutdown a running VM with the shutdown command. This is the appropriate method for shutting down a VM. The other acceptable option is to issue the sudo halt -p command when logged into the VM.

$ sudo virsh shutdown Ubuntu_10.04
Connecting to uri: qemu:///system
Domain Ubuntu_10.04 is being shutdown

If your systems never shutdown or don’t respond to the shutdown command, login to the VM and install the acpid package. That will solve the problem. The next command is the destroy command. Destroy powers off the system as if you unplugged it from its power source. A power loss like that isn’t good for a physical system or a virtual one. Reserve it for when you must kill a system quickly and without regard for data corruption. Destroy does not remove the VM’s definition file or disk file(s).

$ sudo virsh destroy Ubuntu_10.04
Connecting to uri: qemu:///system
Domain Ubuntu_10.04_3 destroyed

Advanced Domain Management

To clone a VM, you’ll have to abandon virsh for the virt-clone tool. Minimally, you have to supply the VM name that you’re cloning, which is called the source or original. You have to provide the new VM name and the disk filename(s) that you want to clone.

$ sudo virt-clone -o Ubuntu_10.04 -n Ubuntu_10.04_2 -f /VM/Ubuntu_10.04_2/DISK1.img

Cloning from /VM/Ubuntu_10.04/DISK1.img to /VM/Ubuntu_10.04_2/DISK1.img

Cloning domain...       19% |====        | 2.1 GB  2:29 ETA

An example of a VM clone with more than one disk, look like:

$ sudo virt-clone -o Ubuntu_10.04 -n Ubuntu_10.04_2 \
-f /VM/Ubuntu_10.04_2/DISK1.img -f /VM/Ubuntu_10.04_2/DISK2.img

To remove a VM (Guest domain), shut down the VM. You can use the virsh destroy command, since you don’t care that the system will shutdown ungracefully.

$ sudo virsh destroy Ubuntu_10.04_2

Check the status of your VMs with the following command.

$ sudo virsh list --all

Connecting to uri: qemu:///system
 Id Name                 State
  - Ubuntu_10.04         shut off
  - Ubuntu_10.04_2       shut off

Undefine the domain. This means that you’re removing the domain definition from KVM.

 $ sudo virsh undefine Ubuntu_10.04_2

Now, you can remove the VM’s directory and disk file(s). Neither destroy nor undefine removes the domain’s directory or disk file(s). You have to explicitly remove them from your filesystem.

$ sudo rm -rf /VM/Ubuntu_10.04_2

The Ubuntu_10.04_2 VM is now removed from your system. If you decide that you want it back, you’ll have to restore from backup. When you perform a backup, save the XML descriptor file under /etc/libvirt/qemu that bears the same name as your VM and the associated disk file(s) for your VM.

Virsh gives you a powerful interface with which you can use to manage your VMs. You can use virsh commands in scripts or call them from other programming languages to help you develop automated or web-based virtualization services. You may access help at any time by using the virsh help command for the entire list of commands. If you’re using libvirtd version < 0.6.3, upgrade to a newer version to enjoy a more functional list of virsh commands.

Next time, you’ll enjoy the third and final article in this Ubuntu-flavored KVM series where you’ll learn, finally, how to manage your VMs with the graphical application virt-manager and gather a few troubleshooting tips to boot.

Comments on "Up and Running with KVM Ubuntu Style: Part Two"

The information talked about in the post are some of the best obtainable.

YRpraU jrfvjovieajy, [url=http://ctugtwumfvor.com/]ctugtwumfvor[/url], [link=http://uptatxjezazk.com/]uptatxjezazk[/link], http://atnwnejjsrck.com/

Although internet sites we backlink to below are considerably not connected to ours, we feel they’re essentially really worth a go by way of, so possess a look.

Thank you for the good writeup. It if truth be told used to
be a enjoyment account it. Glance complicated to far introduced agreeable from you!
By the way, how could we keep up a correspondence?

My blog post – LouiePDupoux

I really love your blog.. good colors & theme. Have
you make this website yourself or do you hire someone to get it
done for yourself? Plz reply as I’m planning to construct my very own blog and wish to know where u got this from.
appreciate it

Also visit my homepage; GinetteRIrby

Leave a Reply