Start virtual machines sequentially

This is for discussing general topics about how to use VirtualBox.
Post Reply
kinderbueno
Posts: 1
Joined: 2. Apr 2024, 10:19

Start virtual machines sequentially

Post by kinderbueno »

I'm running VirtualBox (7.0.14) on a linux host. I have a script that starts up several often used VMs. Essentially the bash script looks like:

Code: Select all

for vm in VM1 VM2 VM3
do
  VBoxManage startvm $vm
done
Ideally I would like VBoxManage to return only once the VM has started. Half the time that is exactly what happens, ie VBoxManage starts the VM, waits until it has started then returns (exits) so my script can start the next VM in the loop. So in this scenario the VMs are started sequentially (or one at a time) in an orderly fashion.

However, the other half of the time, VBoxManage returns immediately after having started the process of starting the VM. In this scenario all the VMs are essentially started at the same time, this results in lots of disk thrashing with every VM trying to read from the HDD at the same time.

I'm just running the same script, so why does it sometimes behave in the way that I would like it to, and at other times it doesn't. Is there a way to force VBoxManage to completely finish starting a VM before returning?
granada29
Volunteer
Posts: 711
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Start virtual machines sequentially

Post by granada29 »

I'm not sure of a direct answer to your question but after starting each VM you could poll

Code: Select all

vboxmanage showvminfo "vm-name" --machinereadable|grep "VMState="
until you see VMState="running", before starting the next VM. You would probably need a sleep in the poll loop.
Post Reply