Net Installing CentOS on VirtualBox

Although we all have our favourite Linux distributions, and mine is most definitely Ubuntu, it is often the case that in the workplace we have to learn another distribution, and while that is still Linux is may operate in a way that is quite different to what we are used to. A common workplace Linux distribution is RedHat Enterprise Linux which is supplied complete with a support package. The problem here is that if you want to install it to just learn about it, the price tag might put you off (it currently starts at $349). There is a related free version called Fedora, but this has a slightly different focus, where RedHat goes for stability over features, Fedora is more cutting edge. The result is that the two may not be the same, and depending on what you want to do, Fedora might not provide you with the knowledge you need to work with the RedHat environment. Help is at hand though, RedHat provide the source code to their distribution, which, thanks to open source licensing can be reused.

CentOS desktop - click to enlargeCentOS is a project that aims to rebuild the sources from this “prominent North American Enterprise Linux vendor” and make a distribution that is very similar to RedHat. The RedHat logos of course do not appear as they are proprietary, but the rest is similar enough to use as a way to learn about this platform. If you are using Ubuntu you might be wondering why build a CentOS virtual machine? There are many differences between the Ubuntu and CentOS distributions that might affect your development, the two systems use different package managers (RPM on CentOS and APT on Ubuntu), the file systems are laid out slightly differently and sometimes different versions of key software are officially supported, which could potentially cause incompatibilities.

You can install CentOS as a virtual machine in VirtualBox without having to download a full installation CD image by using a “net install” CD. This contains just enough files to be able to start installation and connect to the Internet to download the other resources needed. The current net install image is just 8.3MB in size and can be found at the CentOS download page: http://www.centos.org/modules/tinycontent/index.php?id=15, go though this and select a mirror that is local to you. The file name of the current net installer is “CentOS-5.3-i386-netinstall.iso” (when I downloaded it, CentOS was on version 5.2 so there may be some differences between what is written here and your experience).

Set up a new virtual machine (VM) on VirtualBox with the following options:
Name: Centos 5.2
Type: Linux
Version: Redhat
Base Memory:
1024
Hard disc: New hard disk image, dynamically expanding, 8GB

Before you start the VM up, click on the entry for the new machine and click Settings. Under GeneralAdvancedExtended Features select “Enable VT-x/AMD-v” if your processor supports it, under Audio select “Enable Audio” and select “OSS Audio Driver” (or the audio driver that works best for you) and “ICH AC97” for the audio controller. Start up the virtual machine and when the first run wizard appears select the image of the net install CD that you downloaded. When the VM starts you'll be asked if you want to install in graphical or text mode, I selected graphical, however the first few configuration screens will be text as we are doing a net install. After selecting you preferred language and keyboard type, select “HTTP” for the installation method. Leave the “Configure TCP/IP” options at their defaults.

The next screen is “HTTP Setup”, here you will enter the values where CentOS can find the rest of the installation files it needs. You'll need to work out these values for your local mirror, it is the directory containing CentOS for your target architecture. This is not the same as the CD image download directory. The actual file it is looking for next is called “stage2.img” which should be under the “images” directory of this mirror location. For example, I downloaded CentOS from the UK Mirror Service so the value I entered for “Web Site Name” was “www.mirrorservice.org” and the value for the CentOS directory was “/sites/mirror.centos.org/5.2/os/i386/”. Next you should see a message saying it is retrieving the “images/stage2.img” file. After a short delay you should find that the graphical installer starts up and the next step is to let it partition the virtual disc, click “Yes” to this request and then select “Remove all partitions on selected drives and create default layout”, leave the next screen “Network devices” as is, the next screen will ask your location, then it will ask for a root password. Now it will ask you what software you want to install, here I just selected “Desktop – GNOME” and enabled the additional repository of “Packages from CentOS extras”. Phew! Nearly there, now it has enough information to install the operating system to your virtual machine. The whole process isn't quite as slick as Ubuntu, but it is slightly more complicated because we did a net install.

When installation is finished and you log into CentOS for the first time the Setup Agent will run to enable you to set up some basic configuration information such as a non-root user name and password. When you log in it will also check for any updates, you should apply all of these before trying to install the VirtualBox Guest Additions.

The final step is to install the VirtualBox Guest Additions. In your VM window select DevicesInstall Guest Additions to “insert” the CD image with the required software. In CentOS open a terminal (ApplicationsAccessoriesTerminal) change to root (type “su”) and install the packages necessary to compile a new kernel module:

yum install gcc
yum install kernel-devel

Now go to the folder where the Guest Additions CD is mounted (cd /media/VBOX then press [TAB]) and enter:
sh VboxLinuxAdditions-x86.run (for the 32 bit version)

When it is finished and the VM rebooted you should now have a fully working CentOS installation.

References:
CentOS 5 documentation: http://www.centos.org/docs/5/
How to install Guest Additions in CentOS 5.1: http://forums.virtualbox.org/viewtopic.php?t=4960&highlight=install+guest+addition
Entry in Wikipedia for CentOS: http://en.wikipedia.org/wiki/Centos

Comments

Hi, I'm a complete newbie with VirtualBox but just used this guide. Extremely helpful and reliable, got everything working although I used the DVD install route via bitTorrent rather than the Net install.

A couple of very small comments, at the end where it says:

Now go to the folder where the Guest Additions CD is mounted (cd /media/VBOX then press [TAB]) and enter:
sh VboxLinuxAdditions-x86.run (for the 32 bit version)

that means type:

cd /media/VBOX

within the terminal window. I got a message saying no such directory because the names had changed slightly, in that case you can change directory (cd) to:

cd /media

then type:

ls

which stands for list and will list all the directories so you can guess the right one and "cd" inside that one.

Incidentally you press [tab] because it auto completes lines for you, type the first few letters then press tab.

Great guide, many thanks.

This is just what I was looking for after a failed "default" install. I'll try it out tonight. Thanks for the guide!

Excellent writeup, and was invaluable in helping me get CentoOS guest system installed on my XP host!

One problem I had was trying to install using the most recent versions of CentOS (5.4 and 5.5). They had dependency issues which I could never figure out.

Once I went back to archives and found CentOS 5.2, that installed with no problems. Then the updates brought me up to the most recent version (5.5).

Thanks for this tutorial.
However, I ran into problems by enabling the additional repository of “Packages from CentOS extras”.
I installed it without this option.

Thank you very much it was a great and clear help.
Best regards

Very nice guide thank you!

My only criticism is this blatant prejudice against people with slow connections! I never experienced any "short delay", more like half an hour of waiting!

Only joking of course, thank you again.

Add new comment

Comments are always very welcome, but please note the following:
  • Sadly due to the high number of spam comments recently all comments are now manually moderated. You comment will therefore not appear on the site instantly.
  • Comments on this web site are monitored for spam using Mollom. By posting a comment, you accept that your message and other personal details about you will be analysed and stored for anti-spam and quality monitoring purposes, in accordance with Mollom's privacy policy.
  • Please use your own name not a company or website name to submit comments. Your comment will be removed if you don't do this.
  • All links in comments will be marked with a no follow attribute. That means posting a link to your site here won't help your search engine rankings.
  • By submitting a comment you agree that your comment can be reproduced under the same licensing terms as the rest of the content on the site.
  • Comments can be removed at any time without explanation, but won't be removed just because you disagreed with something I said.