I have installed virtual box 4.2 on a Ubuntu 11.10 host.

I have Windows 7 as the only guest OS.

I'm able to auto start Windows 7 virtual when Ubuntu boots by adding it in start application with the command "VBoxMange startvm Win7" in the command option.

Now when I shutdown Windows 7 , the virtualbox program is getting closed, but I go back to Ubuntu, when I want to have Ubuntu shut down as well when I click Shutdown in Windows 7 in Virtualbox.

This is an assignment for me. Can anybody please help me on this?

Also, when virtual box starts up automatically, Ubuntu's desktop should not be visible.

  • 1
    It would have been a major design flaw indeeed, if guests could issue a shutdown command for for their hosts. I hope the designers of VirtualBox were smart enough to not allow something like that. – mikewhatever Jan 27 '13 at 13:34
  • 2
    This is such a curious request. Why don't you just install Windows 7 on your machine rather than running it within a VM? – Paddy Landau Jan 27 '13 at 13:52

The way to do this is to write a script to start your VM, wait until it terminates, and then issue the shut-down command.

Create a folder bin in your home folder (if it does not exist already).

Now create a file with the following contents. Let's call it win7vmshutdown, and save it in your bin folder.


VBoxManage startvm 'Win7'                           # Start the VM.

sleep 10s                                           # Give it time to start up. 

while pgrep VirtualBox >/dev/null                   # As long as the VM is running...
        sleep 5s                                    # Wait a bit before trying again.

gnome-session-quit --power-off                      # Issue the command to shut down.

Make the script executable; enter the following in a Terminal.

chmod +x ~/bin/win7vmshutdown

In your Startup Applications, remove the VBoxManage ... command and replace it with win7vmshutdown.

The shutdown command will prompt you for shutdown; if you don't answer, it will shut down in 60 seconds. This gives you time to interrupt the shutdown in case of unexpected problems.

Reboot your computer to test.

You said:

Also, when virtual box starts up automatically, Ubuntu's desktop should not be visible.

To do that, you want to run your VM in full-screen. Install the Guest Additions in your VM, reboot it, and run it full-screen.


You need to create a script that runs on your Windows box that performs a coordinated shutdown of your systems.

From what I read, you want to trigger this from inside your Windows 7 VM.

For a scriptable shutdown of Windows 7, use the psshutdown utility from SysInternals.

You will also need to signal your host to shut down. The best way to do this is to remotely trigger it using secure shell.

On the Ubuntu machine :

You should create a user specifically for this task, and an SSH key specifically for this user. This user will be running a script with elevated privileges and access to it should be at a minimum.

On the Windows machine :

You will need a means to run the script on the host machine via SSH. The Cygwin version of OpenSSH is probably the best option.

So your Windows script should

  • Use SSH to start the script on the host
  • Run psshutdown -t 0 -k

The Ubuntu script should

  • Be owned by root
  • Have the setuid attribute on so that it will run with root privileges
  • sleep for a period of time greater than the Windows machine shutdown
  • Execute /sbin/poweroff

As for the other matter - if you don't want to see the Ubuntu desktop at any time, you can just not load it. Add a user X session that only starts the VirtualBox instance in full screen mode.

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.