KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

Pause kvm virtual machine from shell

11 replies [Last post]
cyrofilho
Offline
Joined: Jul 28 2008
Points: 0

Hello all,

I will run my kvm virtual machine on a lvm partition, so i can make snapshots and backup the virtual machines on another server. But i think that before doing the lvm snapshot, i have to pause the virtual machine, so the changes gets writen to the disk. So i am trying to make a shell script that pauses my kvm virtual machine, take a lvm snapshot, and replay the virtual machine. The second and third steps i know how to do (-loadvm kvm startup option) but how can i pause the virtual machine from the linux command line? I am starting my virtual machine in daemon mode and with vnc, so i cant access the console monitor and every thing i have is a linux job running.

Is that a way to execute savevm on a shell script instead of from the monitor console? Thanks a lot for any help.

Cyro

Anonymous
Using virsh I think you can

Using virsh I think you can execute commands directly: try :

virsh pause domain

Or something like that... At least this is what the manpage for virsh says :

virsh [OPTIONS]

Good luck!

Haydn Solomon
Offline
Joined: Mar 7 2008
Points: 458
Syntax

You're right but I think the syntax is

virsh suspend <domain>

cyrofilho
Offline
Joined: Jul 28 2008
Points: 0
But can i use virsh even

But can i use virsh even starting the vm directly with the kvm command? I mean i am not using virsh to start the virtual machine, can i still use it afterwards? Thanks.

Haydn Solomon
Offline
Joined: Mar 7 2008
Points: 458
You won't be able to use the

You won't be able to use the virsh ( and other tools that use libvirt ) to manage your virtual machines unless they're started using them. BTW, you may have noticed that the virsh also has a save command that you can use for saving your virtual machine state to file. ie. virsh save <domain>.

If you want to start managing your current vms with the tools that use libvirt so that you can write scripts, you can create an xml file describing your current vms, store them in /etc/libvirt/qemu, then starting using the libvirt based tools and writing scripts using virsh.

Anonymous
My problem for using virsh is

My problem for using virsh is that i am not able to make it start the virtual machine with a usb device on, like the option -usbdevice host:0000:0000 that i can use using the qemu command directly!

Haydn Solomon
Offline
Joined: Mar 7 2008
Points: 458
virsh management

How are you starting your machine with virsh? What version of libvirt are you using? Can you paste your xml config file?

Anonymous
Xml config

Xml config file:

#############

winxpsp3
88b47238-6149-c624-5adf-e90b8e16d6d2
1048576
1048576
1

hvm

destroy
restart
destroy

/usr/bin/kvm

####################

libvirt version:

0.4.0-2ubuntu8

I am starting the virtual machine thru virt-manager. How can i change the xml file so it runs usbdevices?

Thanks a lot.

Anonymous
. . winxpsp3 .

.
. winxpsp3
. 88b47238-6149-c624-5adf-e90b8e16d6d2
. 1048576
. 1048576
. 1
.
. hvm
.
.
.
. destroy
. restart
. destroy
.
. /usr/bin/kvm
.
.
.
.
.
.
.
.
.
.
.
.
.

Sorry, this is the xml file. Please do not consider the . caracter on each line beggining.

Anonymous
Doesn't work, it loses the

Doesn't work, it loses the format everytime!

Haydn Solomon
Offline
Joined: Mar 7 2008
Points: 458
USB support will be supported by

USB support will be supported by libvirt AFTER version 0.4.4 which is the current release so there's no support for it at the moment. Remember virt-manager, virsh, virt-viewer etc all depend on libvirt so until libvirt supports it, you won't see it in virt-manager. Even when libvirt does begin supporting it, virsh will probably be the first tool to support it as it's probably easiest to add new features compared to graphical tools.

However, although libvirt doesn't yet support it, the syntax has already been established and is as follows:

<hostdev mode='subsystem' type='usb'>
     <source>
         <vendor id='0x1234'/>
         <product id='0xbeef'/>
     </source>
</disk>

This is an example taken directly from the official libvirt page. You can find this information at the following link.

http://libvirt.org/formatdomain.html#elementsUSB

 

I've updated the comment box with an fckeditor tool that allows formatting of your posts so you can paste xml format and source code. Use the "Formatted" Format and be sure to choose "full html" as the input format just below the comment box.

 

Anonymous
ugh, old thread, but you can

ugh, old thread, but you can access the monitor by telnet even if you use VNC if you start like this:

kvm -daemonize -vnc :41 -m 128 -hda hda.qcow2 -usb -usbdevice tablet -net nic,macaddr=00:DE:AD:BE:EF:41 -net tap,ifname=tap41,script=no -monitor telnet:127.0.0.1:9941,server,nowait

critical part:
"-monitor telnet:127.0.0.1:9941,server,nowait"

so you have VNC at port 41 (with guest screen, serial console...)
and you can telnet to port 9941 to access the mgmt console.

from a script you can send comands with netcat, like this:
----------------------------------
blackmolly:~# cat /VMs/vmsendcmd
#!/bin/bash
monport="99"$1
cmd=`echo $@ | cut -d" " -f2-`

echo $cmd | nc -q0 localhost $monport >/dev/null
----------------------------------

eg:
vmsendcmd 41 stop

HTH

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.