VirtualBox
VirtualBox
- "innotek VirtualBox is a family of powerful x86 virtualization products for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL)."
Installation
RedHat
Download VirtualBox RPM (I am using the RHEL5 RPM)
# Download: VirtualBox-1.5.6_28266_rhel5-1.i586.rpm
Install dependencies:
# i386 #yum install gcc kernel-devel libSDL-1.2.so.0 libasound.so.2 libqt-mt.so.3 libxslt.so.1 yum install gcc kernel-devel SDL alsa-lib qt libxslt # x86_64 yum install gcc kernel-devel SDL.x86_64 alsa-lib.x86_64 qt.x86_64 libxslt.x86_64
Install RPM:
# i386 rpm -Uvh VirtualBox-1.5.6_28266_rhel5-1.i586.rpm # x86_64 rpm -Uvh VirtualBox-1.6.0_30421_rhel5-1.x86_64.rpm
Ubuntu
apt-get update ; apt-get install virtualbox
Kernel Module
These installs will attempt to compile the kernel module. If you need to rerun the setup due to a failure, run:
/etc/init.d/vboxdrv setup
Comparison
VBox_vs_Others – Oracle VM VirtualBox - VirtualBox vs. VMware vs. Parallels - http://www.virtualbox.de/wiki/VBox_vs_Others
GUI
The VirtualBox GUI can create and control VMs
Command Line Tools
VBoxManage is our command-line interface (See chapter 7 of the user manual)
List VMs:
VBoxManage list vms
Show VM details:
vm showvminfo <name>
Start VM:
VBoxManage startvm <name> # Start with RDP support VBoxManage startvm <vmname> -type vrdp VBoxHeadless -startvm <vmname> VBoxHeadless -startvm <vmname> -p <port> #VBoxVRDP has been renamed VBoxHeadless in v1.6
Stop VM:
VBoxManage controlvm <name> poweroff
Reset VM:
VBoxManage controlvm <name> reset
Add aliases for easy usage:
vi /etc/bashrc alias vm=VBoxManage alias vmlist="vm list vms | grep Name"
Creating a virtual machine on a headless server
VirtualBox User Manual 7.4.2 Step by step: creating a virtual machine on a headless server:
Set virtualbox name:
VBOXNAME="centos5"
Create Virtual Machine:
VBoxManage createvm -name "$VBOXNAME" -register
Settings for VM:
VBoxManage modifyvm "$VBOXNAME" -memory "256MB" -acpi on -boot1 dvd -nic1 nat
Create virtual disk (10GB):
VBoxManage createvdi -filename "$VBOXNAME.vdi" -size 10000 -register VBoxManage modifyvm "$VBOXNAME" -hda "$VBOXNAME.vdi"
Attach ISO to VM:
VBoxManage modifyvm "$VBOXNAME" -dvd /full/path/to/iso.iso # VBoxManage modifyvm "$VBOXNAME" -dvd ~/CentOS-5.1-i386-bin-1of6.iso
Start VM RDP:
VBoxVRDP -startvm "$VBOXNAME"
Connect via RDP to VM:
rdesktop -a 16 my.host.address
Unmount ISO so reboots work:
VBoxManage modifyvm "$VBOXNAME" -dvd none
Bridge Networking
Install bridge tools:
yum install bridge-tools
Setup a bridge network:
# create bridge brctl addbr br0
# remove address from eth0 (will disable networking) ifconfig eth0 0.0.0.0
# add interface to bridge brctl addif br0 eth0
# reconnect network dhclient eth0 or... ifconfig br0 x.x.x.x netmask x.x.x.x
# create permenant virtual interface VBoxAddIF vbox0 root br0
# delete virtual interface VBoxDelIF vbox0
# list current virtual interfaces ifconfig
For a permenet bridge configuration:
# Add bridge device # /etc/sysconfig/network-scripts/ifcfg-br0DEVICE=br0 TYPE=Bridge BOOTPROTO=dhcp ONBOOT=yes# the bridge will take over eth0, so set it to the static IP of eth0 DEVICE=br0 TYPE=Bridge BOOTPROTO=static IPADDR=10.161.101.6 NETMASK=255.255.255.0 ONBOOT=yes
# Add eth0 to bridge # /etc/sysconfig/network-scripts/ifcfg-eth0 BRIDGE=br0
# Restart service /sbin/service network restart
# Create virtualbox host interface and add to bridge # vbox0 => "all host interfaces created in this way must be called vbox followed by a number" # <user> => "Replace <user> with the name of the user who is supposed to be able to use the new interface." # To see current host interfaces see ifconfig VBoxAddIF vbox0 <user> br0 # Delete if needed... VBoxDelIF vbox0
# Tell VM to use virtual interface under "settings"->"network"->"attached to" # and enter "vbox0" into the "interface name" field.
# NOTE: A VIRTUAL INTERFACE CAN ONLY BE USED WITH WITH ONE VIRTUAL MACHINE
Switch VM interface to host interface mode:
VBoxManage modifyvm "$VBOXNAME" -hostifdev1 vbox0 #VBoxManage modifyvm "$VBOXNAME" -nic1 hostif