Thursday, August 18, 2011

Installing 32-bit CentOS 5.6 in VirtualBox 4.0 on 64-bit Windows 7

VirtualBox (http://www.virtualbox.org) is a very handy virtualization application that can very quickly get your Virtual Machines up and running and supports a wide variety of environments.  Lately, I have been using it to host various Linux distributions on my Windows 7 machine while I study and experiment with different technologies.

Recently I decided that I wanted to install CentOS 5.6 with the Gnome DWM and ran into a couple of little small issues that are very easy to get around if you know how to handle them.

First, I am using the image CentOS-5.6-i386-bin-DVD and initializing the new VM with the following settings (your settings may be slightly different):



Start the VM and choose the default boot option, which will attempt to load CentOS 5.6 from the mapped DVD drive.   CentOS-5.6-i386-bin-DVD fails to load, hanging on the line: "NET: Registered protocol family 2":


There is an easy workaround for this issue.  Power off the hung VM using the guest window's menu or by closing the window and choosing the "Power Off" option, then go back to the VirtualBox Manager, select the CentOS VM from the list of machines, and click the "Settings" button.  From there, you'll need to select "System" from the list on the left, then check the "Enable IO APIC" box, click the "OK" button, and start your new VM again.


The VirtualBox documentation states that "Enabling the I/O APIC is required for 64-bit guest operating systems", then follows that statement up with "software support for I/O APICs has been unreliable with some operating systems other than Windows". Since we're installing a 32-bit Linux distribution as our guest operating system, enabling I/O APIC does not sound like the right thing to do, but it works.

After the guest operating system is installed, rebooted, and patched it's time to install the VirtualBox Guest Additions.  The VB Guest Additions make the guest OS much more usable by providing a host of features that include better mouse integration, higher screen resolutions, clipboard integration, shared folders, and (my favorite) dynamic screen resizing.  Before the VB Guest Additions can be installed completely, we must first install a couple of prerequisite packages:

  • gcc - The Gnu C Complier
  • kernel-devel - Development package for building kernel modules to match the kernel.

To install gcc and kernel-devel in CentOS 5.6, open a terminal window as root and enter the following commands and answer "y" when asked to confirm the action.
  • yum install kernel-devel
  • yum install gcc
 YUM (Yellow dog Updater Modified) will automatically detect
dependencies and install any prerequisite packages. 
Now that the prerequisites are out of the way, it is safe to install the VirtualBox Guest Additions. From a command prompt enter the following command as root (note that this command will be different if your VB version is not exactly the same as mine): 

/media/VBOXADDITIONS_4.0.12_72916/VBoxLinuxAdditions.run
In some situations it is possible that the kernel-devel package previously installed is not exactly what is required to build the VB Guest Additions module. If that happens, you will see an error message as in the following screenshot.




If this happens, simply copy the line with the correct yum install kernel-devel-* command and run it at the terminal command prompt. This will install the specific version of the kernel development package that the VirtualBox needs in order to build the Guest Additions module.

When the yum installer completes, execute VBoxLinuxAdditions.run again:

/media/VBOXADDITIONS_4.0.12_72916/VBoxLinuxAdditions.run

Watch the screen - all boxes should have a green "OK" in them.

If there are any steps that say "FAILED" then you may need to consult the VirtualBox documentation at http://www.virtualbox.org/wiki/Documentation.

That's it!  Now restart the guest OS, log in, and enjoy!