Automate Your VMs Like a Pro with VBoxManage
Ever wanted to automate your VirtualBox VMs without opening the GUI?
Manually starting, stopping, and configuring multiple VMs can be tedious. With VBoxManage and PowerShell, you can automate all of it—modifying resources, managing snapshots, and controlling your VMs from the command line. By the end of this guide, you'll be able to fully automate your VirtualBox workflow for already installed VMs.
Prerequisites
VirtualBox installed (latest version)
PowerShell access
Basic knowledge of the command line
Admin privileges (for some commands)
The examples below use Rocky Linux, but they apply to any Linux distribution with a pre-existing VM.
Configure VM Resources
If you want to adjust RAM, CPUs, or network settings for your existing VM:
# Adjust memory, CPUs, and NIC
VBoxManage modifyvm "RockyLinux" --memory 4096 --cpus 2 --nic1 nat
- Change
--memoryand--cpusto suit your needs. -
--nic1 natprovides internet access through NAT.
Manage Storage (Optional)
If you want to add new virtual disks or controllers:
# Add a new SATA storage controller (if needed)
VBoxManage storagectl "RockyLinux" --name "SATA Controller" --add sata
# Create and attach a 50GB virtual disk
VBoxManage createhd --filename "C:\Users\alok\VirtualBox VMs\RockyLinux\ExtraDisk.vdi" --size 50000
VBoxManage storageattach "RockyLinux" --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium "C:\Users\alok\VirtualBox VMs\RockyLinux\ExtraDisk.vdi"
Start, Pause, and Stop the VM
Control your VM without opening the GUI:
# Start VM (headless mode)
VBoxManage startvm "RockyLinux" --type headless
# Pause the VM
VBoxManage controlvm "RockyLinux" pause
# Resume the VM
VBoxManage controlvm "RockyLinux" resume
# Power off the VM
VBoxManage controlvm "RockyLinux" poweroff
Snapshots
Take and restore snapshots to save or revert VM states:
# Take a snapshot
VBoxManage snapshot "RockyLinux" take "BeforeUpdate"
# Restore a snapshot
VBoxManage snapshot "RockyLinux" restore "BeforeUpdate"
Verify VM Settings
Always check that your changes have applied correctly:
VBoxManage showvminfo "RockyLinux"
Look for updated memory, CPU, NIC, and disk information.
Final Notes
- Use consistent VM names (
RockyLinux) to avoid errors. - All commands are idempotent, meaning you can run them repeatedly without breaking the VM.
- Snapshots are great for testing updates or configuration changes safely.
Top comments (0)