- Master the commands from VBoxManage to manage and automate VirtualBox
- Learn to create, modify and manage Virtual machines optimally
- Configure network adapters, disks, and advanced resources by terminal
- Take advantage of scripts and Tricks CLI for professional and efficient virtualization
Have you ever wondered How to manage your virtual machines efficiently and quickly from the command lineNowadays, mastering tools like VBoxManage in VirtualBox is key for both system administrators and virtualization enthusiasts looking to streamline tasks, optimize resources, and automate processes. Forget the graphical interface for a while: here you'll discover how to work magic in your terminal.
In this article you have this tutorial about VirtualBox commands, designed so that you can create, modify, manage and automate any virtual machine, whether in Windows, Linux or macOS. Whether you're starting from scratch or looking for advanced tips, here you'll find clear examples, practical commands, and easy-to-understand explanations so you can overcome your console fear and get the most out of VirtualBox.
What is VirtualBox and why should you use commands?
VirtualBox It is a powerful cross-platform virtualization platform that allows you to run multiple OS simultaneously on your computer. It's compatible with x86 and AMD64/Intel64 architectures and stands out for its ease of use and flexibility. One of its greatest advantages is its command-line tool. VBoxManage, which unlocks the full potential of VirtualBox, allowing you to perform tasks as varied as automating deployments, managing resources, configuring networks, or troubleshooting problems that may not be available from the graphical interface.
But why use VBoxManage? Although the graphical interface is intuitive, the VirtualBox CLI (command line interface) not only offers all features available (including advanced and experimental tweaks), but it also allows you to create scripts, automate repetitive processes, and manage servers without a graphical environment. Especially in Linux environments or when working on headless servers, the command line is simply indispensable.
Getting Started: Installation and Working Environment
Before you start typing commandsMake sure you have VirtualBox installed on your computer. It's compatible with Windows, macOS, Linux, and Solaris. In most cases, installation is straightforward and comes with VBoxManage, which is installed by default alongside VirtualBox.
To make sure VBoxManage is working properly and is in your system PATH, simply open a terminal and type VBoxManageIf you see a list of commands, you're ready to go. If not, check your environment variables or consult the installation help specific to your system.
Tip: On Linux and macOS, the command may be vboxmanage (lowercase), although both variants usually work the same.
Exploring VirtualBox Interfaces
VirtualBox offers several forms of interaction:
- VirtualBox Manager: the classic graphical user interface (GUI).
- VBoxManage: the command line interface (CLI), ideal for advanced tasks and automation.
- Main API and Web Services: for custom integrations and developments.
Actions you perform in one interface are automatically reflected in the others. For example, if you create a virtual machine using the terminal, it will also appear in the GUI, and vice versa.
Essential commands for querying and managing virtual machines
To start tinkering with VBoxManage, you need to know which virtual machines you have available and their status.
List all registered virtual machines:
VBoxManage list vms
View running virtual machines:
VBoxManage list runningvms
Check the types of operating systems supported by VirtualBox:
VBoxManage list ostypes
This command provides a comprehensive list of supported operating systems (Windows, Ubuntu, Debian, Solaris, etc.), along with their IDs and descriptions, which are essential for specifying the correct operating system when creating a VM.
Creating a virtual machine from scratch (Ubuntu case study)
Let's illustrate step by step how to create an Ubuntu virtual machine Only with commands. This applies to any other system; you just need to change the names and parameters.
1. Create the virtual machine and register it
VBoxManage createvm --name UbuntuServer --ostype Ubuntu_64 --register
What does this command do? Generates an XML definition file for the virtual machine named "UbuntuServer", registers it in VirtualBox, and associates the Ubuntu 64-bit operating system type with it. The parameter –register It is essential for the VM to appear available in the application.
2. Configure the virtual machine hardware
Once the virtual machine is created, you need to adjust its parameters. hardware: RAM memory, CPUs, VRAM, etc.
VBoxManage modifyvm UbuntuServer --memory 2048 --cpus 2 --vram 128
Quick explanation: We assigned 2GB of RAM, 2 virtual CPUs, and 128MB of video memory to the new machine.
For further customization, you can add the VM description:
VBoxManage modifyvm UbuntuServer --description "Servidor Ubuntu 22.04 para pruebas"
If your host system supports it, it is recommended to enable hardware virtualization and the IO APIC option for better performance:
VBoxManage modifyvm UbuntuServer --hwvirtex on --ioapic on
3. Create and connect a virtual hard drive
Like any physical computer, your machine needs a virtual hard drive to install the operating system. You can create it with:
VBoxManage createhd --filename UbuntuServer.vdi --size 10240 --variant Standard
This command creates a 10GB dynamically allocated VDI disk. The path can be relative or absolute, depending on the operating system and your folder structure.
Important Note: You can choose between fixed-size or dynamic images. Dynamic images take up less space initially and grow as they're used; fixed images may offer slightly more performance but take up all the space from the start.
4. Add the storage controller
Each disk image requires a driver to attach to the virtual machine. Typically, a SATA driver is used:
VBoxManage storagectl UbuntuServer --name "SATA Controller" --add sata --bootable on
5. Attach the virtual hard disk to the controller
VBoxManage storageattach UbuntuServer --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium UbuntuServer.vdi
Main point: Ports and devices usually start at 0. You can have multiple drives and controllers depending on your needs.
6. Add an IDE controller and connect an ISO image
To install the operating system, you typically need to mount an ISO image as if it were a DVD. First, create the IDE drive:
VBoxManage storagectl UbuntuServer --name "IDE Controller" --add ide
Then, attach the ISO image:
VBoxManage storageattach UbuntuServer --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /ruta/a/ubuntu.iso
Remember: Replaces /path/to/ubuntu.iso by the full path to your ISO file.
7. Adjust boot and network ports
You can configure the order of Boot to make the machine first look on the CD/DVD and install the operating system before booting from the hard drive:
VBoxManage modifyvm UbuntuServer --boot1 dvd --boot2 disk --boot3 none --boot4 none
For networking, VirtualBox offers multiple options: NAT, bridge, host-only, internal network, etc. Bridge mode connects the VM directly to the host network, ideal for network testing:
VBoxManage modifyvm UbuntuServer --nic1 bridged --bridgeadapter1 enp2s0
Help: The host network interface name can be obtained with ifconfig (Linux) or ipconfig (Windows).
Start and shut down virtual machines from the terminal
Start the virtual machine:
VBoxManage startvm UbuntuServer
If you prefer to have it start in the background (ideal on servers or for scripting):
VBoxManage startvm UbuntuServer --type headless
Shut down the VM in an orderly manner (by sending an ACPI signal, such as pressing the physical power button):
VBoxManage controlvm UbuntuServer acpipowerbutton
Force immediate shutdown (such as unplugging the cable):
VBoxManage controlvm UbuntuServer poweroff
Restart a virtual machine on the fly:
VBoxManage controlvm UbuntuServer reset
View detailed information and manage the lifecycle of virtual machines
To see all the details of a VM (memory, network, disks, status, etc):
VBoxManage showvminfo UbuntuServer
To register an existing virtual machine (for example, after moving .vbox files):
VBoxManage registervm '/ruta/a/VirtualBox VMs/UbuntuServer/UbuntuServer.vbox'
To unregister (the VM is not deleted from the disk, it just disappears from the VirtualBox listing):
VBoxManage unregistervm UbuntuServer
To delete a VM and all its associated files:
VBoxManage unregistervm --delete UbuntuServer
Clone, export, and import virtual machines
To create an exact copy of a virtual machine, including all its disks and settings, you can refer to How to clone virtual machines in VirtualBox.
To export a virtual machine in OVF format (ideal for migration or backup):
VBoxManage export UbuntuServer --output UbuntuServer.ovf
To import a VM in OVF/Ova format:
VBoxManage import UbuntuServer.ovf
You can examine the characteristics of the OVA image before importing (simulation):
VBoxManage import UbuntuServer.ova --dry-run
Disk and storage media management (HDD, ISO, DVD)
Create additional disks:
VBoxManage createhd --filename /ruta/a/disk-extra.vdi --size 20480 --variant Standard
Add the hard drive to the VM:
VBoxManage storageattach UbuntuServer --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium /ruta/a/disk-extra.vdi
Remove or change the ISO image or disc:
VBoxManage storageattach UbuntuServer --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none
Advanced settings: CPU, dynamic memory, hardware virtualization and other parameters
Modify the number of virtual CPUs:
VBoxManage modifyvm UbuntuServer --cpus 4
Limit CPU usage:
VBoxManage modifyvm UbuntuServer --cpuexecutioncap 50
Enable hardware virtualization (Intel VT-x or AMD-V):
VBoxManage modifyvm UbuntuServer --hwvirtex on
Assign custom RAM and VRAM:
VBoxManage modifyvm UbuntuServer --memory 4096 --vram 256
Adjust the virtual machine description:
VBoxManage modifyvm UbuntuServer --description "Prueba con Ubuntu Server 22.04 LTS"
Network configuration: NAT, bridge, adapters and associated utilities
VirtualBox is especially powerful for virtualized network environments. Depending on the network mode, the VM will be isolated, exposed to the local network, or even on private internal networks between multiple VMs. To manage connections, review How to share folders in VirtualBox and facilitate file sharing on your virtual machines.
Configure network in NAT mode (default):
VBoxManage modifyvm UbuntuServer --nic1 nat
Configure network in bridge mode:
VBoxManage modifyvm UbuntuServer --nic1 bridged --bridgeadapter1 enp3s0
View all network interfaces in bridge mode (useful to know the name of your host adapter):
VBoxManage list bridgedifs
Managing optical drives, ISO images, and extra storage
In addition to the main hard drive, you can mount virtual optical drives, installation ISO images or drivers, and disconnect them after use. For more advanced management, see How to resize virtual disks in VirtualBox.
Add an IDE/SATA controller to storage additional:
VBoxManage storagectl UbuntuServer --name "Controlador Extra" --add sata
Mount an ISO to the virtual optical drive:
VBoxManage storageattach UbuntuServer --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /ruta/completa/imagen.iso
Remove the ISO image:
VBoxManage storageattach UbuntuServer --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none
Automation and scripting with VBoxManage
One of the great advantages of the CLI is the ability to create scripts that automate repetitive processes. For example:
- Create and start multiple virtual machines automatically with bash or batch scripts.
- Automate backups, cloning, exports, or even automatic installations using custom ISO images.
- Launch virtual machines in headless mode for labs or servers without a graphical interface.
Pista: You can use loops in Bash to create multiple VMs by changing only the name and a few parameters. This is widely used in software testing and mass deployments.
Managing extensions and additional features
VirtualBox supports Extension Packs that enable advanced features such as USB 2.0/3.0, VirtualBox RDP, PXE boot for Intel cards, etc. To manage extensions, check How to install extension pack in VirtualBox.
List installed extensions:
VBoxManage list extpacks
Remember to update the Extension Pack when updating VirtualBox to avoid incompatibilities.
Remote management and headless mode
VirtualBox allows you to run and manage virtual machines on headless servers and access them remotely using RDP or other tools.
Starting a machine in headless mode:
VBoxManage startvm UbuntuServer --type headless
Enable VRDP (VirtualBox Remote Desktop Protocol):
VBoxManage modifyvm UbuntuServer --vrde on
You can then connect through any RDP client (such as mstsc on Windows or Remmina on Linux) using the IP and port configured on the host machine.
Advanced Example: Script to Create and Configure a Full VM
If you want to go further, here is a basic example of script (bash-like) that automates the creation and configuration of a VM running Ubuntu 22.04. Customize it as needed.
#!/bin/bash
NAME="UbuntuScriptTest"
VBoxManage createvm --name $NAME --ostype Ubuntu_64 --register
VBoxManage modifyvm $NAME --memory 2048 --cpus 2 --vram 128
VBoxManage createhd --filename $NAME.vdi --size 10240 --variant Standard
VBoxManage storagectl $NAME --name "SATA Controller" --add sata --bootable on
VBoxManage storageattach $NAME --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $NAME.vdi
VBoxManage storagectl $NAME --name "IDE Controller" --add ide
VBoxManage storageattach $NAME --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /ruta/a/ubuntu.iso
VBoxManage modifyvm $NAME --nic1 bridged --bridgeadapter1 enp3s0
VBoxManage startvm $NAME --type headless
And that's it! In less than a minute, you have a VM ready to automatically install Ubuntu.
Master the VirtualBox commands And using it from the command line is an invaluable resource for any virtualization enthusiast, sysadmin, or developer who wants to get the most out of their systems. From scripting automation, advanced network management, machine imports and exports, to quick troubleshooting, the examples compiled and explained here will allow you to tackle almost any challenge. Now that you have all the tricks, commands, and recommendations, put them into practice: your next virtual machine will thank you for it.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.