Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Forked from Driste/vbox_cli.md
Last active January 3, 2018 23:42
Show Gist options
  • Save pythoninthegrass/6d4c08d71f6a7a8955cb1bca36faa386 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/6d4c08d71f6a7a8955cb1bca36faa386 to your computer and use it in GitHub Desktop.
VBox CLI

VirtualBox CLI

Installation

Mac

brew cask install virtualbox virtualbox-extension-pack

Linux

Linux Download

# For RHEL 7
yum install VirtualBox

VirtualBox Extension pack

Download the pack

vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.1.14-112924.vbox-extpack 

Setting Up

vboxconfig
# VBox Config might recommend to update the kernel, for my box:
yum install kernel-devel-3.10.0-327.el7.x86_64

Importing

Setting up VM from scratch:

Refer to Guide

Existing VM in ova or ovf format:

vboxmanage import vm.ovf --dry-run
# See if any of the settings need to be changed
vboxmanage import prevalent.ovf --vsys 0 --memory 10240

Configure for remote management

# vboxmanage modifyvm vm --vrde on --vrdeport <PORT> --vrdeaddress <HOST IP>
vboxmanage modifyvm vm --vrde on --vrdeport 5012 --vrdeaddress 10.254.30.118

VM Actions

Create vm

VBoxManage createvm --name "windows_10" --register

List vm

VBoxManage list vms

List info

vboxmanage showvminfo "windows_10"

List Properties

vboxmanage guestproperty enumerate "windows_10"

Modify vm

VBoxManage modifyvm "windows_10" --memory 2048

Start vm

VBoxManage startvm "windows_10"

Start vm (without gui)

VBoxManage startvm "windows_10" --type headless

List of running vm

VBoxManage list runningvms

OUTPUT

"windows_10" {fa38d6fe-f302-48f3-aa88-86c49115ea3c}

Stop vm

VBoxManage controlvm "windows_10" poweroff soft

Snapshot vm

VBoxManage snapshot "windows_10" take "Aug 1 - windows_10"

Restore vm

VBoxManage snapshot "windows_10" restore "Aug 1 - windows_10"

Delete vm

# Remove from vbox
vboxmanage unregistervm "windows_10"
# Remove from vbox and filesystem
vboxmanage unregistervm "windows_10" --delete

controlvm

  • Can Modify the VM in any state.

modfiyvm

  • Requires poweroff of the VM.

Turn the Audio adapter off

vboxmanage modifyvm "windows_10" --audio none

Bridge NIC

Configure Bridged networking (This tells VirtualBox to bridge eno1 to NIC1 on the host)

vboxmanage modifyvm "windows_10" --nic1 bridged --bridgeadapter1 eno1

# or add promisc mode (deny|allow-vms|allow-all)
vboxmanage modifyvm "windows_10" --nic1 bridged --nicpromisc1 allow-all --bridgeadapter1 eno1

Setup VM to start on Host Boot

Linux

  • RHEL or SYSTEMCTL systems

Create the config file /etc/vbox/autostart.cfg

# If you are the only user set it to allow
default_policy = allow

Create the Virtualbox Defaults file /etc/default/virtualbox

VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

Enable Autostart

VBoxManage modifyvm "windows_10" --autostart-enabled on

Set the autostartdbpath property

VBoxManage setproperty autostartdbpath /etc/vbox

Reload the service

# RHEL or SYSTEMCTL systems
sudo systemctl restart vboxautostart-service

# Other older systems
sudo service vboxautostart-service restart

References:

VirtualBox Useful Commands · GitHub
VBox CLI · GitHub
VirtualBox Download
VBoxManage Manual
Virtualbox in Terminal
VRDE Romote managment
https://www.virtualbox.org/manual/ch07.html#vboxheadless https://www.virtualbox.org/manual/ch08.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment