How to use VirtualBox in Terminal / Command line

PART ONE

How to manage VirtualBox in command line or terminal. VBoxManage is the command which is used to manage VirtualBox in commandline. Using VBoxManage, one can create and control the virtual OS and there are many features than GUI VirtualBox.

Here is a simple tutorial on how to create a virtual OS (Ubuntu10.10) using VBoxManage and access it remotely from the host machine.

INTRUCTIONS

To create a virtualmachine(Ubuntu10.10), use the below command or copy and paste it in terminal. If you want to create a virtual machine for fedora or some other OS, change the name Ubuntu10.10 to fedora or slax or kubuntu etc.

VBoxManage createvm --name Ubuntu10.10

In the above command, “createvm” is used to create a virtual machine and “–name“defines the name of the virtual machine. After executing this command it will create virtual machine called “Ubuntu10.10.vbox” in home folder under “VirtualBox VMs/Ubuntu10.10/Ubuntu10.10.vbox”

*Note: If the name has space, then it should be given within quotes.

Say for example, “Ubuntu 10.10″.

Now, create the hard disk image for the virtual machine using the below command

VBoxManage createhd --filename Ubuntu10.10 --size 5120

In the above command, “createhd” is used to create hard disk image and “–filename” is used to specify the virtual machine’s name, for which the hard disk image is created. Here, “–size” denotes the size of the hard disk image. The size is always given in MB. Here we have specified 5Gb that is 5120MB.

After creating a virtual machine, the VirtualBox has to be registered. “registervm” command is used to register the virtual machine. The full path of the virtual machine’s location has to be mentioned.

VBoxManage registervm '/home/user/VirtualBox VMs/Ubuntu10.10/Ubuntu10.10.vbox'

or

The virtualmachine can be registered while creating virtual machine using “–register“. Below is the command

VBoxManage createvm --name Ubuntu10.10 --register

Now set the OS type. For example, if the Linux OS has to be installed, then specify the OS type as Linux or Ubuntu Or Fedora etc.

VBoxManage modifyvm Ubuntu10.10 --ostype Ubuntu

One of the most important command in VBoxManage is “modifyvm“. Using “modifyvm”, one can modify many features in virtual machine like changing the memory size, name of the Virtual Machine, OS type and many more. The name of the virtual machine has to be specified inorder to modify it. In the above command, Ubuntu10.10 has been explained. The command “–ostype” is used to set the OS type like Linux, Windows, Ubuntu, Fedora, etc,.

Now, set the memory size for the virtual OS, i.e. the ram size for the virtual OS from the host Machine.

VBoxManage modifyvm Ubuntu10.10 --memory 512

The command “–memory <size>” is used to set the RAM size for the virtual machine from the host machine. The size should be defined in MB.

Now create a storage controller for the virtual machine.

VBoxManage storagectl Ubuntu10.10 --name IDE --add ide --controller PIIX4 --bootable on

storagectl <name>” is used to create a storage controller for virtual machine. Later the virtual media can be attached to the controller using “storageattach” command. The above command creates the storage controller called IDE. <name> defines the name of the virtual machine.

Here,

–name <name>” specifies the name of the storage controller that needs to be created or modified or removed from the virtual machine.

–add <options>” defines the type of system bus to which the storage controller must be connected. Available options are ide/sata/scsi/floppy.

–controller <options>” allows to choose the type of chipset that is to be emulated for the given storage controller. Available options are LsiLogic / LSILogicSAS / BusLogic / IntelAhci / PIIX3 / PIIX4 / ICH6 / I82078.

–bootable <on/off>” defines whether this controller is bootable or not.

VBoxManage storagectl Ubuntu10.10 --name SATA --add sata --controller IntelAhci --bootable on

Using the above command, a storage controller called SATA has been created. The hard disk image can be attached to this later.

Now, attach the storage controller to the virtual machine using “storageattach” .

VBoxManage storageattach Ubuntu10.10 --storagectl SATA --port 0 --device 0 --type hdd --medium "filename"

The above command will attach the storage controller SATA to virtual machine Ubuntu10.10 with the medium i.e., to the virtual disk image which is created.

storageattach <name>” is the command used to attach the storage controller to the virtual machine.

<name> defines the name of the virtual machine.

–storagectl <name>” is used to define the name of the storage controller which needs to be attached to the virtual machine.

<name> defines the name of the storage controller.

–port <number>” is used to define the number of storage controller’s port which is to be modified.

–device <number>” is used to define the number of the port’s device which is to be modified.

–type <options>” is used to specify the type of the drive in which the medium should be attached. Available options are dvddrive / hdd / fdd.

–medium <options>” defines the hard disk image or ISO image file or virtual DVD. Available options are none / emptydrive / <uuid> / <filename>host:<drive>iscsi

*Note: If you decide to specify the filename, then specify the full path where it is located.

Example: “/home/user/Ubuntu10.10.vdi”

VBoxManage storageattach Ubuntu10.10 --storagectl IDE --port 0 --device 0 --type dvddrive --medium "filename"

Here, the above command will attach the storage controller IDE with the medium of ISO image as DVD drive. This medium can be closed after installing the virtual OS(Ubuntu10.10).

filename“– Example: “/home/user/Downloads/ubuntu-10.10-desktop-i386.iso”

Next, add some features like audio, 3d acceleration, network, etc,.

VBoxManage modifyvm Ubuntu10.10 --vram 128 --accelerate3d on --audio alsa --audiocontroller ac97

–vram <size>” This sets the size of RAM that the virtual graphics card should have. The size should given in MB.

–accelerate3d <on/off>” if the guest additions are installed, this sets the hardware 3D acceleration for the virtual machine.

–audio <options>” is used to set the audio for the virtual machine with available host driver. Available options are none /null / oss / alsa / pulse.

–audiocontroller <options>” is used to set the controller for the audio in the virtual machine. Available options are ac97 / hda / sb16.

VBoxManage modifyvm Ubuntu10.10 --nic1 nat --nictype1 82540EM --cableconnected1 on

–nic<1-N> <options>” with this the type of networking can be set for each of the VM’s virtual network cards. Available options are none / null / nat / bridged / intnet / hostonly / vde.

–nictype<1-N> <options>” is used to specify which networking hardware is to be presented to the guest VirtualBox. Available options are Am79C970A / Am79C973 / 82540EM / 82543GC / 82545EM / virtio.

–cableconnected<1-N> <on/off>” This allows to temporarily disconnect a virtual network interface from virtual machine. This might be useful for re-setting certain software components in the VM.

Now to start a virtual machine, use the below command

VBoxManage startvm Ubuntu10.10

startvm <name>” is the command used to start the virtual machine. By default it starts in the GUI mode.

<name> defines the name of the virtual machine.

Remote Desktop in VirtualBox

To activate the remote desktop, set the port number and address.

VBoxManage modifyvm Ubuntu10.10 --vrde on --vrdeport 5012 --vrdeaddress 192.168.1.6

–vrde <on/off>” is used to set the remote desktop ON or OFF.

–vrdeport <number>” is used to set the port number in the port in which the virtual machine should be available. “default or 0″ will set the port in 3389.

–vrdeaddress <address>” is used to set the “IP” address in which it should be accessable.

Now, start the virtual machine using the below command

VBoxManage startvm Ubuntu10.10 --type headless

–type <options>” is used to specify the mode in which it should start the virtual machine. Available options are gui / sdl / headless.

headless” produces no visible output on the host at all, but only delivers VRDP data. This front-end has no dependencies on the X Window system on Linux and Solaris hosts.

Alternative method to start virtual machine for remote access is VBoxHeadless. Use the below command.

VBoxHeadless --startvm Ubuntu10.10

–startvm <name>” is used to start the virtual machine. <name> defines the name of the virtual machine.

To access the remote desktop, use rdesktop command. By default the linux system should have rdesktop. If not, install it. Use the below command from the client machine to access the virtual machine remotely.

rdesktop -a 16 -N 192.168.1.6:5012

To stop the virtual machine, check the below command

VBoxManage controlvm Ubuntu10.10 poweroff

“controlvm <name> <options>” controlvm command is used to control the state of the virtual machine. <name> defines the name of the virtual machine. Some of the available options are pause / resume / reset / poweroff / savestate / acpipowerbutton / acpisleepbutton. There are many options in controlvm to see all the options available in it. Either type or copy and paste the below command in terminal.

VBoxManage controlvm

Hope this will be helpful for you!!!

Related Posts Plugin for WordPress, Blogger...

  • Pingback: How to install Skype 4.0 in Ubuntu 12.10 / 12.04 using PPA

  • Pingback: How to create launcher and add icon to Unity in Ubuntu 12.10

  • Dave

    This is amazing, thank you very much.

  • Pingback: Install VirtualBox in Ubuntu 13.04 / 12.10 / 12.04 using PPA

  • http://twitter.com/mr_Borune Rune T C Petersen

    Hi Manivannan
    Great article!

    Althou I have a problem when we get to rdesktop I get the error:
    ERROR: Failed to open display:
    Both host and guest are raring ringtail

    here’s a history of my actions:
    —————————————————————————————————————————
    VBoxManage createvm –name Ubuntu13.04
    VBoxManage createhd –filename ‘/home/administrator/ubuntuVB/UbuntuGserver.vdi’ –size 4096
    VBoxManage registervm ‘/home/administrator/VirtualBox VMs/Ubuntu13.04/Ubuntu13.04.vbox’
    VBoxManage createvm –name Ubuntu13.04 –register
    VBoxManage modifyvm Ubuntu13.04 –ostype Ubuntu
    VBoxManage modifyvm Ubuntu13.04 –memory 1024
    VBoxManage storagectl Ubuntu13.04 –name IDE –add ide –controller PIIX4 –bootable on
    VBoxManage storagectl Ubuntu13.04 –name SATA –add sata –controller IntelAhci –bootable on
    VBoxManage storageattach Ubuntu13.04 –storagectl SATA –port 0 –device 0 –type hdd –medium /home/administrator/ubuntuVB/UbuntuGserver.vdi
    VBoxManage storageattach Ubuntu13.04 –storagectl IDE –port 0 –device 0 –type dvddrive –medium “/home/administrator/ubuntuVB/ubuntu-13.04-server-amd64.iso”
    # VBoxManage modifyvm Ubuntu13.04 –vram 128 –accelerate3d on –audio alsa –audiocontroller ac97
    VBoxManage modifyvm Ubuntu13.04 –nic1 bridged –bridgeadapter1 p135p1
    VBoxManage modifyvm Ubuntu13.04 –vrde on –vrdeport 3389 –vrdeaddress 192.168.2.190
    VBoxManage startvm Ubuntu13.04 –type headless
    Waiting for VM “Ubuntu13.04″ to power on…
    VM “Ubuntu13.04″ has been successfully started.

    sudo apt-get install rdesktop
    rdesktop -a 16 -N 192.168.2.190:3389
    Autoselected keyboard map en-gb
    ERROR: Failed to open display:

    VBoxManage controlvm Ubuntu13.04 poweroff

    sudo vi /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    # The loopback network interface
    auto lo
    iface lo inet loopback
    # The primary network interface
    auto p135p1
    iface p135p1 inet dhcp

    —————————————————————————————————————————
    Br Rune

  • http://twitter.com/mr_Borune Rune T C Petersen

    Sharing is caring:
    “Althou I have a problem when we get to rdesktop I get the error:
    ERROR: Failed to open display:
    Both host and guest are Ubuntu servers 13.04 raring ringtail”

    found in the VBox.log file:
    VRDE: VirtualBox Remote Desktop Extension is not available

    Console:
    wget http://download.virtualbox.org/virtualbox/4.2.12/Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack
    sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack

    then it worked.

    • http://www.howopensource.com Manivannan

      Hi Rune T C Petersen,

      Thanks for the info :)