Skip to content

Instantly share code, notes, and snippets.

@Driste
Last active April 29, 2023 19:12
Show Gist options
  • Save Driste/f1b18eed6fa4b87f672a7e310df48e79 to your computer and use it in GitHub Desktop.
Save Driste/f1b18eed6fa4b87f672a7e310df48e79 to your computer and use it in GitHub Desktop.
VBox CLI

VirtualBox CLI

Download

# For RHEL 7
yum install VirtualBox-5.1-5.1.14_112924_el7-1.x86_64.rpm

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

Virtualbox Extension pack

Download the pack

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

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 managment

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

VM Actions

List

vboxmanage list vms
# "vm" {29c72c20-cf09-4390-be36-f72dc9afd148}

Start

# vboxmanage startvm <VM NAME> --type headless
vboxmanage startvm vm --type headless
# vboxheadless -s <VM NAME>
vboxheadless -s vm

List info

vboxmanage showvminfo <VM NAME>

List Properties

vboxmanage guestproperty enumerate <VM NAME>

Stop

# vboxmanage controlvm <VM NAME> poweroff
vboxmanage controlvm vm poweroff

Delete

# Remove from vbox
vboxmanage unregistervm <VM NAME>
# Remove from vbox and filesystem
vboxmanage unregistervm <VM NAME> --delete

controlvm

Can Modify the VM in any state.


modfiyvm

Requires poweroff of the VM.

Turn the Audio adapter off

vboxmanage modifyvm <VM NAME> --audio none

Bridge Nic

Configure Bridged networking (This tells virtualbox to bridge eno1 to NIC1 on the host) **
vboxmanage modifyvm <VM NAME> --nic1 bridged --bridgeadapter1 eno1

# or add promisc mode (deny|allow-vms|allow-all)
vboxmanage modifyvm <VM NAME> --nic1 bridged --nicpromisc1 allow-all --bridgeadapter1 eno1

Setup VM to start on Host Boot

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 <VM NAME> --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

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