How to create a headless VirtualBox guest machine on Ubuntu Linux

|

|

This post provides a tutorial on installing a headless VirtualBox guest machine on Ubuntu Linux. Headless installation refers to installing and running VirtualBox without a direct monitor, typically through a remote terminal. The tutorial details steps from installing VirtualBox, setting up a guest machine, to modifying OS settings and remotely accessing the guest machine.

This post describes installing or creating a headless VirtualBox guest machine in Ubuntu Linux.

Headless installation is when you install and run VirtualBox on a server without a direct monitor or desktop environment via a remote terminal. The GUI-less installation of VirtualBox is typical in server environments.

Headless installation of VirtualBox is generally used in server environments where there is no need for a graphical user interface (GUI), and the installation and management of the VirtualBox guest machines can be done remotely via a command-line interface (CLI).

It also allows for more efficient use of resources since the machine can run without the overhead of a GUI and can be easily managed and automated through scripts.

How to install a headless VirtualBox guest machine in Ubuntu Linux

As described above, one can install a headless VirtualBox guest machine in Ubuntu Linux.

The host server must be installed before installing a guest OS on VirtualBox software. Click the link below to learn how to install VirtualBox on Ubuntu Linux.

How to install VirtualBox on Ubuntu Linux

Once VirtualBox is installed, you can begin installing a headless guest OS.

To create a VirtualBox guest machine called Ubuntu_2204, follow the guide below.

First, create a location to store all the guest machines and configuration files. Then, run the commands below to create a folder in the /var directory called vbox.

sudo mkdir -p /var/vbox

Then run the commands below to create your first guest machine named Ubuntu_2204 and store the configurations in /var/vbox

sudo VBoxManage createvm --name Ubuntu_2204 --ostype Ubuntu_64 --register --basefolder /var/vbox

After running the commands above, run the commands below to view information about the guest OS you created.

sudo VBoxManage showvminfo Ubuntu_2204

You should see something like the content below:

Name: Ubuntu_2204
Groups: /
Guest OS: Ubuntu (64-bit)
UUID: 7ff8048e-b6d8-49ca-b21a-ad0fc04ba6d3
Config file: /var/vbox/Ubuntu_2204/Ubuntu_1710.vbox
Snapshot folder: /var/vbox/Ubuntu_2204/Snapshots
Log folder: /var/vbox/Ubuntu_1710/Logs
Hardware UUID: 7ff8048e-b6d8-49ca-b21a-ad0fc04ba6d3
Memory size: 128MB
Page Fusion: off
VRAM size: 8MB
CPU exec cap: 100%
-------------
-------------

Next, modify the guest OS to increase the system memory, include a virtual DVD drive, and enable VRDP (Virtual Remote Desktop Protocol) to access the guest machine remotely by running the commands below.

sudo VBoxManage modifyvm Ubuntu_2204 --memory 1024 --boot1 dvd --vrde on --vrdeport 5001

Add a network adapter and NAT it by running the commands below. If you want it to be bridged, change NAT to bridged.

sudo VBoxManage modifyvm Ubuntu_2204 --nic1 nat

Next, create a storage SATA controller named Ubuntu_2204_SATA

sudo VBoxManage storagectl Ubuntu_1710 --name "Ubuntu_2204_SATA" --add sata

Next, create a virtual HDD with a 10GB size and format it as VDI with the standard variant.

sudo VBoxManage createhd --filename /var/box/Ubuntu_2204.vdi --size 10280 --format VDI --variant Standard

Next, attach the virtual hard disk created above to the VM.

To do that, run the commands below:

sudo VBoxManage storageattach Ubuntu_2204 –-storagectl Ubuntu_1710_SATA –-port 1 –-type hdd –-medium /var/box/Ubuntu_1710.vdi

Next, attach the downloaded operating system ISO file to the VM by running the commands below.

sudo VBoxManage storageattach Ubuntu_2204 --storagectl Ubuntu_2204_SATA --port 0 --type dvddrive --medium /tmp/Ubuntu_2204-server-amd64.iso

When you run the showvminfo commands, you should see the new guest machine config settings.

Name: Ubuntu_2204
Groups: /
Guest OS: Ubuntu (64-bit)
UUID: 7ff8048e-b6d8-49ca-b21a-ad0fc04ba6d3
Config file: /var/vbox/Ubuntu_2204/Ubuntu_2204.vbox
Snapshot folder: /var/vbox/Ubuntu_2204/Snapshots
Log folder: /var/vbox/Ubuntu_2204/Logs
Hardware UUID: 7ff8048e-b6d8-49ca-b21a-ad0fc04ba6d3
Memory size: 1024MB
Page Fusion: off
VRAM size: 8MB
CPU exec cap: 100%
HPET: off
Chipset: piix3
Firmware: BIOS
Number of CPUs: 1
PAE: on
Long Mode: on
Triple Fault Reset: off

Now that everything is ready, run the commands below to start the guest machine.

sudo VBoxManage startvm Ubuntu_2204 --type headless

You should see the message that the machine has started

Waiting for VM "Ubuntu_2204" to power on.
VM "Ubuntu_2204" has been successfully started.

Now open Remote Desktop Connection on your Windows machine and connect to the server IP followed by port 5001

You should be able to install the guest machine remotely via RDP.

Enjoy!

Like this:



2 responses to “How to create a headless VirtualBox guest machine on Ubuntu Linux”

  1. Michael Avatar
    Michael

    I believe you forgot to add step

    sudo VBoxManage storageattach Ubuntu16 –storagectl Ubuntu16_SATA –port 2 –type hdd –medium /var/box/Ubuntu16.vdi

    1. !robot Avatar
      !robot

      Thanks… post upadted

Leave a Reply to Michael Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.