Oracle’s open source VirtualBox offers a solid GUI for managing virtual machines. But sometimes you’d prefer to use the command line. Here’s how.
Dec 28th, 2024 7:00am by 

If you’ve finally started working with VirtualBox virtual machines, you’ve probably found the software incredibly easy to use. With Oracle’s VirtualBox, you can create and deploy virtual machines of your favorite Linux distribution for testing or daily usage, Windows and even macOS.

Here’s the thing: if you create a virtual machine instance of a server OS, you probably don’t want to keep the VirtualBox GUIs running so a headless server can be reached. GUIs not only take up system resources, but they could also make it easy for some unwitting person to step up to your desktop and stop a running server.

Should you run into such a case, you’ll want to know how to run those virtual machines from the command line.

Not only does this mean you’ll save precious CPU cycles and RAM, but you can also manage those VMs remotely. SSH into the host and start, pause, stop and even delete your virtual machines.

Let me show you how this is done.

What You’ll Need

To make this work, you’ll need a running instance of VirtualBox installed on a Linux host. You’ll also need a user with sudo privileges. That’s it — let’s get to work.

Installing the VirtualBox Extension Pack

The first thing you must do is install the VirtualBox Extension Pack. With the extension pack, any virtual machine that is started from the command line will not have access to the network. Without an available network, those virtual machines are pretty useless.

To install the VirtualBox extension pack, do the following:

 

Screenshot

 Zoom

Figure 1: If the extension pack has already been installed, it’ll be listed here.

 

Now that the extension pack is installed (it should be listed in the Manager), you’re ready to start working with your virtual machines from the command line.

List Your Virtual Machines

To manage your virtual machines, you have to know their full names, which can be found with the command:

The output should look something like this:

Those are all the current virtual machines I have added to VirtualBox.

Say you want to start the virtual machine “Ubuntu Server.” For that, the command would be:

The output should look like this:

You can verify that it’s running by issuing the following command:

The output should look like this:

You can then access the virtual machine as you normally would (as long as you remember the IP address of the server).

Here are some more commands you can use to manage those virtual machines (I’ll stick with the Ubuntu Server VM as an example):

  • Pause a virtual machine: VBoxManage controlvm “Ubuntu Server” pause --type headless
  • Restart a paused virtual machine: VBoxManage controlvm “Ubuntu Server” resume --type headless
  • Shutdown a running virtual machine: VBoxManage controlvm “Ubuntu Server” poweroff --type headless
  • Delete a virtual machine: VBoxManage unregistervpm "Ubuntu Server" --delete-all

Creating a New Virtual Machine

You can also create virtual machines from the command line. The process is a bit more complicated than managing previously existing VMs, and you still have to use a GUI (such as an RDP client) to complete the OS installation. Make sure you’ve download the ISO for the OS you want to install before starting with this process. If you’re feeling brave, here are the steps (make sure to modify them as needed for your situation):

Create the VM

First, create the virtual machine with the command:

 

Configure the RAM and the Network Card

Next, you’ll need to configure the RAM and network card with the following three commands:

 

Create the Disk and Connect the ISO Image

We’ll now create an 80GB SATA HD and a CDROM with an attached Ubuntu ISO with the commands (modify as needed):

 

Configure RDP Access

Next, configure RDP access so it can be accessed from the network with the commands:

You should then be able to start the new virtual machine with the command:

This will launch the VM and you can then access it via RDP on port 10001, where you can finish installing the guest OS.

And that’s all there is to managing your VirtualBox VMs from the command line. If I’m being 100% honest with you, I much prefer creating the virtual machines from the GUI and then managing them from the command line.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *