How to Use VirtualBox: Creating Your Own VMs
    Main Page
    Lab Hardware
    Lab Software
 

Last updated: 14 Nov 2012

Creating User-Defined VMs

Background

Most lab workstations are Linux hosts that are able to run at least one virtual machine or VM. Windows runs as a guest operating system and provides a standard learning and coursework environment. It is defined and configured by Institute lab staff.

There may be times when you want to create your own VM -- a user-defined VM. There are two ways to do this.

  1. VM on Windows host

    All lab workstations running Windows natively or as a guest can also support creating VMs inside of Windows, using Oracle's VirtualBox virtual machine manager. These VMs run within your Windows login account and should not continue to run after you log off.

  2. VM on Linux host

    In non-general development labs, you can also create VMs that will stay up until you stop them, for research and special projects work. These VMs run under a special Linux account, and can either replace or add to other VMs running concurrently. That is, if you don't need the standard Windows VM, you can stop the VM and run just your VMs. Typically, you stop the provided Windows VM when a lab workstation is not shared but dedicated to your work.

Stop the Windows VM

The predefined Windows VM can be stopped by:

  1. Logging into Windows as usual
  2. Opening a CMD shell
  3. Entering:
      g:\stop_vm
      
  4. Logging off
  5. When the "Press Ctrl-Alt-Del" screen is shown:
    1. Enter Ctrl-Alt-Del
    2. Press the Enter key or click OK
    3. Click on the red button in the lower right=hand corner and shutdown the VM.

Once the Windows VM is shut down, you should be able to login to one of the provided accounts.

Creating a VM

VirtualBox provides two ways of creating and managing a VM: via the VirtualBox GUI, or via the VBoxManage command line. You'll likely find the GUI much more pleasant to use than the command line, but the command line can do much more than the GUI allows -- something to keep in mind as the complexity of your VM grows.

VirtualBox is started from either the command line (e.g., in Linux: VirtualBox &) or by searching for the VirtualBox application, then clicking on the application's icon. Either method brings up the same VirtualBox GUI.

  1. Click on the New button.
  2. Name and operating system

    Provide a name, and select the type of OS and the OS version corresponding to that OS. In addition to the unmarked 32-bit versions, you can also select 64-bit versions.

    The OS selection helps VirtualBox optimize its operation for that OS.

  3. Memory size

    Specify how much virtual RAM you want to provide to this VM. While the recommended amount is usually adequate for light student use, you might want to increase the amount; stay within the "green area" to avoid conflicting with the RAM needed by the host operating system to run. Also keep in mind how many VMs you will be running at the same time. For best performance, try to keep the total RAM that all VMs use to within that same green area.

  4. Hard Drive

    If you will be using a "live" CD or DVD, you don't need to create a virtual hard drive (unless you will want to install that live CD to disk later).

    Usually, you will want to create a virtual hard drive now, though you can always create one later and attach it to your VM.

  5. Hard drive file type

    Choosing the VDI hard drive file type is a good, safe bet.

  6. Storage on physical hard drive

    Using the default dynamically allocated storage is usually the best choice. A smaller size (vs. a fixed size) makes copying a VM faster.

  7. File location and size

    Normally, the name of the virtual disk is the same as the VM. That works for one disk per VM, but if you want more than one, you'll have to add them later... and the names will need to be different. The size of the disk depends on what you want to do with it. Windows 7 or 2008 require at least 20GB with updates and a couple of apps installed.

After that, you should see your defined VM, which you can further define and tweak using the Settings button (make sure your VM is selected first!).

The next step after creating a VM is usually attaching a virtual CD/DVD to it, in the form of a file that ends with .iso -- an ISO file. While you can use a real CD/DVD on a dedicated computer, virtual ones are used on remote computers to avoid excessive network traffic, so it is often a good idea to use an ISO file instead. Also, it is faster to use an ISO file than a real CD/DVD.

For example, let's say you created a 32-bit Fedora Linux VM, and want to use the Fedora 17 Live CD ISO file to boot up. The file path is /home/labadmin/Fedora-17-i686-Live-Desktop.iso.

  1. Click on Storage
  2. In the Storage Tree:

    There is a storage controller called Controller: IDE. It is a virtual IDE controller — a disk and CD/DVD controller that was popular before SATA controllers took over the market.

  3. Click on the Empty CD/DVD icon.

    The Attributes will change to show the CD/DVD Drive.

  4. Click on the CD/DVD icon with a small down arrow on it to the right of the CD/DVD Drive.
  5. Select Choose a virtual CD/DVD disk file....
  6. Navigate to and select the Fedora-17-i686-Live-Desktop.iso file.
  7. Click OK to virtually insert the virtual CD/DVD into the virtual drive.

Now you can start your VM, which should boot up to the CD/DVD (if it's bootable) or the hard disk (if it has an OS installed).

Managing a VM or Guest OS

  • Install VirtualBox Guest Additions

    You'll find working with the VM much more pleasant if you install the guest additions, but how to do so is beyond the scope of this document.

  • Do not install or use software that you don't have the license to use

    You must not install software that the UW does not have a license to use.

    Some software has use restrictions, such as it cannot be used for funded research or for developing commercial products.

  • Update the OS

    Once you install an OS to a virtual hard disk, you are a "system owner" and have the responsibility to maintain the security of that OS, per UW Security Policy. One of the simplest and most effective things to do is to update the OS to its latest patches. This means running Windows or Microsoft update on a Windows VM, and using the corresponding software updater on a Linux VM. Update the operating system and the applications installed within it.

    Updates should be run periodically if they can't be configured to run automatically.

  • Install antivirus tools

    The UW provides antivirus tools for Windows, Mac, and Unix/Linux. Installing them can help prevent malware from infecting your VM.

  • NAT vs. Bridged networking

    The default networking type is NAT, or Network Address Translation. NAT uses the existing network interface controller (or NIC) on the host to provide access to the network from within your VM. If all you are doing inside your VM is browsing the web, using network client software (such as ssh or SQL Server Management Studio), or pinging other computers, NAT is a good solution and doesn't require any configuration. In addition, it doesn't use up any IPv4 addresses.

    However, using NAT means that your VM doesn't have a real IP address in the sense that it can be detected by another computer. This is a problem if your VM will be used as a server, and needs to expose its IP address and ports to use to the network. While you can still do that with NAT, you would need to use non-standard ports and set it up specially in VirtualBox (Settings/Network/Adapter 1/Advanced/Port Forwarding).

    If your VM's guest OS must use standard ports (e.g., port 80 for a web server or port 22 for the ssh daemon), you should change your VM to use bridged networking (Settings/Network/Adapter 1/Attached to/Bridged adapter). A bridged VM will appear as if it is directly attached to the network -- if it uses dynamic IP addresses, it will get an IPv4 address from the network's DHCP server. If you have a static IP address assigned to you, you could use that inside your VM.

  • Stopping a User-defined VM

    It is usually better to gracefully shutdown a VM (or any computer) than to essentially pull the plug (poweroff or reset). Often, choosing the VirtualBox menu item Machine/ACPI Shutdown will perform a graceful shutdown. Also, you can use the OS's shutdown features to do the same.

    Powering off or resetting a VM should be used as a last resort, as it may corrupt the virtual disk(s).

  • Backup your data

    Nothing will be backed up for you, so you are responsible for making your own backups. Since the host's physical disk could fail, you could lose all of your virtual disks, so don't rely on the host's disk for your backups. Instead, use an external drive, and make another copy to a second external drive once per week.

Change Log

14 Nov 2012 Original document


Hours  |  Support Information  |  News  | 
Policies  |  Emergencies