Installing VirtualBox and running your own VBox VMs
In this section we are going to install a headless VirtualBox. I like the idea of keeping it at the command line (i.e. no graphical interface), so that it consumes less resources and also so that it can be easily scripted and automated. Otherwise if you prefer to install a graphical user interface, there are a few options; you can use an x11 server tunnelling though your laptop and simply export the display into your machine. Another option is to use a remote desktop software like VNC or NoMachine.
In order to install a headless version of VirtualBox in RedHat and Fedora distributions follow the next set of instructions:
These instructions were taken from: http://tecadmin.net/install-oracle-virtualbox-on-centos-redhat-and-fedora/#
-
Add Required Yum Repositories. Firstly you are required to add VirtualBox yum repository in your system. Download repository file from its official site and place it under at /etc/yum.repos.d/virtualbox.repo – First navigate to /etc/yum.repos.d/ directory and get the repo
cd /etc/yum.repos.d/
sudo wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
-
Similarly, add EPEL yum repository:
rpm -Uvh http://epel.mirror.net.in/epel/6/x86_64/epel-release-6-8.noarch.rpm
-
Before installing VirtualBox make sure to install all required packages to run VirtualBox like kernel-headers, kernel-devels etc. Use following command to install required packages.
sudo yum install gcc make patch dkms qt libgomp
sudo yum install kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel
-
Setup the environment variable KERN_DIR. VirtualBox installation required kernel source code to install required modules. We need to configure environment variable KERN_DIR to which VirtualBox get kernel source code. In my case latest kernel source is available in 2.6.32-642.6.1.el6.x86_64 directory under /usr/src/kernels/ – Make sure you are using correct source path.
export KERN_DIR=/usr/src/kernels/2.6.32-642.6.1.el6.x86_64
-
Install Oracle VirtualBox now. Use following command to install VirtualBox 5.1 using yum command line tool. It will install latest version of VirtualBox 5.1.x on your system.
sudo yum install VirtualBox-5.1
-
After installation we need to rebuild kernel modules using following command:
sudo yum install kernel-uek-devel-3.8.13-68.2.2.3.el6uek.x86_64
sudo /sbin/vboxconfig
How to install Virtualbox 5.1 in Ubuntu:
1. The 5.1 release conflicts with the old 5.0 or 4.x releases, so first open terminal (Ctrl+Alt+T) and run command to remove the previous VBox installation (if any):
sudo apt remove virtualbox virtualbox-5.0 virtualbox-4.*
Or:
sudo apt-get purge virtualbox*
2. Download Virtualbox 5.1 for your OS (i386=32bit, amd64=64bit):
Double click the deb file and install via Ubuntu Software.
3. For those who want to install VBox 5.1 from official Linux repository and receive future updates via Software Updater. Run the commands below one by one in terminal:
Note: According to your Ubuntu codename, replace xenial with wily, trusty, or precise.
sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" >> /etc/apt/sources.list.d/virtualbox.list'
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
sudo apt update
sudo apt install virtualbox-5.1
Congratulations!!! That's it.
NOTE: If you are within a proxy, then try:
sudo http_proxy=http://www-proxy.au.oracle.com:80 apt update
sudo http_proxy=http://www-proxy.au.oracle.com:80 apt install virtualbox-5.1
If you want to manage your VMs from within the Host Machine, you can use VBoxManage – See https://www.virtualbox.org/manual/ch08.html for more information. Some useful commands are:
-
List all loaded VMs
VBoxManage list vms
-
List all running VMs
VBoxManage list runningvms
E.g.
VBoxManage list runningvms
"ICS16.3.5_OP" {088457a8-c9cc-424a-8720-4bc02cce9298}
"API_Platform_Beta_1" {5de85cbd-2203-46cd-949e-f94f79ae797f}
"Integration_12.2.1.1.0_OTN" {b8191645-04d6-4c3e-b6f3-c42e5cb8e514}
-
List info about a specific guest VM
VBoxManage guestproperty enumerate [VM_Name]
-
A variation of the latest in order to just get the IP Address:
VBoxManage guestproperty enumerate [VM_Name] | grep IP
E.g.
VBoxManage guestproperty enumerate "ICS16.3.5_OP" | grep IP
Name: /VirtualBox/GuestInfo/Net/0/V4/IP, value: 10.0.0.50, timestamp: 1476324285478581000, flags:
- Control Running VMs lifecycle:
VBoxManage controlvm <vmname> pause|resume|reset|poweroff|savestate
- Get the complete list of options with:
VBoxManage controlvm
- In order to start your VM in headless mode:
VBoxManage startvm <vmname> --type headless
- Import a New Appliance:
VBoxManage import [Appliance]
- Authorising certificates:
VBoxManage import Integration_12.2.1.1.0_OTN.ova --vsys 0 --eula accept
- Setting the NIC interface to bridge:
VBoxManage showvminfo [VM Name], e.g. VBoxManage showvminfo Integration_12.2.1.1.0_OTN
See the NIC interface number in use:
VBoxManage modifyvm [VM Name] --nic<1-N> none|null|nat|natnetwork|bridged|intnet|hostonly|generic --cableconnected<1-N> on|off
e.g.
VBoxManage modifyvm Integration_12.2.1.1.0_OTN --nic1 bridged --cableconnected1 on