How to start the Virtualbox VMs under terminal

时间:2023-03-08 22:08:58
How to start the Virtualbox VMs under terminal

Since we have servral machine on my testbed(fedora), and if I need start some VMs on that, I have to go to the server and using the VirtualBox GUI to start it. Now I am bored of this, I want to start the VMs and connect with termial using my laptop. So I want to show how you start your VMs without using the Virtal   Virtualbox has powerful command line tools, and most of time we’ll use this “VBoxManage”, this tool will help you start and shutdown the virtual machines, or just let you configure the network and check the status of the machine, and etc. It has many options to make you life better. You can get more info just by typing “VBoxMange”. The simple way of start/shutdown of the VMs is just “VBoxManage startvm <vm_name> or <uuid>” (U can use VBoxMange list vms to get the info)

[majian@localhost ~]$ VBoxManage list vms
"blackbox" {41a1c221-49cd-4605-b0fd-e7fdd1aceb36}
[majian@localhost ~]$ VBoxManage startvm 41a1c221-49cd-4605-b0fd-e7fdd1aceb36
Waiting for VM "41a1c221-49cd-4605-b0fd-e7fdd1aceb36" to power on...
VBoxManage: error: The virtual machine 'blackbox' has terminated unexpectedly during startup with exit code 1
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Machine, interface IMachine

Well, we got one problem here, that’s because we are using the ssh terminal without GUI, we need to use the Headless mode to do that, you have two option for that:

VBoxManage startvm "myvm" --type headless   // VBoxMange with headless mode or

VBoxHeadless  -s “myvm”                     // use the direct command VBoxHeadless

and here’s the sample output of that when I use the method 2, but please note that if you use VBoxHeadless, this terminal need to stay open when you use your VM or you need to run this command in the backgroud.

[majian@localhost ~]$ VBoxHeadless  -s "blackbox"
Oracle VM VirtualBox Headless Interface 4.3.10_RPMFusion
(C) 2008-2014 Oracle Corporation
All rights reserved.

-EOF