Installing virtualbox plus GUI ubuntu 16.04

Problem

Had virtual box installed and was using it from the command line. The process of creating a new virtual machine using this approach proved difficult. Tools like vagrant make this process easier but I needed to share this image with a non vagrant user.

Solution

Installed the default version of virtualbox that comes with ubuntu 16.04.

When I tried installing the latest version of virtual box, I would get the following error when starting a newly defined image:


Failed to open a session for the virtual machine bandago.

The virtual machine 'vmImage' has terminated unexpectedly during startup with exit code 1 (0x1).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: MachineWrap
Interface: IMachine {85cd948e-a71f-4289-281e-0ca7ad48cd89}

The solution maybe to after installing virtualbox, additionally installing the following packages:

(I never got to test this though)

vde2

virtualbox-guest-additions-iso

virtualbox-qt

Solution

Install virtualbox and the above packages:


imela@whiscardz ~ $ sudo apt-get install virtualbox virtualbox-guest-additions-iso virtualbox-qt
Reading package lists... Done
Building dependency tree
Reading state information... Done
virtualbox is already the newest version (5.1.38-dfsg-0ubuntu1.16.04.2).
The following NEW packages will be installed:
virtualbox-guest-additions-iso virtualbox-qt
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 47.4 MB of archives.
After this operation, 87.4 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Note: After defining a new vm, when it’s time to link the ISO, double click on the vm definition and then select the iso.

References

Creating a Virtual Machine

Installing Oracle VM VirtualBox and Extension Packs

Oracle Linux_Downloads

How to Install VirtualBox 5.2 on Ubuntu 16.04 LTS

Exporting and Importing Virtual Box Images

Problem

Needed to save a virtual box image to be shared with someone else

Solution

Using vboxmanage command line to export the image and then test importing the image.

Steps

  • First list the virtual box images available

imela@whiscardz$ vboxmanage list vms
"test_default_1549514247520_18667" {6e29d56a-6531-4274-9d91-c6719e9fdaf3}
  • Then export the image you want to a file

imela@whiscardz$ vboxmanage export test_default_1549514247520_18667 -o test_default_1549514247520_18667.ova

  • Then copy it to the machine that you want to import the image.
  • Finally import the image.

imela@whiscardz2$ vboxmanage import test_default_1549514247520_18667.ova
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Potential Issues

When I tried exporting to a file name other than the name of the image, it failed and threw the error below (it could be the extention):


imela@whiscardz2$ vboxmanage export test_default_1549514247520_18667 --output otherFileName.ovf
0%...
Progress state: VBOX_E_IPRT_ERROR
VBoxManage: error: Appliance write failed
VBoxManage: error: RTVfsFsStrmAdd failed for 'otherFileName.ovf' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component ApplianceWrap, interface IAppliance
VBoxManage: error: Context: "RTEXITCODE handleExportAppliance(HandlerArg*)" at line 1263 of file VBoxManageAppliance.cpp

References

How to export and import VirtualBox VM images?

VBoxManage registervm/unregistervm

Export to OVF

VBoxManage export

VBoxManage import

virtualbox commandline options

Update 2019-01-15

Problem

Also needed to delete virtual box images that were not being used via the command line

Solution

  • First list the vms

$ VBoxManage list vms
"20180126" {00953737-12d0-49eb-a1d2-c749047ccacf}
"1519895285801_90671" {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3}
"1522057779833_1088" {87021084-3202-4131-8f9c-5839774140a8}
  • Use the unregistervm flag along with the –delete option to delete the vm and it’s associated files.

$ vboxmanage unregistervm {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3} --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Problem

Needed a way to be able to start and stop GuestOS on virtualbox using the commandline.

Solution

  • First list the vms

$ VBoxManage list runningvms
"academy_default_1522238466753_84362" {3a36e205-e8e2-4a96-b9c3-9f76f2ad17e5}

Here are some more options that can be used with the list command. NB If your vm was started with a specific user then running list without switching to the user that started the vm causes the result to be blank:


~$ vboxmanage list
Usage:

VBoxManage list [--long|-l] [--sorted|-s] vms|runningvms|ostypes|hostdvds|hostfloppies|
intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|
hostinfo|hostcpuids|hddbackends|hdds|dvds|floppies|
usbhost|usbfilters|systemproperties|extpacks|
groups|webcams|screenshotformats

  • Then shutdown the vms

~$ vboxmanage controlvm "academy_default_1522238466753_84362" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
:~$ vboxmanage list runningvms
:~$

References

vboxmanage command line options

How to safely shutdown Guest OS in VirtualBox using command line

How to automatically start and shut down VirtualBox machines?

VBoxManage control and manage Virtualbox from command line

How to run VirtualBox virtual machines from the command line

VBoxManage registervm/unregistervm or delete vm

 

Virtual Box – Port Forward Guest to Host

Problem

Needed to assess a web port on the Guest VM on Virtual Box.

Solution

From the virtualbox manager gui, right click on the vm, click on settings, then click on network. Select NAT, then click on advanced and then port forwarding.

Choose a host port, the guest port should be port 80. You dont have the include the guest and host ip as this will allow connections from any host.

Update 2019 March 06

You need to choose a large number for the port on the host otherwise vbox might not allow you to port forward to a lower port number such as 222.

Use NAT and then port forward Guest to Host
Guest to Host port forwarding using NAT

References

How to access a NAT guest from host with VirtualBox

NAT Port Forwarding in VirtualBox

How to Forward Ports to a Virtual Machine and Use It as a Server

How To: Port Forwarding on VirtualBox