Mastering VirtualBox VBoxManage Commands: A Comprehensive Cheat Sheet

Mastering VirtualBox VBoxManage Commands: A Comprehensive Cheat Sheet

VirtualBox is a powerful and popular open-source virtualization tool that allows you to run multiple operating systems on a single physical machine. While the VirtualBox GUI provides a user-friendly interface for most tasks, there's a whole world of possibilities available through the command-line interface, specifically using the VBoxManage command. In this blog post, we'll explore some essential VBoxManage commands to help you manage your virtual machines with ease.

Basic Virtual Machine Management

  1. Create a New Virtual Machine:

     VBoxManage createvm --name "VM Name" --ostype <OS_Type> --register
    

    This command creates a new virtual machine with the specified name and OS type.

  2. Modify VM Settings:

     VBoxManage modifyvm "VM Name" --memory <Memory_Size> --cpus <CPU_Count>
    

    Adjust the virtual machine's memory and CPU settings as needed.

  3. Attach an ISO Image to VM:

     VBoxManage storageattach "VM Name" --storagectl "SATA Controller" --port 0 --device 0 --type dvddrive --medium /path/to/iso-file.iso
    

    Use this command to attach an ISO image to the VM's virtual optical drive.

  4. Start VM:

     VBoxManage startvm "VM Name" --type headless
    

    Start the virtual machine in headless mode, which means it runs without a graphical user interface.

  5. Pause/Resume VM:

     VBoxManage controlvm "VM Name" pause
     VBoxManage controlvm "VM Name" resume
    

    Pause and resume a running virtual machine.

  6. Power Off VM:

     VBoxManage controlvm "VM Name" poweroff
    

    Gracefully power off a running VM.

Working with Snapshots

Virtual machine snapshots allow you to capture and restore a VM's state at a specific point in time.

  1. Create a Snapshot:

     VBoxManage snapshot "VM Name" take "Snapshot Name"
    

    Create a snapshot of the VM's current state with a descriptive name.

  2. Restore to a Snapshot:

     VBoxManage snapshot "VM Name" restore "Snapshot Name"
    

    Restore the VM to a previously saved snapshot.

  3. Delete a Snapshot:

     VBoxManage snapshot "VM Name" delete "Snapshot Name"
    

    Remove a specific snapshot from the VM.

Cloning VMs

  1. Clone a VM:

     VBoxManage clonevm "Source VM Name" --name "New VM Name" --register
    

    Create a copy of an existing VM, specifying a new name.

Networking

VirtualBox provides various networking options for VMs.

  1. List Host Network Interfaces:

     VBoxManage list hostonlyifs
    

    View a list of available host-only network interfaces.

  2. Create a Host-Only Network Interface:

     VBoxManage hostonlyif create
    

    Create a new host-only network interface.

  3. Configure Port Forwarding:

     VBoxManage modifyvm "VM Name" --natpf1 "guestssh,tcp,,2222,,22"
    

    Set up port forwarding to allow connections to specific ports in your VM.

Export and Import

  1. Export VM to an OVA file:

     VBoxManage export "VM Name" -o export.ova
    

    Export a VM to an Open Virtualization Format (OVA) file for backup or sharing.

  2. Import VM from an OVA file:

     VBoxManage import export.ova
    

    Import a VM from an OVA file previously exported.

Miscellaneous

  1. List VMs:

     VBoxManage list vms
    

    View a list of all configured virtual machines.

  2. List Running VMs:

     VBoxManage list runningvms
    

    Display a list of currently running virtual machines.

These VBoxManage commands serve as a foundation for efficiently managing VirtualBox virtual machines from the command line. Remember to replace "VM Name", <OS_Type>, <Memory_Size>, <CPU_Count>, and /path/to/iso-file.iso with your specific configuration details. Proper permissions and file paths are crucial for successful execution.

By mastering these commands, you can streamline your virtualization workflow and take full control of your virtual machines. VirtualBox's command-line capabilities offer flexibility and automation for various virtualization scenarios.