When we are testing something on the server, it’s convenient and safe to do all the things in the virtual machine to avoid crash. And this blog records the tips to use the headless virtual box.
1. Create a virtual machine
Create the headless server with specific name and ostype
VBoxManage modifyvm "xxx" --memory 2048 --acpi on --boot1 dvd --nic1 nat
Create a virtual hard disk for the VM, make sure to allocate enough space. Even though, we can change the size later, there are more complex steps to change the partition.
In some special situation, the server only expose a few port, you can not using the VRDP to connect with the headless VirtualBox in port 3389 (default port for rdp protocol) directly. You can deal with this problem with port forwarding. Run the following command in your own PC to forward the request to the server in port 3389. By doing so, you can visit any port in the server as long as you can connect into the server in port 22 and pass the authentication.
nohup VBoxHeadless --startvm "xxx" & # start the VM
VBoxManage controlvm "xxx" savestate # stop the VM and save the state VBoxManage discardstate "xxx" # discard the state
vboxmanage startvm "xxx" --type emergencystop # stop the VM without save the state
Manage the snapshot
1 2 3 4
VBoxManage snapshot "xxx" list # list the snapshot VBoxManage snapshot "xxx" take "yourDiscribe" --live # take the snapshot VBoxManage snapshot "xxx" restore "snapshotID" # restore the snapshot VBoxManage snapshot "xxx" delete "snapshotID" # delete the snapshot
List info
1 2
VBoxManage list vms # list the existing VM VBoxManage list runningvms # list running VM