Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have Ubuntu 10.10 and using VirtualBox 3.2. As a Guest OS I have another Ubuntu in the VirtualBox.

I am starting Guest Ubuntu automatically using following command once my Host Ubuntu boots:

VBoxHeadless -startvm Ubuntu --vrdp on

Then I can access to it with ssh or tsclient.

Now I need to shutdown automatically Guest Ubuntu once I shutdown my Host Ubuntu. Does anybody know any safe method to automatically shutdown Guest Ubuntu with a command line? I have found out two ways one can shutdown Guest OS but I am not sure whether they are safe or not. Here are they:

VBoxManage controlvm Ubuntu acpipowerbutton

or

VBoxManage controlvm Ubuntu poweroff
share|improve this question

5 Answers 5

up vote 10 down vote accepted

If you open up Gnome Power management preferences, you can set what actions to take when the power button. If you set it to shut down, it will shut down gracefully when you press the virtual power button with the VBoxManage controlvm Ubuntu acpipowerbutton command.

share|improve this answer

If you are shutting down the vm when the server does, yo have to wait for the vm(s)

(In this shellscript 'root' is the invoker, and 'theuser' is the owner of 'thevm')

I know the vms have finished when the output of the command VBoxManage list runningvms returns an empty string.

I use this in my shell script

...
stop(){
    su -c "VBoxManage controlvm thevm acpipowerbutton" -s /bin/bash theuser
    while [ "`su -c 'VBoxManage list runningvms' -s /bin/bash theuser`" != "" ]
    do
        echo waiting for VMs to shutdown
        sleep 3
    done
}
...
share|improve this answer

This

VBoxManage controlvm Ubuntu poweroff

is equivalent to pulling the power plug on a real computer. You don't want to do this!

Use the ACPI shutdown method (check the power management setting like Egil suggests) or maybe give the save state method (savestate) a try.

share|improve this answer

To safe shutdown vm use this command:

vboxmanage controlvm Ubuntu poweroff soft
share|improve this answer

You should poweroff your virtual Ubuntu just like you do poweroff your real hardware. From a commanline on a ssh session remotely issue:

sudo poweroff

If you want to save the machine state (similar to suspend/hibernate) use the second point in @htorque's answer.

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.