There was a time back then when the command line was the only mode you can use to communicate with your system. Times have changed and GUI tools have been developed to ease the system administration task. But then, there are times that you need a low-level way to interact with your system and its components, that is the command line.
The Oracle VirtualBox is a virtualization tool that allows one to run multiple VMs simultaneously. VirtualBox comes with a pretty and easy-to-use GUI convenient for managing Virtual Machines(VMs). In addition to that, there is VBOxManage, the command-line tool for VirtualBox installed by default. Aside from the two, Oracle VirtualBox offers some other tools to use to control the VM i.e the Main API, implemented using the Component Object Model (COM/XPCOM) and the web service, which maps nearly the entire Main API for web applications. These components interact as shown in the diagram below.
As much as the GUI tool is easy to use, VBoxManage gives you more functionality such as:
It gives one direct access to the virtualization engine
It allows you to access extra features unavailable through the GUI.
Ability to manage your VMs even in headless mode on servers with no GUI.
Using the VBoxManage CLI is easy. Remember, all commands begin with vboxmanage and then are followed by a subcommand such as controlvm, list, etc. This guide aims to equip you with knowledge on how to manage VirtualBox VMs From Command Line using VboxManage
Setup pre-reqs
Before we commence on this guide, you are required to have the latest version of VirtualBox installed on your system. This can be achieved using the aid from the below guides:
Before you begin managing the VMs using VboxManage, it is important that you list and get to know the VM and their names on your system. You will notice that each VM has its own Universally Unique Identifier (UUID) which identifies the VM.
vboxmanage list vms
Sample Output:
This command can be elongated to provide detailed information for each VM using the -l or --long flag
vboxmanage list vms --long
At times, you may be interested in listing only running VMs. This can be done using the command below.
vboxmanage list runningvms
2. Get the VM Info usingVboxManage
You can also get more information related to a specific VM such as the hardware, network, and other configuration information using the command below.
vboxmanage showvminfo ubuntu20
Sample output:
3. Start and Stop a VM using VboxManage
After listing available VMs on your system, you can start a VM say Ubuntu20 as below.
vboxmanage startvm ubuntu20
Sample Output:
This VM will now be available under running VMs as below.
$ vboxmanage list runningvms
"ubuntu20" 3b21f1b4-b93f-4e82-909a-47ecea31f097
Now stopping the VM, we use the controlvm subcommand, the VM name and poweroff option.
vboxmanage controlvm ubuntu20 poweroff
Sample Output:
From the output, you can see the shutdown progress.
Alternatively, you can pause a VM and resume it later using the command:
vboxmanage controlvm ubuntu20 pause
The paused VM will still be listed under running VMs but currently not consuming the system’s resources. Additional information will be shown such as the time when the VM was paused.
vboxmanage list runningvms -l
Output:
The paused VM can be resumed as below.
vboxmanage controlvm ubuntu20 resume
4. Create a VM Using VboxManage.
Another important task when managing VMs is knowing how to create a VM and make configurations to it. For example to create a Fedora Linux VM, run the command:
Virtual machine 'FedoraLinuxVM' is created and registered.
UUID: 7d2a0d73-8ff7-4379-b48b-fdfda9fbcbd5
Settings file: '/home/thor/VirtualBox VMs/FedoraLinuxVM/FedoraLinuxVM.vbox'
In case you are not sure of the available OS types, check as below.
vboxmanage list ostypes
Sample output:
Now you will have your Fedora VM created, you can modify the VM such as changing the name, assigning memory using the modifyvmsubcommand.
For example, we can change the name from FedoraLinuxVM to Fedora35 as below.
vboxmanage modifyvm FedoraLinuxVM --name Fedora35
Assign memory, CPUs, and the graphic controller to the VM as below.
vboxmanage storagectl Fedora35 --name IDE --add ide --controller PIIX4 --hostiocache on --portcount 2 --bootable on
vboxmanage storageattach Fedora35 --storagectl IDE --type dvddrive --port 1 --device 0 --medium "$ISO_DISK"
7. Take and restore Snapshots usingVboxManage
Taking Snapshots is a very important task in keeping systems secure. On VirtualBox, users have the ability to take and revert to snapshots whenever something unusual happens to the system.
Taking a snapshot of a VM is easy. For example, I will take a snapshot of the Ubuntu20 VM and name the snapshot December 14th snapshot.
vboxmanage snapshot ubuntu20 take "December 14th snapshot"
Sample Output:
You can later restore to the above snapshot. Ensure that the VM is stopped before you restore the snapshot.
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.