Virtualbox with Ubuntu Server

Manage Virtualbox in command line

Installation

sudo apt install virtualbox

# or manually
# wget https://download.virtualbox.org/virtualbox/5.2.22/virtualbox-5.2_5.2.22-126460~Ubuntu~bionic_amd64.deb
# sudo dpkg -i virtualbox*.deb

Install extenstion pack

sudo apt install virtualbox-ext-pack 

# or manually
# sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.4-119785.vbox-extpack

# check installation
VBoxManage list extpacks

Create VM

VBoxManage createmedium disk --filename ubuntu-server1.vdi --size 8192
VBoxManage list ostypes | grep -B 1 -A 2 Ubuntu
VBoxManage createvm --name ubuntu-server1 --ostype "Ubuntu_64" --register
# add sata disk
VBoxManage storagectl ubuntu-server1 --name SATA --add sata --controller IntelAHCI
VBoxManage storageattach ubuntu-server1 --storagectl SATA --port 0 --device 0 --type hdd --medium ubuntu-server1.vdi

# mount dvd bootable iso file
VBoxManage storagectl ubuntu-server1 --name IDE --add ide
VBoxManage storageattach ubuntu-server1 --storagectl IDE --port 0 --device 0 --type dvddrive --medium ~/Downloads/mini.iso
VBoxManage modifyvm ubuntu-server1 --ioapic on
VBoxManage modifyvm ubuntu-server1 --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage modifyvm ubuntu-server1 --memory 512 --vram 8
VBoxManage modifyvm ubuntu-server1 --nic1 nat
VBoxManage setproperty vrdeextpack "Oracle VM VirtualBox Extension Pack"
# vrde port 5000, 5010, 5011 or 5012
VBoxManage modifyvm ubuntu-server1 --vrde on --vrdeport 5000,5010-5012 
VBoxManage startvm ubuntu-server1 --type headless
VBoxManage showvminfo ubuntu-server1

Test it rdesktop -a 16 -N <HOST-IP>:<PORT>

VBoxManage storageattach ubuntu-server1 --storagectl IDE --port 0 --device 0 --type dvddrive --medium none
VBoxManage snapshot ubuntu-server1 take <SNAPSHOT-NAME>
VBoxManage snapshot ubuntu-server1 restore <SNAPSHOT-NAME>
vboxmanage showvminfo <VM Name>

Network

Host-only Network

VBoxManage hostonlyif create
VBoxManage list hostonlyif
VBoxManage  hostonlyif remove vboxnet1

Common scripts

#!/bin/bash

vms=(
    ubuntu-server1
    ubuntu-server2
    ubuntu-server3
)

for vm in ${vms[*]}; do
    VBoxManage startvm ${vm} --type headless
done
#!/bin/bash

vms=(
    ubuntu-server1
    ubuntu-server2
    ubuntu-server3
)

for vm in ${vms[*]}; do
    echo ${vm}
    VBoxManage controlvm ${vm} poweroff
done
#!/bin/bash

vms=(
    ubuntu-server1
    ubuntu-server2
    ubuntu-server3
)

for i in $( seq 1 3 ); do
    VBoxManage modifyvm "ubuntu-server${i}" --vrde on --vrdeport "500${i}"
done
#!/bin/bash

for i in $( seq 1 3 ); do
    printf "connect to: 127.0.0.1:500${i}\n"
    rdesktop -a 16 -N -T "ubuntu-server${i}" "127.0.0.1:500${i}" &
done

MacOS on virtualbox

VBoxManage modifyvm "macOS" --cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff

VBoxManage setextradata "macOS" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac11,3"

VBoxManage setextradata "macOS" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"

VBoxManage setextradata "macOS" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple"

VBoxManage setextradata "macOS" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"

VBoxManage setextradata "macOS" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1

VBoxManage setextradata "macOS" "VBoxInternal2/EfiGraphicsResolution" "1920x1080"

Reference: https://www.virtualbox.org/wiki/Mac%20OS%20X%20build%20instructions

TroubleShouting