When you have a VirtualBox hypervisor installed, there is no doubt that the easiest way to navigate through the VirtualBox is via GUI. It is very user-friendly; even an average user can create and manage a virtual machine using VirtualBox GUI without having prior knowledge on how to manage VM’s.
But the fastest way to use the VirtualBox is via its command line. Many people think that working with the VirtualBox VM via the command line is a complex task, and only an advanced user should be performed. However, that’s not the case. Once you start using the VirtualBox CLI, you may not go back to the GUI again because it’s a faster way to get things done.
Instead of going through multiple steps, you can pretty much do everything with one single command, and you don’t have to move around the menus and sub-menus using the mouse pointer.
Moreover, the VirtualBox Command line supports more features than the GUI.
In this blog, we will look at how you can manage VirtualBox using the command line, we are not going through all the commands, but we will go through the essential ones.
After following this, you can manage the virtual machine in VirtualBox using the command line.
I am using VirtualBox on a Windows 10 machine, and the commands that I use here are pretty much the same for VirtualBox running on other operating systems.
Read also,
How to Manage Snapshot in VirtualBox? – Both GUI and CLI
Can I start VirtualBox GUI from command line?
You can start VirtualBox GUI from the command line. However, you have to be at the installation location and start the CMD from there, which we will discuss next.
After you opened the cmd, all you have to do is type VirtualBox and hit enter. The GUI would open.
The character doesn’t have to be case-sensitive.
As you can see, I have typed the command with the mix of upper and lower cases, and all of them worked just fine. And that should open the Virtualbox GUI.
How to run VirtualBox Command line?
Vboxmanage is the command-line interface utility for the VirtualBox. To start the command line for VirtualBox, you will have to go to the installation location of the VirtualBox. By default, the installation location for the VirtualBox in windows is under C:\Program Files\Oracle\VirtualBox
While you are at the location, you can type cmd
on the address bar. It should open up the command line on the exact location, and you can start to use vboxmanage and the rest of the VirtualBox commands from here now.
To get help or the command reference that you want to follow, you can enter the command vboxmanage and hit enter. It will show you a whole list of commands and the subcommands you could run with the vboxmanage.
List the VirtualBox VM’s.
To see the VM’s list currently running on your VirtualBox machine, you can type the command vboxmanage list vms
and hit enter.
It will show you all the VM’s that are currently installed in the VirtualBox environment with their name and UUID. We will see how we can use both the names and the UUIDs to manage the VM’s in VirtualBox CLI.
C:\Program Files\Oracle\VirtualBox>vboxmanage list vms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "Linux Mint" {8637c1dd-9be0-49f4-9d07-9b12f0892941} "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8} "slitaz" {6c7f5a93-0146-4a7d-af5b-c81349f37551} "Ubuntu-Web Server2 Clone" {8df75390-ec1c-47cb-ba57-07286033ea52} "windows" {bfe6b57c-bcc0-4a93-97a6-1764258f7d3e} C:\Program Files\Oracle\VirtualBox>
How do I see the running VM’s in vboxmanage?
While the list VM’s will show you the list of VM’s that you have in the VirtualBox, You can type the command vboxmanage list runningvms
to see the list of VM’s that are currently running on the VirtualBox.
As you can see, I cannot see any VM’s that are currently running because I have not started any VM’s yet.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms C:\Program Files\Oracle\VirtualBox>
Let’s take a look at how you can start a VM via CLI in VirtualBox.
How to start a VirtualBox VM from command line?
To start a VM, you can use the command startvm following vboxmanage and the VM name or UUID.
The command will be as follows.
Vboxmanage startvm <“vmname”>
You can also type the VMname without quotes. However, if the VM name has space, you cannot run the commands without the quotes.
As you can see, I tried to start a VM with a space in its name, but it didn’t start. Instead threw an error, and when I tried the same command with quotes, it started.
If your machine doesn’t have GUI access, you can also start the VM in a headless mode. This will not open the GUI, and from other devices or a local network, you can log in via ssh protocol and manage the VM, provided you should have the Virtualbox Networking properly set up.
To start the VM in a headless mode, right after the VM name add –type command and type as headless.
vboxmanage startvm <"vmname"> --type headless
When you enter the headless commands, you won’t see the VM opens up in a GUI. However, it will be running in the background. And you can use the runningvm command to see the running VM’s.
C:\Program Files\Oracle\VirtualBox>vboxmanage startvm "Ubuntu-Web Server1" --type headless Waiting for VM "Ubuntu-Web Server1" to power on... VM "Ubuntu-Web Server1" has been successfully started. C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63}
Start the Virtualbox VM with UUID.
Remember, I mentioned managing the VM’s with name and UUID ?.
We have already taken a look at how you can manage the VM’s using the VM’s name. Let’s do the same thing with the UUID.
To get the UUID, you can type the list VM’s command again, and after the name, you should be able to see the UUID.
I have an Opnsense firewall VM with the UUID start with e1c and ends with 9c8.
"OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8}
Let’s start the VM using the UUID, and you should see the VM has started. Since we have not used the headless mode, the VM should open up in a VirtualBox GUI if you have GUI access.
C:\Program Files\Oracle\VirtualBox>vboxmanage startvm "e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8" Waiting for VM "e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8" to power on... VM "e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8" has been successfully started.
I entered the command list running VMS, and I can see the Opnsense firewall VM has been started and running now.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8} C:\Program Files\Oracle\VirtualBox>
How do I see the properties of the Virtualbox VM?
When you wanted to see the properties or the information about a specific VM, you should use vboxmanage showvminfo <vmname> command.
It will help you alter the VM settings later on when you wanted to make some changes, which we will cover in the modifyvm settings.
When you enter the showvminfo command, it will show you detailed information about VM resources, including OS type, CPU, Memory, Storage, and so on.
How to check host machine resources in vboxmanage CLI?
When you deploy a VM to VirtualBox, or any other hypervisor for that matter, the resources such as memory, CPU, and so on are allocated by the host machine. And you must know how much resources are left on your host machine before you spin up more VM’s.
We have checked the VM information by entering showvminfo right. Is it possible to check the host machine properties as well?
You can check the host machine information on the vboxmanage command line, by typing the command below.
vboxmanage list hostinfo.
As you can see, it will show you the number of processors your host machine has. The Memory size and available memory on the and operating system information as well.
Vboxmanage controlvm.
With vboxmanage controlvm you can change the state of the virtu albox virtual machine, you could pause, resume, power off, restart and everything can be done from here.
Let’s take a look at how it works in action.
The Virtualbox CLI is mainly used so everything can be done remotely over the ssh. To make things clear, I will also show you how each command works with the GUI as well.
How to stop VirtualBox VM from command line?
We have some VM’s that we have started to test the vboxmanage command line. How do we go about and shutdown those VM’s via CLI?
The shutdown option in VirtualBox is under the subcommand controlvm, similar to how you power down a physical machine by pressing the power button. You can do the same using acpipowerbutton option.
I will power down one of the Ubuntu web server that I am running in the VirtualBox.
First, let’s check the VM’s in CLI.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8}
For your information, the GUI list also shown.
Shutdown the VM.
C:\Program Files\Oracle\VirtualBox> C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "Ubuntu-Web Server1" acpipowerbutton
I used the command vboxmanage controlvm “Ubuntu-Web Server1” acpipowerbutton and as you can see the VM got shutdown and I no longer see the VM’s under the running state.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8}
Virtualbox VM force shutdown.
When you try to shut down the VM’s using the acpipowerbutton command, it may not work for some of the VM’s because of no ACPI support on the operating system. You can use an alternate command which is poweroff, The poweroff option is like unplugging the cable from a physical machine, and you know that it is not a good practice.
And same applies to this poweroff command as well. You should be extra careful when you use this command as it can corrupt the virtual machine.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "pfSense-fw" {b6627666-ec04-4f47-be31-3556a6b4a10b} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8}
From the current running machines, I will shut down both remaining VM’s that I have.
C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "pfSense-fw" poweroff 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "OPNSENSE-FW" poweroff 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
After few seconds, the VM’s will be powered down, and you should see there are no runningvms currently on the VirtualBox CLI as well in the GUI.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms C:\Program Files\Oracle\VirtualBox>
Reboot a VM in VirtualBox using vboxmanage.
We have taken a look at how you can stop the VM’s using vboxmanage. You can also reboot the VM’s in VirtualBox using the vboxmanage command.
It is recommended to use the restart option within the VM’s, but you have this option available for you to use.
The command for restarting the VM is vboxmanage controlvm <vmname/uuid> reset.
It is similar to the reset button on the physical box.
I have just powered on one of the windows 10 machine that I have, and I will use the command against the same virtual machine.
As soon as I entered the command, the VM got rebooted.
Pause a VM using vboxmanage.
As the name suggests, the pause command will put the VM state into a pause state, and you won’t be able to make any changes on the VM. Neither can you log in. And the VM screen will look in grey.
To pause the VM, you can type the command vboxmanage controlvm “windows” pause.
As you can see from the below screenshot, the one on the left running state and the right is when the VM is paused, and you cannot do anything in the VM until you resume the state of the VM.
You can see the VM is paused in the list of VM’s in the GUI as well.
Resume the VM state from pause.
To come out of the pause state, you can replace pause with resume. It will bring up the VM to be running state again.
C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "windows" resume
You should see the state changed from the pause to resume in VirtualBox.
Save the virtual machine state.
When you try to close the VM’s in GUI, you must have seen an option that says Save the machine state. What it will do is, it will save the current machine state to the disk and close the VM.
The same option is available under the controlvm command as savestate.
I have the same windows 10 VM running, and let’s run the command vboxmanage controlvm “windows” savestate.
Before we run the command, let’s open some applications in the Windows VM and apply the command, and when we start the VM again, it should restore from where it was left off.
This option is handy when you are in the middle of something, and you want to take a long break and come back and resume from where you left off.
I have a web browser and a command prompt window which I have currently opened. And I am going to issue the command now.
I ran the command, and after few seconds, the VM has saved its state and shut down the VM.
C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "windows" savestate 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
You wont be able to see the VM is running in the virtualbox.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms C:\Program Files\Oracle\VirtualBox>
And in the GUI, you can see the VM status as Saved.
Let’s start the VM using the startvm command again, and it should start from where we left off.
C:\Program Files\Oracle\VirtualBox>vboxmanage startvm "windows" Waiting for VM "windows" to power on... VM "windows" has been successfully started. C:\Program Files\Oracle\VirtualBox>
As soon as I powered on the VM, it started to restore the virtual machine. Though the remaining restoration time says 1minutes and 7 seconds, I could get in within few seconds.
And you could see I could get back to the previous state I was in right before I shut down the machine.
Vboxmanage modifyvm
We have taken a look at how you can manage the VM using the vboxmanage controlvm. Let’s take a look at how you can modify the VM properties using the modifyvm subcommand in vboxmanage. When you run the command, make sure you shut down the Virtual machines first.
Change the VM name VirtualBox CLI.
If you want to change the name of the VM in virtualbox CLI, you can run the command vboxmanage modifyvm <" vmname"> --name <newname>
I will rename some of the VM’s names using the –name option in the CLI.
To rename the pfSense-fw we can type the command as follows.
vboxmanage modifyvm "pfSense-fw" --name pfsense-firewall
Similarly I have renamed the two other VM’s as well. Windows to Windows 10 and Ubuntu-web server2 clone to ubuntu_web_server2.
Modify the memory.
When I deployed the Ubuntu machine in VirtualBox, I have added 4Gigs of ram. Since my machine has enough RAM, it should be okay. However, when I want to run more VM’s at the same time, it will be a challenge.
So let’s see how can modify the memory in VirtualBox using CLI.
First, let’s check the current memory allocation.
I can check the memory allocation by typing the vboxmanage showvminfo “vmname” command.
I have provided 4096MB of RAM.
Let’s go ahead and reduce to 1028MB instead.
Before I make the changes, I need to see if I am running the VM or not.
C:\Program Files\Oracle\VirtualBox>vboxmanage list runningvms "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63}
As you can see, the Ubuntu VM is currently running, and I cannot modify the memory allocations to it.
Poweroff the machine. And modify the RAM size to 1028 with the below command.
vboxmanage modifyvm "Ubuntu-Web Server1" --memory 1028
After that, when I checked the vminfo, I could see the memory size reduced to 1gig.
Increasing the memory also the same way. Let’s say you want to increase the memory from 1028 to 2048 replace the 1028 in the previous command to 2048.
vboxmanage modifyvm "Ubuntu-Web Server1" --memory 1028
Modify the CPU.
When we checked the Ubuntu VM CPU, we could see that we have assigned 2 CPUs to it.
What if you are machine is running slow, and you wanted to run the VM’s, but allocate only single-core? You can do that by using the modify CPU option.
So you can type the command vboxmanage modifyvm "Ubuntu-Web Server1" --cpus 1
After that, you can notice the in showvminfo, the CPU is changed to 1 core.
Change the OS Types.
After you deploy an operating system, and later you realize that you choose the different operating system type instead of a correct one, you can go back to the vboxmanage CLI and change the ostype and which is very easy.
You can get the list of supported ostypes in virtualbox by typing the following command.
Vboxmanage list ostypes
Let’s assume that I have installed, windows 10 on my VirtualBox, unfortunately, I have chosen windows 7 as the OS type during the installation.
You can verify the same from the GUI as well.
To change the OS type, first, check the OStype from the list of supported ostypes mentioned above, my operating system type is listed below, which is windows 10 and I have two options to choose from one is 32 bit another is 64 bit.
ID: Windows10 Description: Windows 10 (32-bit) Family ID: Windows Family Desc: Microsoft Windows 64 bit: false ID: Windows10_64 Description: Windows 10 (64-bit) Family ID: Windows Family Desc: Microsoft Windows 64 bit: true
To change from windows 7 to windows 10 enter the command as below.
vboxmanage modifyvm "Windows10" --ostype Windows10_64
After you made the changes, you should be able to see the vminformation changed on the virtualbox CLI and the GUI.
How to delete a VM from VirtualBox using CLI?
You can either remove the Virtual machine from the VirtualBox or delete it from the disk.
To remove the VM from the VirtualBox, you can use the command unregistervm, and it would remove the VM instance from the VirtualBox.
However, the VM files will still be there under the VirtualBox VM folder.
To altogether remove the VM, you can type the command –delete at the end. It should delete the VM.
I have below VM’s in the list, and I will remove slitaz 2 from the list.
C:\Program Files\Oracle\VirtualBox>vboxmanage list vms "pfsense-firewall" {b6627666-ec04-4f47-be31-3556a6b4a10b} "Linux Mint" {8637c1dd-9be0-49f4-9d07-9b12f0892941} "Ubuntu-Web Server1" {105025b5-714c-42a8-81b9-b75b9f0adf63} "OPNSENSE-FW" {e1c7c4b8-ea50-41f9-a32b-1e932f5de9c8} "Ubuntu-Web-Server2" {8df75390-ec1c-47cb-ba57-07286033ea52} "Windows10" {bfe6b57c-bcc0-4a93-97a6-1764258f7d3e} "slitaz" {6c7f5a93-0146-4a7d-af5b-c81349f37551} "slitaz 2" {d0001d66-dbb1-4c0f-beed-86b78cacb1ee} C:\Program Files\Oracle\VirtualBox>
To do that enter the command as below.
vboxmanage unregistervm “slitaz 2” And you no longer see that VM in the list.
But you can see the VM files in the VirtualBox folder.
To register the VM which was removed, you can enter vboxmanage registervm
“C:\Users\saifudhe\VirtualBox VMs\slitaz 2\slitaz 2.vbox”
Note: You need to call the file from the Virtualbox VM locations.
Now the VM is registered back.
Delete the VM completely.
To delete the VM, you can use –delete at the end.
After the deletion, you will still see the folder, but the virtual machine files are deleted.