dcsimg

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"

nbensa

There’s no need to use sudo with virsh.

Reply

I know this website gives quality depending articles and other
material, is there any other web site which provides such information in quality?

Also visit my web page – Papa Pear Saga Hack, Franchesca,

Reply

Hey there, You’ve done a fantastic job. I will definitely digg it and personally suggest to my
friends. I am confident they’ll be benefited from this web site.

Reply

?i my loved one! I ?ant t? s?y th?t this article is awesome, g?eat written ?nd
include a?proximately all important infos. ?’d like
t? l?ok extra posts lik? th?s .

Reply

?lectrlu? offers some off the best microwave ovens which ensire niform cooking,
pre?erving nuutrition and enhancing taste. Thhe Deluyxe by? P?estige
is ??afted f?om strong virgin aluminum. Hunting for a?pliaces can be a very
daunting task.

?y webpage: buycostumes returns

Reply

Hello! I’ve been following your site for a while now and finally
got the courage to go ahead and give you a shout out from Austin Texas!
Just wanted to say keep up the great job!

my webpage; traffic racer hack apk (Ken)

Reply

What’s up to all, the contents existing at this web page are actually awesome for people experience, well, keep up the nice work fellows.

Reply

In most cases, there are studies that show that these products will work, but you
shouldn’t expect to be able to sit back on the couch, eat potato chips, and watch the weight just drop off.

Take 500 to 1,000 mg before each meal, with
a maximum of 3,000 mg total daily. voluntarily and immediately recalled
all the marked by controversy hydroxycut products from this market.

Reply

Hi! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche.
Your blog provided us useful information to work on. You have done a marvellous job!

Reply

Howdy! This article could not be written any better!
Looking through this post reminds me of my previous roommate!
He continually kept talking about this. I’ll forward this post to him.
Pretty sure he’s going to have a good read. Thanks for sharing!

Look into my homepage: ??? ????? ??

Reply

Hey! I know this is kinda off topic however I’d
figured I’d ask. Would you be interested in exchanging links
or maybe guest authoring a blog article or vice-versa?
My blog discusses a lot of the same subjects as
yours and I feel we could greatly benefit from each other.

If you happen to be interested feel free to send me an
email. I look forward to hearing from you! Superb blog by the way!

Feel free to visit my web page … dora

Reply

of course like your web-site however you need to check the spelling on
several of your posts. A number of them are rife with spelling issues and I find it very bothersome
to inform the reality however I will definitely come again again.

Feel free to visit my website; Casual Sex Baltimore

Reply

It is perfect time to make some plans for the longer term and it’s time to be happy.
I have read this put up and if I may just I wish to suggest you few
fascinating issues or tips. Maybe you can write subsequent
articles regarding this article. I want to learn more issues approximately it!

Also visit my web page – ?? ??????? ??

Reply

Really enjoyed this post, how can I make is so that I receive an email sent to me every time there is a new update?

Reply

Great post. I was checking constantly this weblog and I
am impressed! Very helpful info specially the remaining section :) I deal with such info a lot.
I used to be seeking this certain info for a
long time. Thanks and best of luck.

Reply

What’s up mates, its fantastic paragraph regarding teachingand
completely defined, keep it up all the time.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>