Running CentOS in VirtualBox

Following the steps below will result in the creation of a CentOS virtual machine in VirtualBox, with the Guest Additions package installed, and a shared folder configured to allow files to be transferred between the host and guest systems. These instructions assume that the user is running Windows on a computer with the x86_64 architecture (that is, using a 64-bit Intel processor or a clone).

1. Download and install VirtualBox. As of this writing, the latest version is available at the URL “https://www.virtualbox.org/wiki/Downloads”.

2. Download the desired version of CentOS in .iso format. CentOS is a free and open-source operating system built around the Linux kernel, and derived from the proprietary Red Hat Enterprise Linux (RHEL) operating system. As of this writing, the latest version can be downloaded as an .iso file via a link on the CentOS homepage at the URL “https://www.centos.org/”.

3. Restart the host (physical) computer. Before the operating system starts, press Escape or Delete or whatever key is necessary to access the BIOS configuration settings. In the BIOS configuration, turn on virtualization support (notably, be sure to enable any settings named “VT-x”), save the settings, and continue with the boot process. It is not currently possible to run a 64-bit virtual machine in VirtualBox if these BIOS features are not enabled.

4. Start VirtualBox.

5. On the VirtualBox main menu, select the “Machine – New” menu item.

6. On the “Name and Operating System” page of the “Create Virtual Machine” dialog, enter the value “CentOS” in the Name box, select the value “Linux” in the Type box, and select the value “RedHat (64 bit)” in the Version box. Then click the Next button.

7. On the Memory Size page of the dialog, change the value to “1024 MB” and click the Next button. Note that leaving this value at its default as of this writing, “512 MB”, would prevent the subsequent installation process from running in graphical mode, which may invalidate some of the following steps.

8. On the “Hard Drive” page of the dialog, accept the default selection (“Create a virtual hard drive now”) and click the Create button.

9. On the “Hard Drive File Type” page of the dialog, accept the default selection (“VDI”) by clicking the Next button.

10. On the “Storage on Physical Hard Drive” page of the dialog, accept the default selection (“Dynamically allocated”) by clicking the Next button.

11. On the “File Location and Size” page of the dialog, accept the default values (an 8 GB disk in the “CentOS” folder) by clicking the Create button. The dialog will be dismissed, focus will return to the main VirtualBox window, and a new item named “CentOS” will be present in the left pane.

12. Click on the new item “CentOS” in the left pane to select it, then select the “Machine – Settings” menu item from the main menu bar. A dialog titled “CentOS – Settings” will appear.

13. On the Settings dialog, click the “System” item in the list in the left pane. The right pane will be populated with the “System” settings.

14. In the right pane, on the “Motherboard” tab, change the value of the Chipset box to “ICH9”, and activate the “Enable IO APIC” checkbox if necessary. Note that leaving the Chipset value set to its default as of this writing, “PIIX3”, results in severe performance degradation when running a 64-bit operating system.

15. Click the OK button to save the updated settings and dismiss the Settings dialog.

16. Click the item “CentOS” in the left pane to select it, then select the menu item “Machine – Start” from the main menu bar. A new window for the virtual machine will appear, then a dialog titled “Select a Start-Up Disk” will appear. Specify the location of the previously downloaded .iso for CentOS and click the Start button. The dialog will be dismissed and CentOS will attempt to start up.

17. From this point forward, Virtualbox may pop up informational dialogs from time to time regarding things like “mouse capture” or “color compatibility”. Read and dismiss all such dialogs as needed.

18. On the screen that features a countdown to automatic startup (which reads “Automatic boot in:”), interrupt the automatic countdown by pressing the Escape key. A menu titled “Welcome to Centos” will appear. If you fail to interrupt the automatic startup in time, simply restart the virtual machine and try again.

19. From the menu, use the arrow keys to select the value “Install” and press the Enter key. A console screen will appear and many installation status messages will scroll through it. Eventually, the first screen of the installation wizard will appear.

20. As of this writing, the welcome screen contains little more than a CentOS logo and a Next button. Click the Next button to proceed.

21. On the next few screens, follow the prompts to specify a language, keyboard type, and storage device type, clicking the Next button to confirm each choice.

22. After specifying a storage device type, a dialog titled “Storage Device Warning” will appear. Click the “Yes, discard any data” button to dismiss the dialog.

23. Continue to follow the prompts to specify the computer’s name, time zone, root password, and installation type, clicking the Next button to confirm each choice. Be sure to make a note of the root password.

24. Depending on the selections made in previous steps, a dialog titled “Writing storage configuration to disk” may appear. Click the “Write changes to disk” button to continue.

25. Installation will begin, and a progress bar will appear to track its progress. Wait for installation to complete.

26. When installation completes, a screen will appear saying “Congratulations, your CentOS installation is complete.” Click the Close button to proceed. The screen will go blank.

27. Select the menu item “Devices – CD/DVD Devices – Remove Disk from Virtual Drive” from the main menu on the virtual machine window.

28. On the main VirtualBox window, click on the “CentOS” item in the left pane, then select the menu item “Machine – Close – Power Off” from the main menu. The window for the virtual machine will disappear.

29. Still on the main VirtualBox window, and with the “CentOS” item still selected, select the menu item “Machine – Start” from the main menu. A new window for the virtual machine will appear, and CentOS will start booting.

30. When CentOS boots, a “Welcome” screen will appear. Follow the prompts to agree to the license agreement, create a default user (make a note its username and password) set the date and time, and read about the “Kdump” utility, clicking the “Forward” button to confirm each item. On the final screen, click the “Finish” button to proceed. The screen will go blank for a moment, CentOS will finish starting up, and a login dialog will appear prompting for a username.

31. On the login dialog, click the item for the default user created in the previous step, enter the correct password in the Password box that appears, and click the OK button to proceed. The CentOS desktop will appear.

32. To enable the “VirtualBox Guest Additions” for CentOS, hold the right Control key (by default) and press the D key. A new “DVD” icon named “VBOXADDITIONS” will appear on the desktop, and a dialog will appear stating that “you have just inserted a medium with software intended to be automatically started”. Click the OK button on the dialog, and then click the Run button on the next dialog. Yet another dialog will appear, prompting for the password for the root user. Enter the correct password and click the Authenticate button.

33. A console window will appear, and the status messages for the installation of the Guest Additions will appear within it. As of this writing, an error appears stating that “The headers for the current running kernel were not found”, followed by a suggestion that this problem can probably be fixed by running a command starting with “yum install”. Make a note of the full command suggested here and press the Return key to close the window.

34. Select the menu item “Applications – System Tools – Terminal” from the CentOS main menu. A console window will appear.

35. In the console window, enter the command “su”, and then enter the password for the root user when prompted.

36. Still in the console window, enter the full text of the “yum install” command suggested in a previous step (as of this writing, this command is “yum install kernel-devel-2.6.32-358.el6”, though this will change frequently. )(UPDATE 2014/02/12: A commenter has pointed out that you might try simply running the command “yum install kernel-devel” instead)(UPDATE 2015/08/30: Well, now “yum install kernel-devel” doesn’t seem to work anymore, but I encountered the command “yum install kernel-devel-$(uname -r)” that seems to install the right version.)

37. Enter “y” at the next two prompts to confirm the installation of the kernel source package. Wait for the “Complete!” message to appear.

38. Still in the console window, enter the command “yum install gcc”, then type “y” to answer the confirmation prompts. Wait for “gcc”, which stands for “GNU Compiler Collection”, to install.

39. Enter the command “exit” twice to dismiss the console window.

40. Back on the CentOS desktop, right-click the “VBOXADDITIONS” icon, then select the “Open with Autorun Prompt” item from the context menu that appears. Click the Run button on the confirmation dialog, then enter the password for the root user and click the Authenticate button.

41. The console window showing status messages from the Guest Additions installation process will once again appear. Verify that no errors appear this time, wait for the installation to complete, and press the Return key to dismiss the window. (UPDATE 2014/04/14 – I had some trouble with this today, because errors kept occurring during the install. I was eventually able to fix it, via some combination of running “yum update kernel*”, running “yum update kernel-devel”, pressing Ctrl-D to pull down another copy of the Guest Additions, and re-running this step, but I’m not sure which parts of all that actually did the trick.)

42. Remove the “VBOXADDITIONS” icon from the desktop by right-clicking it and selecting the “Eject” item from the context menu that appears.

43. Back on the host operating system (NOT in the virtual machine), create a new folder on the root of the C: drive named “Share”, that is, “C:\Share”.

44. In the VirtualBox main window, select the CentOS item and click the “Settings” button on the tool bar.

45. On the Settings dialog, click the “Shared Folders” item in the list on the left to select it, then click the “Add Shared Folder” icon that appears on the right side of the Settings dialog.

46. In the “Add Share” dialog, specify the path “C:\Share”, verify that the value “Share” is automatically populated in the Name box, then activate all three checkboxes and click the OK button to create the new shared folder. Back on the Settings dialog, click the OK button again to dismiss it.

47. Back on the CentOS virtual machine, open a new console window by selecting the menu item “Applications – System Tools – Terminal”, enter the command “su”, specify the root password, then enter the commands “mkdir /mnt/share” and “mount -t vboxsf Share /mnt/share”. It will now be possible to transfer files between the host and guest operating systems by placing the files in the “C:\Share” and “/mnt/share” folders, as desired.

48. In the main VirtualBox window, open the Settings dialog again, click the “Network” item in the list on the left to select it, click the “Adapter 2” tab in the right pane, click the “Enable Network Adapter” checkbox to activate it and select the value “Host-only Adapter” in the Attached To box.  Click to expand the “Advanced” section and make a note of the value in the MAC Address box.  Click the OK button.

49. Back on the CentOS virtual machine, open a new console window if necessary, use the command “su” to enter superuser mode if necessary, and enter the command “cd /etc/sysconfig/network-scripts” to change the current directory.  Enter the command “cp ifcfg-eth0 ifcfg-eth1 to create a new configuration file for the “host-only” adapter created in the previous step.  Enter the command “nano ifcfg-eth1” to open the file in a text editor.  In the text editor, remove the line starting with “UUID”, change the value “eth0” to “eth1”, and substitute the value in the HWADDR property with the MAC address noted in the previous step, adding “-” characters to format it as necessary.  Then save the file by pressing Ctrl-X and confirming the save at the prompt.  Back on the command line, enter the command “service network restart” to register the changes.

(UPDATE 2015/09/01: Another useful command for getting the VirtualBox host-guest common clipboard to work is “pkill -f VBoxClient; VBoxClient –clipboard”.)

Advertisements
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

2 Responses to Running CentOS in VirtualBox

  1. Vincent says:

    Hi,

    Great Post mate!
    I followed your tut religiously and got stuck on #36. I googled the problem and solved it using
    yum install kernel-devel.

    Cheers

    • Yeah, any list of steps I write doesn’t seem to last very long before something changes in CentOS and the procedure doesn’t quite work anymore. But thanks for testing, and for researching a fix. I’m sure it’ll be helpful the next time I try this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s