Sysadmin:VirtualBox

From Earlham CS Department
Jump to navigation Jump to search

In 2019 we again interested ourselves in VirtualBox, this time for use in smaller machines that we won't run 24/7 as we do the Xen machines. VirtualBox VM's might be useful in the context of senior projects, Networks and Networking, Operating Systems, and more.

Consider the "Old VirtualBox Notes" section archival but potentially useful as a reference. The newer info is what you as a sysadmin care most about.

Host info

We will run VirtualBox on Bowie, along with tools like Docker. We do as much as possible through the command line, though it's possible we'll need to use some X forwarding in individual cases. Networking is sometimes easier done through X forwarding.

List of Useful Commands

Here is a man page for vboxmanage commands --> https://www.virtualbox.org/manual/ch08.html#vboxmanage-startvm

  • vboxmanage startvm <vmname> --type=headless
  • vboxmanage controlvm <vmname> poweroff
  • vboxmanage list vms
  • vboxmanage list runningvms
  • vboxmanage import <name>.ova
  • vboxmanage export <vm name> -o <filename>.ova
  • vboxmanage list vms -l (This lists detailed information of every VM)
  • vboxmanage unregistervm --delete "Name of Virtual Machine"

Old VirtualBox Notes

Reference Links:

Here's some help as far as what VBoxManage can list for you: VBoxManager list{vms |runningvms |ostypes |hostdvds |hostfloppies |hostifs |hostinfo |hddbackends |hdds |dvds |floppies |usbhost |usbfilters |systemproperties}

Installation

Installation of VirtualBox is fairly simple and straightforward.

On Debian, add the following line to /etc/apt/sources.list:

deb http://download.virtualbox.org/virtualbox/debian etch non-free

Then, to register Sun's repository key and update apt's package index:

wget http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc
apt-key add sun_vbox.asc
apt-get update

Install:

apt-get install virtualbox-2.1

It will complain about being unable to find a suitable kernel module, so the VirtualBox drive then needs to be setup. This is done with:

/etc/init.d/vboxdrv setup

Assuming this finishes without errors, VirtualBox is now ready to be used.

Usage

Typical usage of VirtualBox requires running VirtualBox which is a fancy GUI application that allows you to create, run, and monitor VMs. This requires having the Qt libraries and a full X server, both things that are not typically on servers. Fortunately, VirtualBox provides a very easy to use command line interface. For the complete documentation see the VirtualBox User Manual (pdf).

Creating a new VM

Creating a new Virtual Machine is a multi-step process that can be done (almost) completely from the command line.

Here is another example of building a new VM: https://networking.ringofsaturn.com/Unix/Create_Virtual_Machine_VBoxManage.php

  • First, create the initial VM configuration:
VBoxManage createvm -name "quarkprime" -ostype FreeBSD -register -basefolder /quark

In this example, a new FreeBSD VM will be created with the name quarkprime, it will be registered with the VirtualBox installation, and its configurations will be placed in /quark.

  • Next, we need to supply some basic configuration options:
VBoxManage modifyvm "quarkprime" -memory "1024MB" \
               -acpi off \
               -boot1 dvd \
               -nic1 hostif -hostifdev1 eth1 \
               -vrdp on -vrdpport 3390

There are many options that can be given to the modifyvm operation. For a list of all of them, do VBoxManage help | less and search for modifyvm or for a detailed description, see section 8.5 of the User Manual.

  • This newly created VM will have:
    • 1G of memory;
    • no ACPI;
    • the first boot device to the DVD;
    • the network as host-only through the eth1 interface on the host;
    • and VRDP will be enabled and set to listen on port 3390.


  • The VRDP port given above must be a port that is not used by any other VM in order to make use of this feature. To see which ports are currently assigned, do:
VBoxManage list vms | grep VRDP
  • VRDP stands for VirtualBox Remote Desktop Protocol and is VirtualBox's communication protocol for providing remote access to the console of your virtual machine based on the Remote Desktop Protocol (RDP, Wikipedia). It is mostly used to handle the initial installation of the OS, but can also prove to be useful in emergencies when the VM becomes unavailable through the usual remote access methods. VRDP is compatible with most RDP clients including rdesktop, Apple Remote Desktop, VNC, Window's RDC, and many others.


  • Every VM needs a HardDisk and usually we'll want to create a new one. To do this, do
VBoxManage createhd -filename "quarkprime.vmdk" -size 100000 -register

This creates a 100,000MB HardDisk file of type VMDK (Virtual Machine Disk Format; other formats include VDI (VirtualBox's own format) and VHD (Microsoft's virtual disk format)) with the name "quarkprime.vmdk" and registers this disk with the VirtualBox installation.

  • Note: VirtualBox places this new HardDisk in ~/.VirtualBox/HardDisks (In the case of the EC-CS setup, ~ is /root) not in the basefolder specified above. To keep a VM's configuration and HD in the same place, do the following:
    • Move the disk image from /root/.VirtualBox/HardDisks/quarkprime.vmdk to /quark/quarkprime/quarkprime.vmdk
    • Edit the file /root/.VirutalBox/VirtualBox.xml to reflect the new location


  • Next, set the VM to use this disk as its primary:
VBoxManage modifyvm "quarkprime" -hda "quarkprime.vmdk"

Since both the VM "quarkprime" and the disk "quarkprime.vmdk" are registered with VirtualBox, full paths are not required.


  • The next step requires having the OS installation iso somewhere on disk. In this example, the FreeBSD7.1 iso was downloaded to /quark. This iso must be registered with VirtualBox in order to be used by a VM:
VBoxManage openmedium dvd /quark/7.1-RELEASE-i386-disc1.iso


  • Set the VM to use this iso:
VBoxManage modifyvm "quarkprime" -dvd /quark/7.1-RELEASE-i386-disc1.iso


  • Start the VM:
VBoxManage startvm "quarkprime" -type vrdp


  • At this point, the VM is running and booting from the iso we gave it. Since there isn't an OS there yet, we need to connect to its local console to go through the installation process. This is done using a VRDP client such as rdesktop (GNU remote desktop client). On your local machine (laptop, ACL, etc.):
rdesktop -a 16 forty-two.cs.earlham.edu:3390

This opens a new remote desktop session using a color depth of 16 and connecting to the host forty-two.cs.earlham.edu on port 3390. This port is the same as specified with the -vrdpport option to VBoxManage modifyvm and the host is the server where VirtualBox is installed and running.
You should now see a familiar installation screen and should be able to interact with it as usual.


  • When the installation is finished and asks for you to remove the CD, you need to "eject" the CD and reset the boot order, which first requires shutting down the VM:
VBoxManage controlvm "quarkprime" poweroff
VBoxManage modifyvm "quarkprime" -dvd none
VBoxManage modifyvm "quarkprime" -boot1 disk


  • Restart the VM:
VBoxManage startvm "quarkprime" -type vrdp


  • Reconnect to the console (remember, this should be run from your local machine, not the server):
rdesktop -a 16 forty-two.cs.earlham.edu:3390

You should now be connected to a fresh install of your operating system. The next recommended step is to install an SSH server so that there's no need to use rdesktop unless something goes wrong.



Congratulations! You've now installed a Virtual Machine using VirtualBox!

Monitoring VMs

Errors

Occasionally you'll see this error when booting up a virtual machine:

FATAL: Could not read from the boot medium! System halted

In this case, the virtual machine may need to have its hard drive file set again, something along these lines:

VBoxManage modifyvm quarkprime -hda /quark/quarkprime/quarkprime.vdi

Kay's Table

Virtualization Options
VMWare VirtualBox Xen HVM Xen P. KVM
Reasonable I/O Yes ? ? ?
Command Line Interface Yes Yes Yes Yes
Requires ActiveX for Management Yes
Needs Modified Guest Yes ?
Special Kernel Yes Yes ?
Needs VTX Support Yes Yes

Tables from Wikipedia

Name Creator Host CPU Guest CPU Host OS(s) Guest OS(s) License
KVM Qumranet [1] Intel/AMD processor with X86 virtualization,IA64,s390,PowerPC same as platform Linux Linux, Windows, FreeBSD, Solaris GPL version 2
Sun xVM VirtualBox Sun Microsystems x86, x86-64 x86, (x86-64 only on VirtualBox 2 with hardware virtualization) Windows, Linux, Mac OS X (Intel), Solaris, eComStation DOS, Windows, Linux, OS/2, FreeBSD, Solaris GPL version 2; full version with extra enterprise features is proprietary (free of charge for personal and educational use and evaluation)
VMware Server VMware x86, x86-64 x86, x86-64 Windows, Linux DOS, Windows, Linux, FreeBSD, Netware, Solaris, Virtual appliances Proprietary (Free)
Xen Citrix Systems x86, AMD64, (PowerPC and IA-64 ports in progress) (Same as host) NetBSD, Linux, Solaris FreeBSD, NetBSD, Linux, Solaris, Windows XP & 2003 Server (needs vers. 3.0 and an Intel VT (Vanderpool) or AMD-V (Pacifica)-capable CPU), Plan 9 GPL



Name Guest OS SMP available? Runs arbitrary OS? Drivers for supported guest OS available? Method of operation Typical use Guest OS speed relative to Host OS Commercial support available? Needs administrative rights?
KVM Yes Yes Yes (virtio) In-kernel Virtualization Server, home use only for experienced users Near native Yes No (if /dev/kvm is accessible by non-root user)
Sun xVM VirtualBox No Yes Yes Virtualization Business workstation, Enterprise Server Consolidation, Business Continuity, Hobbyist, Developer Near native Yes (with commercial license) Needs (See Support forums)
VMware Server Yes (2-way) Yes Yes Virtualization Server/Desktop Consolidation, Dev/Test Up to near native Yes Needs
Xen Yes Yes Not required with the exception of the networking drivers where a NAT is required. A modified guest kernel or special hardware level abstraction is required for guest OSs. Paravirtualization and Porting or Hardware Virtualization Template:? Up to near nativeTemplate:Ref speed substantial performance loss on some workload (network and disk intensive especially) Yes



Name Can boot an OS on another disk partition as guest USB GUI Live memory allocation 3D acceleration Snapshot of running system Live migration
KVM Yes <ref name="kvm-how-to">Template:Cite web</ref> Yes Yes <ref name="virt-manager">Template:Cite web</ref> Yes <ref name="memory ballooning">Template:Cite web</ref> Supported with VMGL <ref name="VMGL">Template:Cite web</ref> Yes
Sun xVM VirtualBox Partial (since version 1.4, but unsupported) Template:Ref Partial (for any host OS except Solaris)<ref>USB support for OpenSolaris is actively being worked on right now. Retrieved on 2008-09-25</ref> Yes Yes experimental support for OpenGL <ref>Template:Cite web</ref> No in Open Source Edition No in Open Source Edition
VMware Server Yes Yes Yes Yes No Yes
Xen Yes Yes Supported with VMGL <ref name="VMGL"/> Yes


Virtualbox on debian[edit] Cons:

  • Extremely gui orienated. In order to run Debian Virtualbox in "headless mode" (without a gui/windowing system) extra packages including third-party software must be installed such as Virtualbox extention pack 1, VDRE, and a RDP viewer.
  • Accessing a vm requires port fowarding.

?Pros:

  • Creating a new vm is easy.
  • Duplicating a vm is easy.