HowTo Install VirtualBox

From NST Wiki
Jump to: navigation, search

Determining What Versions of VirtualBox Are Available

There are often multiple versions of VirtualBox for you to choose from. Use the following command to determine the current set of choices:

[root@rice ~]# yum list | grep VirtualBox
VirtualBox-4.0.x86_64                    4.0.2_69518_fedora13-1         @virtualbox
VirtualBox-3.1.x86_64                    3.1.8_61349_fedora13-1         virtualbox
VirtualBox-3.2.x86_64                    3.2.12_68302_fedora13-1        virtualbox
[root@rice ~]#

Alternatively one can use (2012-09-13):

[root@d630 ~]# /usr/bin/yum --disablerepo=* --enablerepo=virtualbox list available  2>&1;
Loaded plugins: fastestmirror, filter-data, keys, langpacks, list-data, presto,
              : refresh-packagekit
Determining fastest mirrors
Skipping filters plugin, no data
Available Packages
VirtualBox-4.1.x86_64           4.1.22_80657_fedora16-1               virtualbox
VirtualBox-4.2.x86_64           4.2.0_RC4_80667_fedora16-1            virtualbox
[root@d630 ~]#

Installing VirtualBox 4.0 on a NST v2.13.0 System

The following commands can be used to install VirtualBox onto a NST system (as of 2009-Oct-26 using v2.11.0 of the NST distribution).

yum -y install kernel-devel gcc
yum -y install VirtualBox-4.0

Installing on a NST v2.11.0 System

The following commands can be used to install VirtualBox onto a NST system (as of 2009-Oct-26 using v2.11.0 of the NST distribution).

yum -y install kernel-devel gcc
cd /etc/yum.repos.d
wget -nH http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
yum -y install VirtualBox-4.0

After Installation

Add Users to vboxusers Group

For every user you want to grant access to VirtualBox, you should add that user account to the vboxusers group. This can be done through the Users and Groups GUI tool (under the System | Administration menu on a GNOME desktop), or by using a text editor and directly editing your /etc/group file. For example after adding users pat and dianne, you should a line similar to the following line in your /etc/group file (you may see a number other than 512):

vboxusers:x:512:pat,dianne

Note: If a user is logged in when you add them to the vboxusers group, make sure you have them logout and then back in before running VirtualBox.

Adding Extension Packs

Oracle has introduced the concept of extension packs starting with the 4.0 release of VirtualBox. You should be able to find these extension pack(s) by googling for "oracle vm virtualbox extension pack". At the time of this writing, there was a single USB 2.0 extension pack available.

You must be logged in as the root user to install a extension pack. The following demonstrates the command used to install the USB 2.0 extension pack:

VirtualBox Oracle_VM_VirtualBox_Extension_Pack-4.0.2-69518.vbox-extpack

Starting VirtualBox

From the GNOME desktop, you can find the Oracle VM VirtualBox launcher under the Applications | System Tools menu. Alternatively, you can start VirtualBox directly from the command line using the command:

VirtualBox

Listing IP Addresses of Running Virtual Machines

VirtualBox makes it a bit tricky to find the IP address allocated to each of your running machines. The following short script makes use of the VBoxManage command to:

  • Get a list of all the running VMs
  • Look up the IP address associated with each running VM

Here is the script that runs on both Linux and Mac (save to a file named: VBoxListIps):

#!/bin/bash
#
#  List IP addresses of running VMs

# Create quoted array of VirtualBox running VMs (need quotes as 
# VMs can have spaces in names)
eval "declare runningVms=($(VBoxManage list runningvms | \
  sed -e 's,^\(".*"\) {.*}$,\1,'))";

# Look up IP address for each VM

for vm in "${runningVms[@]}"; do
  declare ip=$(VBoxManage guestproperty get "${vm}" "/VirtualBox/GuestInfo/Net/0/V4/IP" 2>/dev/null | awk -- '{ print $2; }');

  printf "%-15s %s\n" "${ip}" "${vm}";
done

Here is an example of the output from the script on a system with three running virtual machines:

taco-e:Downloads pkb$ VBoxListIps
192.168.1.80    VaiDev6c
192.168.1.82    dev18-32
192.168.1.112   tlp-el6
taco-e:Downloads pkb$

VirtualBox FAQ

See section: " VirtualBox Frequently Asked Questions"


VirtualBox Automatically Starting Guest VMs

Enabling guest VMs to start automatically at boot can be a challenge. It comes down to the following basic steps:

  • Enabling the auto-start feature in VirtualBox
  • Adding user accounts that you want give the auto-start capability to
  • Each user account must then be configured and register the virtual machines that should be started at boot.

Enabling the Auto-Start Feature

For NST 28 (and Fedora 28), you need to modify/create the /etc/vbox/vbox.cfg file with two parameters required for the auto-start feature (other Linux distributions may use the /etc/default/virtualbox configuration file).

VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

You will also need to enable the virtualbox-autostart.service at boot time so that registered virtual machines will be auto-started:

systemctl enable vboxautostart-service.service

Allow User Accounts

Create the /etc/vbox/autostart.cfg file and add allow a specific user account (change USER shown below to the name of the user account to be enabled on your system):

default_policy = deny
USER = {
allow = true
}

Make sure that the user account is part of vboxusers group (if you are already logged into the USER account you should log out and back in after completing this step):

sudo usermod -aG vboxusers USER

Update permissions on the /etc/vbox configuration files as follows to permit the members of the vboxusers group sufficient privileges:

sudo chmod 1775 /etc/vbox
sudo chgrp vboxusers /etc/vbox /etc/vbox/autostart.cfg
sudo chmod 640 /etc/vbox/vbox.cfg /etc/vbox/autostart.cfg

Users Then Register VMs

At this point you need to log in to the user account that will register a VM to start at boot time and run the following commands. Change the setting of "vm" to the name of the virtual machine you want to start at boot time (use "VBoxManage list vms" to get a list of virtual machines). You may need to stop the VM before modifying its auto-start properties.

VBoxManage setproperty autostartdbpath /etc/vbox     # Only needs to be done once
vm=nst28-repo                                        # USE NAME OF YOUR VM
VBoxManage modifyvm $vm --autostart-enabled on       # Can be: <on|off>
VBoxManage modifyvm $vm --autostart-delay 30         # Have seen issues if delay is left at 0
VBoxManage modifyvm $vm --autostop-type acpishutdown # Can be: <disabled|savestate|poweroff|acpishutdown
VBoxManage showvminfo $vm                            # Auto-start options shown, not auto-stop