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 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
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 General → Advanced → Extended 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 Devices → Install Guest Additions to “insert” the CD image with the required software. In CentOS open a terminal (Applications → Accessories → Terminal) 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.
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