CentOS as a Guest OS in VirtualBox

Installation of CentOS as a guest OS is much like installing on real hardware. Start by downloading the ISO file[s] you wish to use for installation from a CentOS Mirror.

Creating a Virtual Machine

Create a New Virtual Machine (VM) with the Virtual Machine Wizard, choosing Linux for the OS Type and Red Hat or Red Hat (64 bit) for the Operating System. Memory should be at least 768MB for a graphical install to work. Next the virtual hard disk wizard will start. The OS disk should be at least 8GB. For a relatively full install, allocate at least 15GB, otherwise use all the defaults. Additional disk[s] can be added later if desired.

After the VM is created, run Settings, go to Storage, and under IDE Controller click on the CD icon on the left, then select the similar CD icon on the right and pick Choose a virtual CD/DVD from the list. Navigate to the directory where the ISO image[s] reside and pick one, for example CentOS-5.10-x86_64-bin-DVD-1of2.iso or CentOS-6.5-i386-bin-DVD1.iso. Change any additional settings, such as the amount of memory for the virtual video adapter, and whether to use NAT or Bridged networking. For a first install attempt make a minimum of changes to the defaults.

Start the VM and perform a graphical install, or if desired a text install. After the install reboot and perform firstboot configuration.

Installing Guest Additions

You will need to be the root user for the following tasks. Login to a root shell or "su -" in a terminal window.

The installation of VB will require the building of kernel modules. If DKMS (Dynamic Kernel Module Support) is installed it will be used and will simplify kernel upgrades. Installing DKMS from RPMforge or EPEL repository is recommended before installing VirtualBox. Don't forget to configure the yum-priorities plugin. Installing DKMS may pull in required development dependencies, depending on the package source.

yum --enablerepo rpmforge install dkms

If DKMS is not used the Guest Additions will need to be reinstalled after every kernel update.

If the development environment and kernel source are not already installed:

yum groupinstall "Development Tools"
yum install kernel-devel

You may also choose to only install a minimum set of individual development tool packages (at least gcc and make are required, in addition to kernel-devel) rather than the groupinstall which some may consider overkill. Replace "kernel-devel" with "kernel-PAE-devel" if using a PAE kernel on CentOS-5. If you are not using a standard CentOS kernel, you must acquire and install the source for your kernel from wherever you got the kernel. Do not try to install a Xen kernel in a Guest OS, or run KVM or any other nested virtualization hypervisor.

From the VM Devices menu select Install Guest Additions.... If running a GUI the virtual CD image for guest additions will automount - for instance under CentOS-6 with KDE it is mounted under /media/VBOXADDITIONS_4.1.8_75467. If autorun is enabled in a GUI you may get a window asking if you want to let the autorun execute, and asking for root authorization. Take all the defaults and the install should complete.

If not in a GUI, or if there is no autorun, as root mount /dev/cdrom (if necessary) and cd to the mountpoint. Type ./VBoxLinuxAdditions.run to install.

Patch for CentOS 6.2 with VBOXADDITIONS_4.1.8

There is a bug for CentOS 6.2 that prevents the 3D guest driver from building correctly. A forum user has provided a patch and a link to a VB Forum thread with more details.

Mount the Guest Additions ISO as above, but do not run the installer. Copy/paste the patch below to a file, for instance el6.patch.

--- vboxvideo_drm.c_orig        2011-12-19 08:05:26.000000000 -0500
+++ vboxvideo_drm.c     2012-01-03 15:04:11.181357021 -0500
@@ -112,7 +112,7 @@
         .poll = drm_poll,
         .fasync = drm_fasync,
     },
-#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
+#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39) && !defined(DRM_RHEL61)
     .pci_driver =
     {
         .name = DRIVER_NAME,
@@ -127,7 +127,7 @@
     .patchlevel = DRIVER_PATCHLEVEL,
 };
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 39)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 39) || defined(DRM_RHEL61)
 static struct pci_driver pci_driver =
 {
     .name = DRIVER_NAME,
@@ -137,7 +137,7 @@
 
 static int __init vboxvideo_init(void)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
+#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39) && !defined(DRM_RHEL61)
     return drm_init(&driver);
 #else
     return drm_pci_init(&driver, &pci_driver);
@@ -146,7 +146,7 @@
 
 static void __exit vboxvideo_exit(void)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
+#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39) && !defined(DRM_RHEL61)
     drm_exit(&driver);
 #else
     drm_pci_exit(&driver, &pci_driver);

Follow a procedure as below. The example is for x86_64 (also know as amd64).

cd /media/VBOXADDITIONS_4.1.8_75467/
./VBoxLinuxAdditions.run --noexec --target ~/TMP/
cd ~/TMP/
mkdir ../TMP2
tar jxvf VBoxGuestAdditions-amd64.tar.bz2 -C ../TMP2/
cd ../TMP2/src/vboxguest-4.1.8/vboxvideo/
cat > el6.patch # copy/paste patch code above - end with <Ctrl-D>
patch -p0 < el6.patch
cd ~/TMP2/
tar jcvf ../TMP/VBoxGuestAdditions-amd64.tar.bz2 *
cd ~/TMP
./install.sh

For i386 substitute x86 for amd64 in the above procedure.

Patch for CentOS 6.3 with VBOXADDITIONS_4.1.18

<!> Note that no patch is required for CentOS 6.3 starting with VBOXADDITIONS_4.1.20 (See the Changelog for VB 4.1.20.)

There appears to be a bug which prevents the successfull build of the vBox guest additions in CentOS 6.3 guests (the OpenGL module fails). A forum user has provided the following patch which apparently solves the problem. Please see above on how to patch the guest additions source code:

--- vboxvideo_drm.c.original    2012-07-10 08:26:22.000000000 +0200
+++ vboxvideo_drm.c     2012-07-10 08:34:06.000000000 +0200
@@ -67,6 +67,9 @@
 #   if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,1)
 #    define DRM_RHEL61
 #   endif
+#   if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,3)
+#    define DRM_RHEL63
+#   endif
 #  endif
 # endif
 
@@ -85,7 +88,7 @@
     return 0;
 #endif
 }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0) || defined(DRM_RHEL63)
 /* since linux-3.3.0-rc1 drm_driver::fops is pointer */
 static struct file_operations driver_fops =
 {
@@ -109,7 +112,7 @@
     .get_map_ofs = drm_core_get_map_ofs,
     .get_reg_ofs = drm_core_get_reg_ofs,
 #endif
-# if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
+# if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) && !defined(DRM_RHEL63)
     .fops =
     {
         .owner = THIS_MODULE,

Patch for CentOS 6.4 with VBOXADDITIONS_4.2.8/4.2.10

There appears to be a bug which prevents the successful build of the vBox guest additions in CentOS 6.4 guests (the OpenGL module fails). A forum user has provided the following patch which apparently solves the problem. Please see above on how to patch the guest additions source code:

--- vboxvideo_drm.c.ori 2013-03-01 12:11:52.146639050 +0100
+++ vboxvideo_drm.c     2013-03-01 12:18:57.231061446 +0100
@@ -70,6 +70,9 @@
 #   if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,3)
 #    define DRM_RHEL63
 #   endif
+#   if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,4)
+#    define DRM_RHEL64
+#   endif
 #  endif
 # endif
 
@@ -106,7 +109,7 @@
 {
     /* .driver_features = DRIVER_USE_MTRR, */
     .load = vboxvideo_driver_load,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) && !defined(DRM_RHEL64)
     .reclaim_buffers = drm_core_reclaim_buffers,
 #endif
     /* As of Linux 2.6.37, always the internal functions are used. */

Patch for CentOS 6.5 with VBOXADDITIONS_4.3.2/4.3.4/4.3.6

There appears to be a bug which prevents the successful build of the vBox guest additions in CentOS 6.5 guests (the OpenGL module fails). A simple workaround as been reported here:

cd /usr/src/kernels/<kernel_release>/include/drm/  
ln -s /usr/include/drm/drm.h drm.h  
ln -s /usr/include/drm/drm_sarea.h drm_sarea.h  
ln -s /usr/include/drm/drm_mode.h drm_mode.h  
ln -s /usr/include/drm/drm_fourcc.h drm_fourcc.h

This is solved with the release of vBox-4.3.8.


This page created by PhilSchaffner. Wiki contributors are invited to make corrections, additions, or modifications.

HowTos/Virtualization/VirtualBox/CentOSguest (last edited 2014-02-26 18:52:18 by ChristophGaluschka)