Skip to content
@deckyard/virtualbox

virtualbox cheatsheet

Every export of @deckyard/virtualbox. Guides are listed in the introduction.

jennifer
import "@deckyard/virtualbox/" as virtualbox;

Every failure is Error{kind: "virtualbox"}. A c argument is a Config, an h a Host, a vm a machine's name or UUID.

Constants

ConstantValueMeaning
DEFAULT_TIMEOUT_MS60000how long an ordinary call may run
DEFAULT_LONG_TIMEOUT_MS3600000how long an import, export, clone or snapshot may run
MIN_MAJOR7the oldest VirtualBox major version open accepts

Connecting

FunctionReturnsDoes
virtualbox.local()Configrun VBoxManage from PATH here
virtualbox.remote(prefix)Configrun it through ssh (a prefix that hands one command line to a POSIX remote login shell); every argument is quoted for sh, and \ and ! are refused
virtualbox.withBinary(c, binary)Configanother VBoxManage program
virtualbox.withTimeout(c, ms)Configthe deadline of an ordinary call, 1 to 86400000 ms
virtualbox.withLongTimeout(c, ms)Configthe deadline of import, export, clone, snapshots and guest copies
virtualbox.open(c)Hostrun VBoxManage --version; refuse VirtualBox older than 7
virtualbox.run(h, args)stringany other subcommand, arguments as given; its output
virtualbox.errorCode(e)stringthe VBOX_E_* / E_* / NS_ERROR_* code of a caught error, "" if none

Inventory

FunctionReturnsDoes
virtualbox.vms(h)list of Vmevery registered machine
virtualbox.runningVms(h)list of Vmthe running ones
virtualbox.hasVm(h, vm)boolwhether a machine is registered
virtualbox.osTypes(h)list of OsTypethe guest OS types, for create
virtualbox.hdds(h)list of Mediumthe virtual disks
virtualbox.hostOnlyIfs(h)list of HostOnlyIfthe host-only interfaces
virtualbox.natNets(h)list of NatNetthe NAT networks
virtualbox.hostInfo(h)HostInfothe host's processors, memory and OS

Machines

FunctionReturnsDoes
virtualbox.info(h, vm)VmInfostate, hardware, NICs, forwards, storage, folders
virtualbox.state(h, vm)stringpoweroff, running, paused, saved, ...
virtualbox.create(h, name, osType)stringcreate and register a machine; its UUID
virtualbox.createIn(h, name, osType, baseFolder)stringthe same, under another folder
virtualbox.register(h, settingsFile)nullregister a .vbox file
virtualbox.unregister(h, vm)nullunregister, keeping the files
virtualbox.delete(h, vm)nullunregister and delete the files
virtualbox.setCpus(h, vm, cpus)nullprocessors, 1 to 64
virtualbox.setMemory(h, vm, memoryMb)nullmemory, 4 to 2097152 MiB
virtualbox.setFirmware(h, vm, firmware)nullbios, efi, efi32, efi64
virtualbox.setNic(h, vm, index, attachment, network)nullattach NIC 1 to 36: nat, bridged, hostonly, intnet, natnetwork, null, none
virtualbox.addController(h, vm, name, bus)nulla storage controller: ide, sata, scsi, floppy, sas, usb, pcie, virtio
virtualbox.attachDisk(h, vm, controller, port, device, path)nulla disk image on a port; VBoxManage's medium keywords (none, host:...) are refused
virtualbox.attachDvd(h, vm, controller, port, device, path)nulla DVD drive with an .iso, or emptydrive
virtualbox.detach(h, vm, controller, port, device)nullempty a port
virtualbox.createDisk(h, path, sizeMb)stringa dynamically growing .vdi; its UUID

Power and port forwards

FunctionReturnsDoes
virtualbox.start(h, vm)nullstart without a window
virtualbox.startWith(h, vm, mode)nullstart headless, gui or separate
virtualbox.powerOff(h, vm)nullpull the plug
virtualbox.acpiShutdown(h, vm)nullpress the power button; the guest shuts down
virtualbox.pause(h, vm)nullpause
virtualbox.resume(h, vm)nullresume
virtualbox.reset(h, vm)nullpress reset
virtualbox.saveState(h, vm)nullsave the state to disk and stop
virtualbox.forwards(h, vm)list of Forwardthe NAT port forwards of every NIC
virtualbox.forward(nic, name, hostPort, guestPort)Forwarda TCP rule on all host addresses
virtualbox.addForward(h, vm, rule)nulladd a rule, running or stopped
virtualbox.removeForward(h, vm, nic, name)nullremove a rule

Snapshots, clones, appliances

FunctionReturnsDoes
virtualbox.snapshots(h, vm)list of Snapshotthe snapshot tree, parents first
virtualbox.takeSnapshot(h, vm, name, description)stringtake one; its UUID
virtualbox.restoreSnapshot(h, vm, name)nullgo back to one (machine off)
virtualbox.deleteSnapshot(h, vm, name)nulldelete one
virtualbox.clone(h, vm, newName)nulla full, registered copy
virtualbox.linkedClone(h, vm, snapshot, newName)nulla copy on difference disks from a snapshot
virtualbox.importOva(h, path)nullimport an .ova / .ovf
virtualbox.importAs(h, path, name)nullthe same, naming the machine
virtualbox.exportOva(h, vm, path)nullexport to an .ova / .ovf

The guest

FunctionReturnsDoes
virtualbox.guestProperty(h, vm, key)stringa guest property, "" when unset
virtualbox.setGuestProperty(h, vm, key, value)nullset one
virtualbox.unsetGuestProperty(h, vm, key)nullremove one
virtualbox.guestIp(h, vm, nic)stringthe IPv4 address of guest interface nic (from 0), "" if none yet
virtualbox.waitForIp(h, vm, nic, timeoutMs)stringwait for that address
virtualbox.credentials(username, password)Credentialsa guest account
virtualbox.guestRun(h, vm, account, argv)GuestResultrun a program in the guest and wait; how it ended and its own exit code
virtualbox.copyTo(h, vm, account, hostPath, guestPath)nullcopy a file into the guest
virtualbox.copyFrom(h, vm, account, guestPath, hostPath)nullcopy a file out of the guest
virtualbox.sharedFolders(h, vm)list of SharedFolderthe shared folders
virtualbox.addSharedFolder(h, vm, name, hostPath, readOnly, autoMount)nullshare a host directory
virtualbox.removeSharedFolder(h, vm, name)nullstop sharing it

Types

Config

FieldMeaning
binary as stringthe VBoxManage program
prefix as list of stringthe command it runs under; empty to run it here
timeoutMs as intthe deadline of an ordinary call
longTimeoutMs as intthe deadline of the long operations

Host

FieldMeaning
config as Confighow it is reached
version as stringVBoxManage --version, such as 7.1.4r165100
major as intthe major version
minor as intthe minor version

Vm

FieldMeaning
name as stringthe machine's name
uuid as stringits UUID

OsType

FieldMeaning
id as stringthe id create takes, such as Ubuntu_64
description as stringits name
familyId as stringthe family, such as Linux
familyDescription as stringthe family's name
is64Bit as boola 64-bit OS

Medium

FieldMeaning
uuid as stringthe disk's UUID
parentUuid as stringits parent, base for a base disk
state as stringcreated, inaccessible, ...
type as stringnormal (base), normal (differencing), ...
location as stringits file
format as stringVDI, VMDK, VHD, ...
capacityMb as intits size in MiB

HostOnlyIf

FieldMeaning
name as stringsuch as vboxnet0
ip as stringthe host's IPv4 address on it
netmask as stringits network mask
dhcp as boolconfigured by DHCP
status as stringUp or Down
mac as stringits hardware address

NatNet

FieldMeaning
name as stringthe network's name
network as stringsuch as 10.0.2.0/24
gateway as stringthe gateway address
dhcp as boolits DHCP server is on
enabled as boolit is enabled
ipv6 as boolIPv6 is on

HostInfo

FieldMeaning
processors as intlogical processors
cores as intprocessor cores
processor as stringthe first processor's description
hardwareVirtualization as boolVT-x or AMD-V
memoryMb as intmemory in MiB
memoryAvailableMb as intfree memory in MiB
os as stringthe host OS
osVersion as stringits version

Nic

FieldMeaning
index as intthe slot, from 1
attachment as stringin lower case: nat, bridged, hostonly, intnet, natnetwork, generic, ...
model as stringthe emulated card
mac as string12 hex digits
connected as boolthe cable is connected
network as stringthe host interface or network it is attached to

Forward

FieldMeaning
nic as intthe NIC, from 1
name as stringthe rule's name
protocol as stringtcp or udp
hostIp as stringthe host address, "" for all
hostPort as intthe host port
guestIp as stringthe guest address, "" for its DHCP address
guestPort as intthe guest port

Controller

FieldMeaning
name as stringsuch as SATA
type as stringthe emulated chip
ports as intits port count
bootable as boolthe machine may boot from it

Attachment

FieldMeaning
controller as stringthe controller
port as intthe port
device as intthe device on it
medium as stringthe image file, or emptydrive

SharedFolder

FieldMeaning
name as stringits name in the guest
hostPath as stringthe host directory
scope as stringmachine, transient (until the machine stops) or global (every machine)

VmInfo

FieldMeaning
name as stringthe machine's name
uuid as stringits UUID
osType as stringits guest OS type, as described
state as stringpoweroff, running, ...
memoryMb as intmemory in MiB
vramMb as intvideo memory in MiB
cpus as intprocessors
firmware as stringBIOS, EFI, ...
configFile as stringits .vbox file
guestAdditions as stringthe running Guest Additions' version, "" if none
currentSnapshot as stringthe current snapshot's name
nics as list of Nicthe enabled NICs
forwards as list of Forwardthe NAT port forwards
controllers as list of Controllerthe storage controllers
attachments as list of Attachmentwhat is attached to them
sharedFolders as list of SharedFolderthe shared folders
raw as map of string to stringevery showvminfo --machinereadable value

Snapshot

FieldMeaning
name as stringits name
uuid as stringits UUID
description as stringits description
depth as int0 for a first snapshot, 1 below it, ...
current as boolthe machine runs from it

Credentials

FieldMeaning
username as stringthe guest user
password as stringthe password, passed through a named pipe, never on disk or a command line

GuestResult

FieldMeaning
status as stringexited, killed (by a signal) or abnormal
exitCode as intits exit code when exited: 0 to 93, -1 for 94 or more; -1 otherwise
stdout as stringits standard output
stderr as stringits error output