Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a virtual machine with virt-manager that runs on kvm/qemu. The machine works well when started through virt-manager. However, I would like to be able to start and stop the VM through a script in init.d, so that it comes up and down along with the host. I need to have virt-manager show that the machine is running, and to be able to connect to its console through there.

When I use the command line that is produced by running ps -eaf | grep kvm after starting the vm through virt-manager, I get some console messages about redirected character devices, but the machine does start and runs properly. However, I do not get any indication from virt-manager that it has started. How can I modify the command line to get virt-manager to pick up the running VM? Is there anything else about the command line that should change when starting outside of virt-manager?

Command line is (slightly reformatted for readability):

/usr/bin/kvm -S -M pc-0.12 -enable-kvm -m 512 -smp 1 -name BORON \
-uuid fa7e5fbd-7d8e-43c4-ebd9-1504a4383eb1 \
-chardev socket,id=monitor,path=/var/lib/libvirt/qemu/BORON.monitor,server,nowait \
-monitor chardev:monitor -localtime -boot c \
-drive file=/dev/FS1/BORON,if=ide,index=0,boot=on,format=raw \
-net nic,macaddr=52:54:00:20:0b:fd,vlan=0,name=nic.0 \
-net tap,fd=41,vlan=0,name=tap.0 -chardev pty,id=serial0 -serial chardev:serial0 \
-parallel none -usb -usbdevice tablet -vnc 127.0.0.1:1 -k en-us -vga cirrus
share|improve this question
up vote 7 down vote accepted

As far as automatically starting/stopping and you're using virsh you can do that like this (as a privileged user)

virsh autostart Domain

I'm not sure why virt manager isn't giving you any output. It does have a connection to the machine hosting machine right? It should show a list of domains if it's connected.

share|improve this answer

Open the VM display, click View->Details

enter image description here

Select Boot Options, and tick Start virtual machine on host boot up

enter image description here

share|improve this answer

The answer by Tim is the way to go, virsh allows you to do many useful things except that.

To set a virtual machine to be automatically started, you use:

# virsh autostart <domain-id>

The <domain-id> is either the virtual machine's number, UUID or a "friendly name" like "debian1", which you entered in virt-manager.

To get a list of virtual machines (numbers and names), use:

# virsh list --all

In my case I get:

 Id Name                 State
----------------------------------
  1 other                running
  2 other-clone          running

So I've used:

# virsh autostart other
share|improve this answer

install virsh then

virsh list                    (this will print list of your VMs)
virsh dominfo your_vm_name    (get info about selected VM)
virsh autostart your_vm_name  (set autostart of selected VM)
share|improve this answer
    
if VM stuck at grub, virt-viewer your_vm_name, and boot up. After that, change /etc/default/grub, make sure that GRUB_TIMEOUT=0. then update-grub – HVNSweeting Jan 25 '13 at 6:56

You can also place a symlink to the guest domxml in /etc/libvirt/qemu/autostart:

Will look like this for a VM named "test":
test.xml -> /etc/libvirt/qemu/test.xml

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.