View previous topic :: View next topic |
Author |
Message |
jerann n00b
Joined: 26 Jan 2005 Posts: 67
|
Posted: Mon Dec 05, 2011 5:03 am Post subject: Shutting down VM on physical machine reboot (QEMU) [SOLVED] |
|
|
I have an Athlon 64 X2 desktop here at home that runs 64-bit Gentoo; I use it primarily as a file/web server. I wanted to install a 32-bit Gentoo VM on the server, so I followed the directions here and got everything working. I'm starting the VM with the kvm command using the vnc switch, and I put a script to start the VM on boot in /etc/local.d so it would automatically boot the vm whenever I boot the server. The server rarely gets shut down or rebooted, but it occurred to me that every time I shut down the physical server, it'll be sort of like pulling the plug on the VM. I've always held that you shouldn't do that on a physical machine... is that bad? Should I try to rig some method to issue a shutdown command to the VM? This is the first time I've managed to set up a virtual machine, so I'm pretty inexperienced on that aspect of it.
Last edited by jerann on Tue Dec 06, 2011 5:36 am; edited 1 time in total |
|
Back to top |
|
|
Telemin l33t
Joined: 25 Aug 2005 Posts: 753 Location: Glasgow, UK
|
Posted: Mon Dec 05, 2011 3:59 pm Post subject: |
|
|
Hi Jerann,
Usually it is considered a BadIdea(Tm) to kill a machine without warning, virtual or physical. Killing a VM without warning doesn't necessarily have the same filesystem damage implications as killing a physical system (although I imagine that still depends on implementation (others please correct me)) but you get no guarantees of anything, and lose any work in progress.
Have you considered using a script to save the VM state on shutdown and check for a statefile on startup? Take a look at the KVM site there are if I remember some scripts that have already been written for such things.
You may also want to take a look at libvirt/virsh, I never used it myself but it sounds like it might be what you are after. Google is your friend on that one:)
-Telemin- _________________ The Geek formerly known as -Freestyling-
When you feel your problem has been solved please add [Solved] to the topic title.
Please adopt an unanswered post |
|
Back to top |
|
|
jerann n00b
Joined: 26 Jan 2005 Posts: 67
|
Posted: Tue Dec 06, 2011 5:35 am Post subject: |
|
|
Telemin wrote: | Usually it is considered a BadIdea(Tm) to kill a machine without warning |
That's definitely what I was thinking
Telemin wrote: | Have you considered using a script to save the VM state on shutdown and check for a statefile on startup? |
Ah, no actually I hadn't thought of that - it's probably a much more fundamentally sound approach than trying to stall the physical machine shutdown process to wait for the vm shutdown process.
Telemin wrote: | You may also want to take a look at libvirt/virsh, I never used it myself but it sounds like it might be what you are after. Google is your friend on that one:) |
I think libvirt is probably the way I'll go, since it looks at a glance like it could support what I'm trying to do. It looks like another option might be to redirect qemu's monitor, as described here and send commands using telnet. It seems to me like that'd be a little more of a jury-rigged solution. Either way, I've got enough to Google with now; I'll make another thread if I have trouble with libvirt or some such. Thanks! |
|
Back to top |
|
|
newtonian Guru
Joined: 19 Jan 2005 Posts: 465 Location: Hokkaido Japan
|
Posted: Mon Feb 20, 2012 9:50 pm Post subject: Getting virsh shutdown gentoo_vm working |
|
|
This is what I did to get auto shutdown working for kvm gentoo client virtual domains:
On the KVM Host:
Code: | echo 'app-emulation/libvirt -lxc python lvm qemu' >> /etc/portage/package.use
emerge -av libvirt
/etc/init.d/libvirtd start
rc-update add libvirtd default
|
Config for my client vm:
Code: |
<domain type='kvm' id='13'>
<name>my_gentoo_vm</name>
<uuid>90eb4382-5f3f-f852-f0bb-8f70cd7b3e2a</uuid>
<memory>4182016</memory>
<currentMemory>4182016</currentMemory>
<vcpu>4</vcpu>
<os>
<type arch='x86_64' machine='pc-1.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
snip...
|
Notice the <acpi/> line.
On the Gentoo client vm:
Make sure acpi is on in the kernel(usually on by default in gentoo-sources).
Install acpid on the client vm:
Code: | emerge -av acpid
/etc/init.d/acpid start
rc-update add acpid default |
Test:
You can test by sshing into your gentoo vm after you've started it with virsh create
and running virsh shutdown command from your KVM host box:
Code: | virsh create my_gentoo_vm.xml |
Code: | virsh shutdown my_gentoo_vm |
Hope this helps.
Cheers, |
|
Back to top |
|
|
|