Mastering VirtualBox

Mastering VirtualBox: A Quick Guide for Beginners

Introduction:

In the ever-evolving world of cloud computing, VirtualBox emerges as a savior for beginners looking to experiment and conduct Proof of Concepts (POCs) on their local machines. This quick guide provides essential VirtualBox commands to kickstart your virtualization journey.

What is VirtualBox?

VirtualBox is free, open-source virtualization software. It enables you to create and run multiple virtual machines on a single physical computer.

Features of VirtualBox

  • Isolation: VirtualBox creates isolated virtual environments, ensuring that different operating systems or applications do not interfere with each other.

  • Experimentation: It’s a safe platform for trying out new operating systems, software, or configurations without affecting your main system.

  • Testing: Developers can test software on different operating systems and environments to ensure compatibility and functionality.

  • Legacy Support: VirtualBox helps run older applications or operating systems that may not be compatible with modern hardware.

  • Security: Malware or potentially harmful content can be analyzed within virtual environments, preventing them from affecting the host system.

  • Training and Learning: It’s a great tool for training, allowing users to practice on various systems without physical hardware.

  • Cross-Platform Compatibility: VirtualBox facilitates running Windows on a Mac or Linux on a Windows machine, enhancing flexibility.

  • Snapshots: Snapshots enable users to save a VM’s state, making it easy to revert to a previous state if something goes wrong.

  • Server Consolidation: Virtualization can help consolidate multiple servers onto a single physical machine, reducing hardware and maintenance costs.

  • Resource Management: VirtualBox lets you allocate specific amounts of RAM, CPU, and storage to each virtual machine, optimizing resource utilization.

Virtual Box Quick Command Reference


To list down Available Guest OS supported by VirtualBox
  
$ vboxmanage list ostypes | grep -i fedora
    ID:          Fedora
    Description: Fedora (32-bit)
    ID:          Fedora_64
    Description: Fedora (64-bit)
List of steps to create a new VM (eg: Fedora) from ISO

  1. Create Virtual Machine (VM) Skeleton and Register a VM
    
    $ vboxmanage createvm --name "Fedora-38-test" --ostype Fedora_64 --register
        Virtual machine 'Fedora-38-test' is created and registered.
        UUID: e0f9f117-f999-4c7a-bd77-9d1ce4e3f73a
        Settings file: '/Users/Test/VirtualBox VMs/Fedora-38-test/Fedora-38-test.vbox'
    
  2. Add CPU, RAM, and Video RAM
    
    $ vboxmanage modifyvm "Fedora-38-test" --cpus 1 --memory 2048 --vram 16
    
  3. Configuring a Virtual Network Adapter
    
    $ vboxmanage modifyvm "Fedora-38-test" --nic1 nat
    
  4. Create a Virtual Hard Disk
    
    $ vboxmanage createmedium disk --filename ~/VirtualBox\ VMs/Fedora-38-test/Fedora-38-test-disk001.vmdk --size 5120 --format=VMDK --variant Standard
    
  5. Add Storage Controller to a VM
    
    $ vboxmanage storagectl "Fedora-38-test" --name "SATA Controller" --add sata --bootable on
    
  6. Attach a Virtual Hard Disk to Virtual Storage Controller
    
    $ vboxmanage storageattach "Fedora-38-test" --storagectl "SATA Controller" \
    --port 0 --device 0 --type hdd  \
    --medium ~/VirtualBox\ VMs/Fedora-38-test/Fedora-38-test-disk001.vmdk
    
  7. Add IDE Controller to Virtual Machine (To Later Connect ISO via CD/DVD)
    
    $ vboxmanage storagectl "Fedora-38-test" --name "IDE Controller" --add ide
    
  8. Attach an ISO
    
    $ vboxmanage storageattach "Fedora-38-test" --storagectl "IDE Controller" \
    --port 0  --device 0 --type dvddrive \
    --medium ~/Documents/ISO/Fedora-Server-dvd-x86_64-38-1.6.iso
    
  9. Time to start the VM once all the resources are configured to create the VM
    
    $ vboxmanage startvm "Fedora-38-test"
    
  10. Now follow the steps to install the Fedora, like we do on physical box.

  11. Optional Step: Incase you have problem with graphics and screen scaling issue
    
    $ vboxmanage modifyvm "Fedora-38-test" --graphicscontroller=vmsvga $ vboxmanage setextradata "Fedora-38-test" GUI/ScaleFactor 1.8
    
    $ vboxmanage modifyvm "Fedora-38-test" --graphicscontroller=vmsvga
    
    $ vboxmanage setextradata "Fedora-38-test" GUI/ScaleFactor 1.8
    
  12. Note: Above value may varies from system to system based on monitor size/pixels.


  13. Optional Step: Want to enable VirtualBox Remote Display Protocol (VRDP)
    
    $ vboxmanage modifyvm "Fedora-38-test" --vrde on
    
    $ vboxmanage startvm "Fedora-38-test" --type=headless
    
  14. Note: You can use rdesktop/rdp or any other rdp supported software to connect to remote machine.

To list down VM use the following command (available in any state)

$ vboxmanage list vms "Fedora-38-VirtualBox-Original" {553fea69-61b6-4024-b069-15219bf3e9cd} "Fedora-38" {02944e40-6cec-4b9a-b558-8ca74cdfe334}
                    
$ vboxmanage list vms
    "Fedora-38-VirtualBox-Original" {553fea69-61b6-4024-b069-15219bf3e9cd}
    "Fedora-38" {02944e40-6cec-4b9a-b558-8ca74cdfe334}
To list down running VM use the following command

$ vboxmanage list runningvms
    "Fedora-38-VirtualBox-Original" {553fea69-61b6-4024-b069-15219bf3e9cd}
To view information about a particular virtual machine use the following command

$ vboxmanage showvminfo "Fedora-38-VirtualBox-Original" Name: Fedora-38-VirtualBox-Original Encryption: disabled Groups: / Guest OS: Fedora (64-bit) UUID: 9a9615f6-0173-4c67-961f-ef9cb0968b15 ...... ......
                    
$ vboxmanage showvminfo "Fedora-38-VirtualBox-Original"
    Name:                        Fedora-38-VirtualBox-Original
    Encryption:     disabled
    Groups:                      /
    Guest OS:                    Fedora (64-bit)
    UUID:                        9a9615f6-0173-4c67-961f-ef9cb0968b15
    ......
    ......
To start a VM use the following command (by default it will open in GUI mode)

$ vboxmanage startvm "Fedora-38-VirtualBox-Original"
    Waiting for VM "Fedora-38-VirtualBox-Original" to power on...
    VM "3cab8256-1ce5-4cd7-b74e-f155b75f6436" has been successfully started.
To start a VM in Headless mode use the following command

$ vboxmanage startvm 3cab8256-1ce5-4cd7-b74e-f155b75f6436 --type headless
    Waiting for VM "3cab8256-1ce5-4cd7-b74e-f155b75f6436" to power on...
    VM "3cab8256-1ce5-4cd7-b74e-f155b75f6436" has been successfully started.
To Power off a machine (without saving the state), it has the same effect as pulling the power cable on a real computer.

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" poweroff
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
To save the state and power off (It Saves the current state of the VM to disk and then stops the VM)

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" savestate
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Poweroff Button (It Sends an ACPI shutdown signal to the VM, as if the power button on a real computer had been pressed)

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" acpipowerbutton
To Pause a VM (Temporarily puts a VM on hold, without permanently changing its state)

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" pause
To Resume from Pause state (Undoes a previous pause command)

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" resume
Cold reset (It has same effect on a VM as pressing the Reset button on a real computer)

$ vboxmanage controlvm "Fedora-38-VirtualBox-Original" reset
To make the VM unavailable to use

$ vboxmanage unregistervm "Fedora-38-VirtualBox-Original"

Note: It does not delete the definition and the files associated with the virtual machine.


To delete a VM as well as its associated files

$ vboxmanage unregistervm "Fedora-38-VirtualBox-Original" --delete-all
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
To create a VM from existing VM (Clone)

$ vboxmanage clonevm "Fedora-38-VirtualBox-Original" --name "Clone-Fedora-38" --register 
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%  Machine has been successfully cloned as "Clone-Fedora-38"
To create a copy of a existing image and export to other machine/cloud etc.

$ vboxmanage export "Fedora-38-VirtualBox-Original" -o Fedora-38.ova
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Successfully exported 1 machine(s).
To import a VM file

$ vboxmanage import ~/Documents/ISO/Fedora-38-VirtualBox-Original.ova
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Interpreting /Users/XXXXX/Documents/ISO/Fedora-38-VirtualBox-Original.ova...
    OK.
Snapshot related commands (To save the state of a VirtualBox)

To Create a new Snapshot

$ vboxmanage snapshot "Fedora-38-VirtualBox-Original" take fedora-snapshot
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Snapshot taken. UUID: 88f38480-e272-4764-8bd1-0f8bf119208e
To list a Snapshot for a particular VM

$ vboxmanage snapshot Fedora-38-VirtualBox-Original list 
    Name: fedora-snapshot (UUID: 88f38480-e272-4764-8bd1-0f8bf119208e) *
To restore a Snapshot for a particular VM

$ vboxmanage snapshot Fedora-38-VirtualBox-Original restore fedora-snapshot
    Restoring snapshot 'fedora-snapshot' (88f38480-e272-4764-8bd1-0f8bf119208e)
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
To delete a Snapshot for a particular VM

$ vboxmanage snapshot Fedora-38-VirtualBox-Original delete fedora-snapshot
    Deleting snapshot 'fedora-snapshot' (290c257d-a881-4359-9577-d9959fff5d98)
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Get In Touch

East Delhi, New Delhi

connect@iopshub.com

+91 73038 37023