Solved

Automatically starting virtual machine in Oracle VM VirtualBox

Posted on 2013-11-12
26
4,095 Views
Last Modified: 2014-02-09
Hi Experts,

I've recently commenced work with a client who is running a virtualbox virtual machine inside Windows 7 (no, not Windows Server 20xx as you might expect).

VirtualBox opens automatically on startup (easy enough to do), but the virtual machine inside that does not.

I've had a look at a few forums but most I've seen are doing this in Linux, and that's outside my area of expertise!

So, how can I set up VirtualBox (or the virtual machine) so that the virutal machine in question automatically boots on PC restart?
0
Comment
Question by:Servant-Leggie
  • 12
  • 11
  • 2
26 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39644653
If I understand you correctly, you don't have to start the UI for VirtualBox.

Use the command line util VBoxManage, here is a capture of a cmd session:
C:\Program Files\Oracle\VirtualBox>VBoxManage list vms
"TestDSL (Damn Small Linux)" {4bcb49ed-45a8-4334-86d9-5d808d6b49a9}
"TestGOS3" {69269fd8-85b5-4059-b48c-8d432a7d588f}
"TestAndroid" {e4ab981c-62ca-4e17-af64-961781505ebe}

C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "TestDSL (Damn Small Linux)"
Waiting for VM "TestDSL (Damn Small Linux)" to power on...
VM "TestDSL (Damn Small Linux)" has been successfully started.

C:\Program Files\Oracle\VirtualBox>

Open in new window

So that second command (with the name of the vm of your choice) you can put in a script or directly in a scheduled task (on system startup) and you're good to go...
0
 

Author Comment

by:Servant-Leggie
ID: 39664717
robert_schutt, just to confirm, do I replace 'Damn Samll Linux' with the client's VM name (and do I need the brackets (I'd suspect not)?) which copying that 10 line code into VBoxManage?

Sorry if this isn't a super clever question - this isn't my area of speciality!
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39665222
No, replace the whole name, made bold in below command line

VBoxManage startvm "TestDSL (Damn Small Linux)"

so including the double quotes, needs to be replaced and the exact name you can find with the first command

(it's not a 10 line code, it's the complete output, just 2 actual commands after the directory prompt)
0
 

Author Comment

by:Servant-Leggie
ID: 39710079
Thanks, robert_schutt. I'll be running this later this afternoon (OZ time), so will give it a go and let you know how it goes.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39733476
Hi, it's been a while again. Is it still not clear or are you having other problems?
0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 39778995
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 

Author Comment

by:Servant-Leggie
ID: 39778480
Sorry, Robert Schutt, but work/ Christmas/ etc got in the way of my replying.

I'm sorry but I didn't quite get what you were saying until your (2nd) last post, but if I understand it correctly now, I only enter lines 1 & 6 above which should produce lines below similar to those you gave in your example?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39778600
Yes, "C:\Program Files\Oracle\VirtualBox>" is my prompt, showing that I'm in the VirtualBox program directory. From there you can execute the 2 commands. But you will probably not have a virtual machine called "TestDSL (Damn Small Linux)" so you need to examine the output and use the correct name for the vm you want to start.

@LeeTutor: should I post an objection to stop the deletion process?
0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 39778936
Yes, post an objection.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39778996
Author has responded and explained the delay, we should be able to resolve this.
0
 

Author Comment

by:Servant-Leggie
ID: 39784051
Thanks, Robert Schutt. I get what you're saying now and have just completed the VM restart using these commands through CMD. The question is, and I suspect this is an easy one to answer, how to I make a script (and what do I save it as, etc)? I've seen others write very basic scripts, but have never done one myself.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39784247
The simplest would be to put the command you want to run in a .bat file.

This can be run in a number of ways (like putting it in the StartUp folder), but since you mentioned you want to run it when the machine starts I would recommend making a scheduled task (under Control Panel / Administrative Tools) that runs on system boot. You don't even need a .bat file for that, you can set the working directory, the actual command, and its arguments in a task.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Servant-Leggie
ID: 39787352
Robert Schutt, thanks for both suggestions. I've never really used the scheduled tasks before (in fact, I believe I forgot it was even a feature), but that would be the simplest way to achieve the task we want. However, I wonder whether creating a .bat file and putting it in startup might be better as I'm not wanting to start VMBox, but an instance within it. I'd be interested in your thoughts on that - for all I know, a scheduled task is most powerful than I currently give it credit for and may be able to do exactly what we want!
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39787432
The choice depends mainly on whether you want to start the VM when somebody logs on to the machine or always when the machine is started, even when nobody logs on.

The first case can be done with a .bat file in the startup folder. Otherwise use a scheduled task.
0
 

Author Comment

by:Servant-Leggie
ID: 39792780
Robert Schutt, as the PC being used for the server (file server which is also running VirtualBox), the latter option would be the way to go. What I can't work out is how the virtual server instance within VirtualBox would open- a scheduled task can open VirtualBox itself, but then what automatically prompts the virtual server instance to open?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39792809
Indeed, that sounds impossible so hopefully that's not what's needed. What I've been working towards all along is only starting the VM on the host server (so in your Windows 7 system). What you need to do inside the VM could be a whole different ball game as it could be another OS which doesn't know about .bat files and scheduled tasks at all. But I'm pretty sure most systems can be configured to run tasks at system startup if that's what you're talking about.

As for your what you're actually starting up, I hope it's clear that in my very first comment I stated that the way I see it, you don't start the VirtualBox application/user interface, but instead use the VBoxManage utility to start a VM directly.
0
 

Author Comment

by:Servant-Leggie
ID: 39793408
Robert Schutt, it is a bit of an unnecessary setup which they have, as far as I can see, set up by the client's previous IT guy.

They have a Windows 7 Pro 'server' which is running VirtualBox. In VirtualBox, there is another instance of Windows 7 Pro. On this Windows 7 Pro instance running within VirtualBox is found all server users- none of them have access to the Windows 7 Pro which VirtualBox is running from - or, ar least, they only have access to certain folders as per drive mapping/ sharing setup.

Usually after Windows updates, the 'parent' Windows 7 restarts, but doesn't restart VirtualBox. So, restarting VirtualBox is half the job done, but then we need to have the Windows 7 instance within VirtualBox restart too.

Perhaps that's a clearer explanation than I first gave?!

It sounds like I need to have VirtualBox start up as a scheduled task when the PC reboots for any reason and ALSO have a .bat file in the parent Win7Pro which will automatically start up the Windows 7 instance within VirtualBox. So, really, I need to know how to create a script - I can place it in Startup items easily enough...
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39793549
I'm not a server administrator myself but in my experience, however convenient, it is not a good idea to let windows updates run unattended on a server and restart it automatically.

But back to the problem at hand. It does seem like a slightly overcomplicated setup but I couldn't say for sure. I don't understand what needs to be run in the 'inside' Win7. The 'outside' Win7 runs the scheduled task at startup to run the correct VM (using the VBoxManage utility) and that should start the server for the users. That should start up without further need for intervention unless I missed something in your description.

If we're not on the same page, just try this:

On the 'outside' server, open a command prompt, go to the VirtualBox program directory and run the command
VBoxManage list vms

Open in new window

Please report back the output. I've attached a picture to show how I use it.
capture command prompt
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39793562
PS: creating a batch script can be as easy as opening up notepad and placing something like this in a file that you save with a .bat extension:
cd /d "c:\program files\oracle\virtualbox"
VBoxManage startvm "name of your VM"

Open in new window


PS2: after that, just double check that it wasn't saved as xxx.bat.txt! if you have a favorite text editor, use that instead.
0
 

Author Comment

by:Servant-Leggie
ID: 39798631
Robert Schutt, thanks for that info. I've created a batch file,  placed it in the startup folder and will restart the PC remotely tonight to test whether it's doing what we need.

Feeling hopeful!
0
 

Author Comment

by:Servant-Leggie
ID: 39813867
Robert Schutt, restarted the PC and, while VirtualBox restarted, the chosen Virtual Machine within din not. Any thoughts?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39813932
I'm not clear on what you mean by "while VirtualBox restarted". Note that the command I posted does not start VirtualBox (as in, the User Interface where you can start a VM manually), but only the VM of your choice directly.

In the screenshot I posted earlier, you can see the VM starts directly, not the VirtualBox UI.

BTW: My request to you to post the output of the VM list command went unnoticed or do you need more instructions to get to that?

Otherwise, any chance you can post a screenshot (with any sensitive info blacked out) to show me what you want to do? Sometimes a picture is worth a 1000 words.
0
 

Author Comment

by:Servant-Leggie
ID: 39834418
Robert Schutt, thanks for clarifying as I thought that the script would open the GUI as well. Admittedly, because I saw no GUI, I assumed that it wasn't opening. I would have presumed, however, that the Windows containing the Virtual Session would still have opened, but it didn't. Is this an unfair assumption, or does it look like it didn't load on startup as expected?

Is it possible, too, that I didn't give it enough time to load - I think I gave it around a minute, which I thought was enough time?

I will post the output of the VM list command after visiting their office - this afternoon or tomorrow, depending on ideal timing. You're right - that request simply went unnoticed - sorry about that...
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39834792
That is a fair assumption. Like in my screendump above, the VirtualBox GUI is not started, but you can see the linux box on the right, it starts exactly the same as it would when you start it from the VirtualBox GUI.

I think the window should appear straight away when you test the script (you did test it I hope?). Startup time for the OS could be longer, that depends on a lot of things.

I can't see a reason for the VM not to start so hopefully we can drill down to find what's wrong, so first check that the script (batch file) actually runs, then verify the location should be ok by putting something simple in the same location like a batch file that logs the time to a file.
0
 

Author Comment

by:Servant-Leggie
ID: 39846031
Robert Schutt, we have had success!!

I was looking at the script when I visited there last week and realised that there was a SPACE in the name of one of the folders in the file path which didn't exist, so as soon as I corrected that and tried again, ... hey presto!

Thanks for all your assistance and patience - it's been great to be able to work through this and come to a resolution!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

By now, it is common knowledge that Windows 7 has been successfully been able to live up to the hype of being touted as Microsoft’s most anticipated O.S. ever. This latest 2010 Windows release builds up on its predecessor’s positives, adding new…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now