ITcompressor IT — compressed and to the point
← Back to articles

VirtualBox

VirtualBox is a free virtualizer from Oracle: VMs on the desktop for tests, experiments and sandboxes. The scenario of this article: the virtual machine arch-vm.

Installation#

sudo apt update
sudo apt install virtualbox

USB 3.0 and RDP access to VMs additionally require the Extension Pack from virtualbox.org — free for personal use (the package has its own PUEL license).

Creating a virtual machine#

  1. "New" → name arch-vm, OS type (Linux / Arch 64)
  2. RAM — half of the host's, no more
  3. Virtual disk — a dynamic VDI sized for the guest OS
  4. The downloaded ISO is attached as an optical drive on the first start

VM settings#

Settings → sections (before and after creation):

  • System: memory and the number of CPU cores
  • Display: video memory, number of screens
  • Storage: attaching disk/ISO images
  • Network: the adapter type (see the networks section)
  • Shared folders: sharing directories between host and guest

Guest additions#

The additions provide integration: a shared clipboard, screen resize, shared folders.

  1. The VM is running → the "Devices" menu → "Insert Guest Additions CD image"
  2. Inside the guest, mount the CD and run the installer
  3. In a Linux guest the user needs a group for shared folders: sudo usermod -aG vboxsf $USER (re-login afterwards)

Snapshots#

A snapshot is a fixed state of the VM's disk: rolling back to it discards all subsequent disk changes.

# Fix the state
VBoxManage snapshot arch-vm take "clean system"

# List the snapshots
VBoxManage snapshot arch-vm list

# Roll back
VBoxManage snapshot arch-vm restore "clean system"

# Delete an unnecessary snapshot
VBoxManage snapshot arch-vm delete "clean system"

Rolling back restores the disk, not the processes: the state inside the running OS (except the "saved" state of a paused snapshot) will be as after a cold boot.

Managing VMs from the console#

# List the machines
VBoxManage list vms

# Start with a GUI window / in the background without a window
VBoxManage startvm arch-vm
VBoxManage startvm arch-vm --type headless

# Graceful shutdown / hard
VBoxManage controlvm arch-vm acpipowerbutton
VBoxManage controlvm arch-vm poweroff

# Reboot
VBoxManage controlvm arch-vm reset

# Remove the VM from the list (disks remain, deleted separately)
VBoxManage unregistervm arch-vm

headless + guest SSH is often more convenient than a GUI: the machine can be kept on a server and connected to as a regular host (NAT port-forwarding — VBoxManage modifyvm arch-vm --nat-pf1 "ssh,tcp,,2222,,22" or the "Network → port rules" tab in the GUI).

VM networks#

Type How it works When to use
NAT the VM reaches the outside through the host; not visible from outside the VM just needs internet by default
Bridged the VM with its own address in the host's network the VM must look like a regular host
Internal network only between VMs, no way out closed clusters of virtual machines
Host-only a private "VM ↔ host" network accessing the VM from the host itself

The types combine: one VM can be given both NAT and bridged (several adapters in the "Network" settings).

← Back to articles