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


VBoxManage controlvm Ubuntu poweroff

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.

| improve this answer | |
  • As covered by this answer on Superuser, there is a slightly alternative approach: VBoxManage controlvm <vm> savestate. The command will save the VM state and then stop it (as opposed to a shutdown). Since this is the most upvoted answer on this very popular question, I would suggest adding this to this answer. – Etheryte Sep 30 at 20:34

To safe shutdown vm use this command:

vboxmanage controlvm Ubuntu poweroff soft
| improve this answer | |
  • 10
    Can you provide your source? I seem to be unable to find anything on this "soft" option in Chapter 8 of the VBox documentation. – rbaleksandar Aug 11 '15 at 23:29
  • 8
    Killing unsuspecting vms since 2013. Maybe remove this answer? Anyone? – Uprooted Oct 14 '18 at 20:27
  • 1
    poweroff == "PULL THE PLUG". The soft part has no effect :) – rustyx Jan 15 at 21:44

Don't do this:

VBoxManage controlvm Ubuntu poweroff

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

| improve this answer | |
  • 1
    should probably put the don't do this! part before the command. I read the first two lines and ran the command! – nsane Feb 23 '17 at 5:52
  • 1
    @nisargshah95 May I refer you to the example given by this thread. Always read the all the instructions first and always make an effort to understand any command before running it. Especially true in Linux. – Samuel Harmer Apr 13 '17 at 7:15
  • 2
    I understand, but in the most common case, after reading the command, a person would infer that it is the solution (without reading any further) – nsane Apr 13 '17 at 7:43
  • I agree @nsane – I've suggested an edit so that this doesn't happen to others. – Adam K Dean Mar 2 '18 at 17:57

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

    su -c "VBoxManage controlvm thevm acpipowerbutton" -s /bin/bash theuser
    while [ "`su -c 'VBoxManage list runningvms' -s /bin/bash theuser`" != "" ]
        echo waiting for VMs to shutdown
        sleep 3
| 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.

| improve this answer | |

I usually shutdown the VM (Linux) by $ sudo shutdown -h now I guess it is the most gracefull way of terminating the VM because it is shutdown (not poweroff) and provides grace time and (possiblly) the message to the login users.

| improve this answer | |
  • 2
    The question relates to shutting down the guest OS from the host. This would not have the... er... intended effect, if you ran it from the host machine. – Dave Jul 21 '17 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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