Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 42

Thread: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

  1. #21
    Join Date
    Mar 2006
    Beans
    Hidden!

    Smile Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    We got Jonners sorted out in the end I believe. Here's a transcript of requirements:


    1. Test the creation of a saved state of an open VM, and then successfully open it up again (using the GUI) ?

    2. Next stage will be to do this via the command line. Once that works we can look at how to close VMs down when we ask Ubuntu to closedown (can't do anything about Ubuntu crashing I am afraid!), then on how we start a VM when we start Ubuntu (either from fresh, or from a saved state)

    Right, now, as it seems your VM is happy to savestate and resume, we can move onto the next stage. I am going to give you fish as well as teach you how to fish, this is why I am doing it in stages.

    You need to now learn how to save and resume your VM from a terminal. Get your VM up and running.

    1. Open a terminal
    2. Type the following:

    VBoxManage -nologo list runningvms

    You should get back something like this:

    "XP" {afa231b5-397f-4b34-ad33-249c82cb1579}

    ("XP" is the name of the vm I am using, replace XP with the name of your vm, but keep the "")

    3. Then type as follows:

    VBoxManage -nologo controlvm XP savestate

    You should see dots and percentages going up from 10%, and your vm will close. You have saved your vm. You can close your Virtualbox application!

    4. Now type this (replacing XP with the name of your vm and make sure you put the & at the end!:

    VirtualBox --startvm "XP" &

    Your vm should now start up where you left off. You will also notice that you have no main application - more screen real estate! You can always open it up if you need it.

    Right with all this working OK, you know that your vm is happy being saved and resuming from the cli. Now we need a script to start it up when Ubuntu starts. Let's assume your vm is the only vm you want to start.

    Back to the terminal:

    sudo nano /usr/bin/startvm.sh

    Enter or copy/paste the following into the terminal/nano window

    #!/bin/bash
    sleep 60
    /usr/bin/VirtualBox --startvm XP &

    Then press CTRL+X, Y, and Enter.
    Make it executable:

    sudo chmod 755 /usr/bin/startvm.sh

    Now you need to add this script to your startup.

    I use Xubuntu so I go to Xfce Settings Manager -> Sessions and Startup, there is a similar place in Ubuntu where you can add a program you want to start on boot (after login!)

    the command you want to enter is:

    /usr/bin/startvm.sh


    Right that should be it. I have set the timer at 60 seconds, which should ensure your desktop has set itself up and that the vboxdrv driver is in place. You might try editing the script to sleep 30 or less and see if it starts?

    OK close your vm (you have the command now!), and reboot. With any luck your vm should start, just where you left off.

    You can use CharlesA's shutdown script (a few posts above this one) to gracefully close down your vm's.
    No longer participating......

  2. #22
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    Problems, Problems...
    I had to do a reboot after an Ubuntu update.
    The auto start we created would not work, it came up with an error message saying "3cx server" did not exist, so I tried to start using the Gui, and got the enclosed message.... See screenshot.

    I then decided to start from scratch and rebuild the whole thing again.

    Just saved the image following the instructions, which shut it down... I then restarted it with the command
    HTML Code:
    VirtualBox --startvm "3cx server" &
    and ended up with the same error message. I tried again with the Gui, see attached.

    Help. I don't want to rebuild again. Can this be saved and what is going wrong?
    Attached Images Attached Images

  3. #23
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    It sounds like you had a snapshot or something and it's not accessible.

    Make sure the VHD file is in ~/.VirtualBox
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  4. #24
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    There is no file *.VHD I searched the "File System" too.
    How do I re-create it?

    This is a bummer, just when I thought I had it licked!
    Last edited by Jonners59; January 21st, 2011 at 07:59 AM.

  5. #25
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    well, it should be a .vdi or a .vmdk file, but if you are using Virtualbox 3.x, they'll be in ~/.VirtualBox/HardDisks IIRC.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  6. #26
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    Quote Originally Posted by CharlesA View Post
    well, it should be a .vdi or a .vmdk file, but if you are using Virtualbox 3.x, they'll be in ~/.VirtualBox/HardDisks IIRC.
    OK, CHarles
    I found 3cx server.vdi in the "Hard Disks" folder in .VirtualBox

    What do I do now???????

  7. #27
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    It would probably be better to post over on the virtualbox forums.

    See here: http://forums.virtualbox.org/viewtop...=23617&start=0
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  8. #28
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    Solution
    In the Gui, go to the "Machines Manager".
    Look for the faulty machine in the list. You should notice it has sub images. Delete the last one... And keep doing so until it works. As long as you do not delete the base image it will work.

  9. #29
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    Bingo, many thanks

    The answer lay in "File" - "Virtual Media Manager" - "Hard Disks"

    Then just delete the last "Child" to the hard disk causing the probs...

  10. #30
    Join Date
    Sep 2009
    Location
    London
    Beans
    930

    Re: HOWTO: Gracefully Shutdown VirtualBox VMs on Reboot or Shutdown of Ubuntu

    I had a hard drive failure on my PC that we set up and had to rebuild everything from scratch. I tried to set up the scripts you gave but I noticed on reboots and yesterday I had a an auto restart in my absence, the scripts did not work. The VM did not restart. Virtual Box started, but a message, "could not start 3CX Server" comes up.

    Any help, please? I am sure I have just not ticked a box some-where.

Page 3 of 5 FirstFirst 12345 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •