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"


There’s no need to use sudo with virsh.

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,

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.

?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 .

?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

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)

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.

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.

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!

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: ??? ????? ??

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

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

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 – ?? ??????? ??

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?

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.

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

Simply a smiling visitor here to share the love (:, btw outstanding layout.

You are my aspiration, I own few blogs and infrequently run out from to post .

Keep up the great work and bringing in the crowd!

we at beta web sol are providing high quality SEO
services in affordable rates.

Contact us
Skype: khurramjamil63
email: support@betawebsol.com

Hello. splendid job. I did not anticipate this. This is a fantastic story. Thanks!

I carry on listening to the news update speak about receiving free online grant applications so I have been looking around for the top site to get one. Could you tell me please, where could i acquire some?

hi!,I really like your writing so a lot! percentage we keep up a correspondence more approximately your post on AOL? I require an expert on this area to unravel my problem. Maybe that’s you! Having a look ahead to peer you.

Please pay a visit to the sites we follow, like this one, because it represents our picks from the web.

I was recommended this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re wonderful! Thanks!

Just beneath, are several absolutely not connected web-sites to ours, nevertheless, they may be certainly really worth going over.

Wonderful story, reckoned we could combine some unrelated information, nonetheless truly really worth taking a look, whoa did one master about Mid East has got extra problerms at the same time.

Heya! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the great work!

The time to study or visit the content or web pages we’ve linked to below.

I admire your piece of work, thankyou for all the great content.

Wonderful story, reckoned we could combine a handful of unrelated data, nonetheless seriously worth taking a search, whoa did one discover about Mid East has got much more problerms at the same time.

Usually posts some very intriguing stuff like this. If you are new to this site.

One of our visitors not too long ago suggested the following website.

Every as soon as inside a though we select blogs that we read. Listed beneath are the latest internet sites that we opt for.

SDZrzB bpvenzxztwzx, [url=http://ybjqdswltpts.com/]ybjqdswltpts[/url], [link=http://vocagwcxtqud.com/]vocagwcxtqud[/link], http://nwsifiabyddj.com/

We came across a cool web site which you may possibly enjoy. Take a look in case you want.

Thank you ever so for you blog post.Thanks Again. Want more.

That may be the end of this post. Right here you will discover some web pages that we think you?ll enjoy, just click the hyperlinks.

This is one awesome post.Much thanks again. Great.

I really like and appreciate your post.Really looking forward to read more. Keep writing.

Here is a great Weblog You might Obtain Exciting that we encourage you to visit.

Check below, are some entirely unrelated internet sites to ours, having said that, they’re most trustworthy sources that we use.

Check below, are some totally unrelated internet websites to ours, however, they may be most trustworthy sources that we use.

In previous garage then, the track alignment will
not enable the smooth Turing of the door this
may increasingly cause your door to not work at all.
Calling Portland door restore will repair it better, you may be convinced as if there was no downside on the door.

Below you will uncover the link to some websites that we assume it is best to visit.

Your place is valueble for me. Thanks!…

Hi! This post could not be written any better! Reading
through this post reminds me of my previous room mate!
He always kept talking about this. I will forward this article to him.
Pretty sure he will have a good read. Thank
you for sharing!

Also visit my blog – BobBMcgray

Check beneath, are some entirely unrelated web-sites to ours, nonetheless, they’re most trustworthy sources that we use.

Leave a Reply