Linux: Run VirtualBox virtual machines via command line

With the rise of virtualization, VirtualBox has established itself as an essential tool for a multitude of users. Whether you are a professional or a simple enthusiast, knowing how to use this software effectively is crucial. Running your virtual machines directly through the command line can seem intimidating, but this article demystifies the process and reveals the benefits of this method.

Why choose the command line?

There command line has several advantages over the GUI, including:

  • Precise targeting of commands without navigating complex menus.
  • Possibility of automating repetitive tasks using scripts.
  • Reduced usage of system resources, contributing to better performance
  • Simplified remote management using protocols like SSH.

Necessary preparations

Necessary preparations

Before diving into running your virtual machines, some preparations are necessary:

  1. Install the latest version of VirtualBox on your Linux system.
  2. Make sure you have the administrative rights to execute certain commands.
  3. VirtualBox Extension Pack must be installed to access network features.

Essential commands to control your VMs

Once prepared, it’s time to use the command line to run and manage your virtual machines. Here are some key commands:

🔍 Orders
▶️ VBoxManage startvm “VM_Name” –type headless
⏸️ VBoxManage controlvm “VM_Name” pause
🔄 VBoxManage controlvm “VM_Name” resume
💻 VBoxManage controlvm “VM_Name” poweroff
🗑️ VBoxManage unregistervm “VM_Name” –delete

Create a new virtual machine via CLI

Create a new virtual machine via CLI

To go further, creating a new virtual machine can also be done via the command line. Here is an overview of the steps to follow:

  1. Create the virtual machine: VBoxManage createvm –name “VM_Name” –register
  2. Configure memory: VBoxManage modifyvm “VM_Name” –memory 2048
  3. Add a hard drive: VBoxManage createhd –filename “/path/to/disk.vdi” –size 50000
  4. Connect the disk and ISO: VBoxManage storageattach “VM_Name” –storagectl “SATA Controller” –port 0 –device 0 –type hdd –medium “/path/to/disk.vdi”
  5. Start the machine: VBoxManage startvm “VM_Name” –type headless

Complete the installation via RDP

To access your newly created VM once started, configure access RDP :

  1. Enable RDP: VBoxManage modifyvm “VM_Name” –vrde on
  2. Specify the port used: VBoxManage modifyvm “VM_Name” –vrdeport 3389
  3. Connect through your favorite RDP client with the IP address of your host machine.

Discuss your experiences!

Discuss your experiences!

What are your challenges or successes in managing virtual machines under Linux ? Share your experiences in comments!