cheat-sheets

VirtualBox

Oracle VirtualBox is a desktop hypervisor for Windows, Linux and macOS. VBoxManage is its command-line interface: use it to create, configure, start and script VMs without the GUI. Vagrant Cheat-Sheet uses VirtualBox as its default provider.

Documentation: VirtualBox User Manual · VBoxManage reference

Verification: every VBoxManage command and option was checked against the official VirtualBox 7.1 User Manual (PDF, chapter 8 synopses and examples). No command was run: VirtualBox could not be installed in the build container. Option spellings changed in 7.x (for example --os-type, --nic-type1, --bridge-adapter1); the manual’s own examples still show older forms such as --ostype, --nic1 and --natpf1, and whether older spellings are still accepted is unverified. Check VBoxManage modifyvm output on your version. Items marked unverified are from general knowledge. Deleting VMs and media is destructive.

See also: libvirt and KVM · Vagrant Cheat-Sheet · Packer · Hypervisors Compared · WSL Cheat-Sheet


Concepts #

TERMMEANING
VM name or UUIDEvery command takes "VM name" or its UUID, shown by VBoxManage list vms
MediumA disk (VDI, VMDK, VHD), DVD or floppy image registered with VirtualBox
Storage controllerThe virtual bus (SATA, IDE, NVMe and so on) that disks attach to
NATDefault network. Guest reaches out, nothing reaches in unless you add port forwarding
NAT NetworkShared NAT between several VMs, they can talk to each other
BridgedGuest appears on the physical LAN
Host-onlyGuest and host only, no outside access
InternalVMs on the same named internal network only
Guest AdditionsDrivers and tools installed inside the guest (shared folders, clipboard, resize)
Extension PackSeparate Oracle download adding USB 2/3, RDP, disk encryption and more. Different licence from VirtualBox itself

Host Basics #

COMMANDDESCRIPTION
VBoxManage -V / VBoxManage --versionInstalled version
VBoxManage list vmsRegistered VMs with UUIDs
VBoxManage list runningvmsRunning VMs
VBoxManage list --long vmsFull detail for every VM
VBoxManage list ostypesValid OS type IDs for --ostype and --os-type
VBoxManage list hostinfoHost CPU and memory
VBoxManage list systempropertiesDefaults, such as the machine folder
VBoxManage list bridgedifsHost interfaces usable for bridged networking
VBoxManage list hostonlyifsHost-only interfaces
VBoxManage list natnetsNAT networks
VBoxManage list hdds / dvds / floppiesRegistered media
VBoxManage list extpacksInstalled extension packs
VBoxManage list usbhostUSB devices on the host
VBoxManage setproperty machinefolder PATHChange the default VM folder
VBoxManage extpack install EXTPACK.vbox-extpackInstall an extension pack (--replace to upgrade)
VBoxManage extpack uninstall "Oracle VirtualBox Extension Pack"Remove it
VBoxManage extpack cleanupRemove stale extension pack files

Create a VM #

createvm makes the VM, modifyvm sets hardware, storagectl and storageattach add disks. Create the disk with createmedium.

COMMANDDESCRIPTION
VBoxManage createvm --name NAME --platform-architecture x86 --ostype OSTYPE --registerNew VM, registered at once. --basefolder DIR chooses where it lives
VBoxManage modifyvm NAME --memory 4096 --cpus 2 --vram 128RAM (MB), CPUs, video memory (MB)
VBoxManage modifyvm NAME --firmware efiUEFI (bios is the other main option)
VBoxManage modifyvm NAME --ioapic onNeeded for more than one CPU on x86
VBoxManage modifyvm NAME --boot1 dvd --boot2 disk --boot3 none --boot4 noneBoot order
VBoxManage modifyvm NAME --graphicscontroller vmsvgaGraphics controller (none, vboxvga, vmsvga, vboxsvga)
VBoxManage modifyvm NAME --tpm-type 2.0Virtual TPM (none, 1.2, 2.0, host, swtpm)
VBoxManage modifyvm NAME --description "TEXT"Description
VBoxManage modifyvm NAME --groups "/GROUP"Put the VM in a group. Empty string removes it
VBoxManage createmedium disk --filename DISK.vdi --size 20480New 20 GB disk (size in MB, or --sizebyte). Formats: VDI, VMDK, VHD via --format
VBoxManage createmedium disk --filename DISK.vdi --size 20480 --variant FixedFixed-size, preallocated disk
VBoxManage storagectl NAME --name "SATA" --add sata --controller IntelAhciAdd a SATA controller
VBoxManage storagectl NAME --name "IDE" --add ideAdd an IDE controller (often used for the install ISO)
VBoxManage storageattach NAME --storagectl "SATA" --port 0 --device 0 --type hdd --medium DISK.vdiAttach the disk
VBoxManage storageattach NAME --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium INSTALL.isoAttach an ISO
VBoxManage storageattach NAME --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium emptydriveEmpty drive
VBoxManage storageattach NAME --storagectl "IDE" --port 0 --device 0 --medium noneRemove the medium from the drive (--forceunmount if the guest has it locked)
bash
VM="web01"
VBoxManage createvm --name "$VM" --platform-architecture x86 \
  --ostype Ubuntu_64 --register
VBoxManage modifyvm "$VM" --memory 4096 --cpus 2 --ioapic on \
  --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage createmedium disk --filename "$HOME/VirtualBox VMs/$VM/$VM.vdi" --size 20480
VBoxManage storagectl "$VM" --name "SATA" --add sata --controller IntelAhci
VBoxManage storageattach "$VM" --storagectl "SATA" --port 0 --device 0 \
  --type hdd --medium "$HOME/VirtualBox VMs/$VM/$VM.vdi"
VBoxManage storagectl "$VM" --name "IDE" --add ide
VBoxManage storageattach "$VM" --storagectl "IDE" --port 0 --device 0 \
  --type dvddrive --medium /path/to/ubuntu.iso
VBoxManage startvm "$VM" --type headless

Ubuntu_64 is an example ID: confirm it with VBoxManage list ostypes.

Unattended Install #

COMMANDDESCRIPTION
VBoxManage unattended detect --iso INSTALL.isoShow whether the ISO is supported for unattended install
VBoxManage unattended install NAME --iso INSTALL.iso --user USER --password-file FILE --hostname HOST.example.com --install-additions --start-vm headlessInstall the OS with no interaction. --start-vm takes a session type such as headless (value list unverified)
VBoxManage unattended install NAME --iso INSTALL.iso --dry-runShow what it would do

The VM must exist, with a disk and storage controller, before unattended install.

Start, Stop and Control #

COMMANDDESCRIPTION
VBoxManage startvm NAMEStart with the GUI window
VBoxManage startvm NAME --type headlessStart with no window. Other types: gui, sdl, separate
VBoxManage controlvm NAME pause / resumePause and resume
VBoxManage controlvm NAME resetHard reset
VBoxManage controlvm NAME acpipowerbuttonPress the ACPI power button (graceful shutdown if the guest handles it)
VBoxManage controlvm NAME shutdownShut down via Guest Additions (--force to force)
VBoxManage controlvm NAME rebootReboot via Guest Additions
VBoxManage controlvm NAME poweroffPull the plug. The guest may lose data
VBoxManage controlvm NAME savestateSave state to disk and stop
VBoxManage discardstate NAMEThrow away a saved state. Unsaved guest state is lost
VBoxManage controlvm NAME screenshotpng FILE.pngScreenshot of the guest display
VBoxManage controlvm NAME setvideomodehint 1920 1080Ask the guest to change resolution
VBoxManage controlvm NAME keyboardputstring "TEXT"Type text into the guest
VBoxManage controlvm NAME clipboard mode bidirectionalShared clipboard (disabled, hosttoguest, guesttohost)
VBoxManage controlvm NAME usbattach UUID_OR_ADDRESS / usbdetachAttach or detach a host USB device (needs the Extension Pack for USB 2/3)
VBoxManage controlvm NAME vrde onEnable the remote display server (needs the Extension Pack)
VBoxManage showvminfo NAMEVM settings and state
VBoxManage showvminfo NAME --machinereadableSame, as key=value lines for scripts
VBoxManage unregistervm NAMERemove the VM from VirtualBox, keep its files
VBoxManage unregistervm NAME --deleteAlso delete its files (disks are kept if shared). Destructive
VBoxManage unregistervm NAME --delete-allDelete all files including media. Destructive

Networking #

Set the adapter type with --nicN (N is 1 to 8 in the GUI, check your version) and the attachment options named in the table.

COMMANDDESCRIPTION
VBoxManage modifyvm NAME --nic1 natNAT (the default)
VBoxManage modifyvm NAME --nic1 bridged --bridge-adapter1 eth0Bridged to a host interface (names from list bridgedifs)
VBoxManage modifyvm NAME --nic2 hostonly --host-only-adapter2 vboxnet0Host-only (name from list hostonlyifs)
VBoxManage modifyvm NAME --nic2 intnet --intnet2 LABNETInternal network
VBoxManage modifyvm NAME --nic2 natnetwork --nat-network2 NATNETNAT Network
VBoxManage modifyvm NAME --nic-type1 virtioAdapter model. Others: Am79C970A, Am79C973, 82540EM, 82543GC, 82545EM
VBoxManage modifyvm NAME --mac-address1 autoNew MAC address. Use it after copying a VM
VBoxManage modifyvm NAME --cable-connected1 offUnplug the virtual cable
VBoxManage modifyvm NAME --nat-pf1 "ssh,tcp,,2222,,22"NAT port forward: host port 2222 to guest port 22. Format name,tcp|udp,host-IP,host-port,guest-IP,guest-port
VBoxManage modifyvm NAME --natpf1 delete "ssh"Delete the rule named ssh. The manual shows both --nat-pf1 and --natpf1 spellings
VBoxManage controlvm NAME natpf1 "ssh,tcp,,2222,,22"Add a forward to a running VM
VBoxManage controlvm NAME nic1 nullChange the attachment of a running VM (null, nat, bridged, intnet, hostonly, generic, natnetwork)
VBoxManage hostonlyif createNew host-only interface. See also hostonlynet below
VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1 --netmask 255.255.255.0Set its IP. On Linux, macOS and Solaris only 192.168.56.0/21 is allowed unless /etc/vbox/networks.conf permits more
VBoxManage hostonlyif remove vboxnet0Remove it
VBoxManage hostonlynet add --name NET --netmask 255.255.255.0 --lower-ip 192.168.56.10 --upper-ip 192.168.56.100Host-only network with a DHCP range (same address restriction on Linux and macOS)
VBoxManage hostonlynet remove --name NETRemove it
VBoxManage natnetwork add --netname NATNET --network "192.0.2.0/24" --enableNew NAT Network
VBoxManage natnetwork modify --netname NATNET --dhcp onEnable its DHCP server
VBoxManage natnetwork start --netname NATNET / stopStart or stop it
VBoxManage natnetwork listList NAT networks
VBoxManage natnetwork remove --netname NATNETDelete it
VBoxManage dhcpserver add --network NET --server-ip IP --lower-ip IP --upper-ip IP --netmask MASK --enableDHCP server for an internal network (--interface IFNAME for a host-only interface)
VBoxManage dhcpserver findlease --network NET --mac-address MACLook up a lease

On Linux, macOS and Solaris, create /etc/vbox/networks.conf to allow other host-only ranges. Each line starts with * followed by the allowed CIDRs, for example * 10.0.0.0/8 192.168.0.0/16.

Snapshots #

COMMANDDESCRIPTION
VBoxManage snapshot NAME take SNAP --description "TEXT"Take a snapshot. --live takes it while running
VBoxManage snapshot NAME listList snapshots (--details or --machinereadable)
VBoxManage snapshot NAME showvminfo SNAPVM settings at that snapshot
VBoxManage snapshot NAME restore SNAPRevert to a snapshot. Current state is lost
VBoxManage snapshot NAME restorecurrentRevert to the most recent snapshot
VBoxManage snapshot NAME edit SNAP --name NEWNAME --description "TEXT"Rename or re-describe
VBoxManage snapshot NAME delete SNAPDelete a snapshot and merge its data into the next. Needs free disk space

Clone, Export and Import #

COMMANDDESCRIPTION
VBoxManage clonevm NAME --name NEWNAME --registerClone and register the copy
VBoxManage clonevm NAME --name NEWNAME --register --mode allClone including all snapshots (machine, machinechildren, all)
VBoxManage clonevm NAME --name NEWNAME --snapshot SNAP --registerClone from a snapshot
VBoxManage clonevm NAME --name NEWNAME --register --options keepallmacsKeep MAC addresses. Repeat --options for keepdisknames and keephwuuids
VBoxManage export NAME --output VM.ovaExport an appliance. Add --manifest for a checksum file or --ovf20 for OVF 2.0
VBoxManage import VM.ova --dry-runShow what would be imported
VBoxManage import VM.ova --vsys 0 --vmname NEWNAMEImport and rename the first virtual system
VBoxManage import VM.ova --options keepallmacsKeep MAC addresses. Others: keepnatmacs, importtovdi
VBoxManage clonemedium DISK.vdi COPY.vdiCopy a disk. --format VMDK converts
VBoxManage clonemedium disk SRC.vdi DST.vmdk --format VMDKConvert VDI to VMDK
VBoxManage convertfromraw IN.img OUT.vdiConvert a raw image into a VirtualBox disk
VBoxManage closemedium disk DISK.vdiUnregister a disk (file stays)
VBoxManage closemedium disk DISK.vdi --deleteUnregister and delete the file. Destructive
VBoxManage showmediuminfo disk DISK.vdiSize, format, type and which VMs use it
VBoxManage modifymedium disk DISK.vdi --resize 40960Grow a disk (size in MB). Resize partitions in the guest after
VBoxManage modifymedium disk DISK.vdi --compactCompact a dynamic disk (zero free space in the guest first)
VBoxManage modifymedium disk DISK.vdi --type immutableMedium type: normal, writethrough, immutable, shareable, readonly, multiattach
VBoxManage modifymedium disk DISK.vdi --move NEWPATHMove the disk file

To use a VirtualBox disk with libvirt and KVM, convert it with qemu-img convert -f vdi -O qcow2 IN.vdi OUT.qcow2.

Guest Control and Shared Folders #

Needs Guest Additions running in the guest.

COMMANDDESCRIPTION
VBoxManage guestcontrol NAME run --exe /bin/ls --username USER --passwordfile FILE --wait-stdout -- ls -l /tmpRun a program in the guest and show its output
VBoxManage guestcontrol NAME copyto --username USER --passwordfile FILE --target-directory /tmp LOCALFILECopy a file into the guest (--recursive for directories)
VBoxManage guestcontrol NAME copyfrom --username USER --passwordfile FILE --target-directory HOSTDIR /tmp/FILECopy a file out of the guest
VBoxManage guestcontrol NAME mkdir --username USER --passwordfile FILE /tmp/DIRCreate a directory in the guest
VBoxManage guestproperty enumerate NAMEAll guest properties (IP, OS, Additions version)
VBoxManage guestproperty get NAME /VirtualBox/GuestInfo/Net/0/V4/IPOne property, here the first NIC’s IPv4 address
VBoxManage guestproperty set NAME PROPERTY VALUESet a property. unset NAME PROPERTY removes it
VBoxManage sharedfolder add NAME --name SHARE --hostpath HOSTDIR --automountShare a host folder (--readonly, --transient, --auto-mount-point PATH)
VBoxManage sharedfolder remove NAME --name SHARERemove it
VBoxManage setextradata NAME KEY VALUESet extra data (advanced settings)
VBoxManage getextradata NAME enumerateList extra data

Prefer --passwordfile over --password, which exposes the password in the process list.

Other #

COMMANDDESCRIPTION
VBoxManage modifyvm NAME --autostart-enabled onAllow autostart (needs the host autostart service set up, unverified)
VBoxManage modifyvm NAME --nested-hw-virt onExpose virtualisation to the guest
VBoxManage modifyvm NAME --paravirt-provider kvmParavirtualisation interface. Others: none, default, legacy, minimal, hyperv
VBoxManage modifyvm NAME --vrde onRemote display server
VBoxManage modifyvm NAME --snapshot-folder PATHSnapshot location
VBoxManage modifynvram NAME inituefivarstoreInitialise the UEFI variable store
VBoxManage modifynvram NAME secureboot --enableEnable Secure Boot
VBoxManage metrics query NAMEPerformance counters
VBoxManage updatecheck performCheck for a new VirtualBox release

Troubleshooting #

SYMPTOMFIX
Start fails with a kernel driver error on LinuxThe vboxdrv module is not loaded. Rebuild it with sudo rcvboxdrv setup. With UEFI Secure Boot the kernel modules must be signed (see the manual’s Kernel Modules and UEFI Secure Boot section)
VirtualBox fails to start with Hyper-V or WSL2 enabled on WindowsBoth want the hypervisor. Disable Hyper-V and the Windows Hypervisor Platform, or accept the slower fallback (WSL Cheat-Sheet)
VBoxManage says the VM is lockedAnother session holds it. Close the GUI or run VBoxManage controlvm NAME poweroff
VM is not listed after copying its folderRegister it: VBoxManage registervm /path/NAME.vbox
Cloned VM clashes on the networkGive it a new MAC with --mac-address1 auto and change the guest hostname
No IP via host-onlyCheck the interface has an IP and that a DHCP server is attached for it
Command option rejectedSpelling differs between 6.x, 7.0 and 7.1. Run VBoxManage modifyvm with no arguments to see the usage for your version

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.