How to Setup CentOs in VirtualBox

by Ryan on May 5, 2010

My primary development environment is generally a CentOS install through VirtualBox. Although the examples here are all CentOS, this guide can be used to install any operating system through VirtualBox.

What is a Virtual Machine

A virtual machine provides a platform for your machine to execute and support a complete operating system. In other words, it is like having an operating system installed on your computer that can be accessed as if it were just another program. Need to test something in Windows, just open up the Windows virtual machine and close it when done. With Sun/Oracle’s VirtalBox platform, installing and maintaining these virtual machines are easier than ever.

Getting Started

Setting up a virtual machine is actually really easy. It may seem intimidating at first, but if you can install Firefox on your computer then you can handle installing a virtual machine. The first thing to do is to download the operating system as well as the VirtualBox platform.

Download the Os

Download the operating system and save it somewhere on your computer. Generally, this is going to be an ISO file. CentOs has three ways to install. The first is by downloading seven (yes, seven!) different iso files. Avoid this at all costs, because mounting and unmounted seven different files during an OS install is quite annoying. The other options are a DVD or a net install. I prefer having a copy of the DVD, but the net install is approximately 10mb so it is really easy to download.

Download and Install VirtualBox

Head over to the VirtualBox download area and pick the version that matches your computer. You are selecting the version that will be installed on your computer. So if your computer is a Windows computer, select the Windows version.

Installing the Virtual Machine

VirtualBox’s setup wizard makes it really easy to install a Virtual Machine. Really easy. So easy, that this guide is pretty much useless.

Naming

Open VirtualBox and click the ‘New’ button in the top right. This will pop up the wizard.

For the name enter something really simple that describes the box. I usually enter the box’s host name such as ‘development1′.

Choose the best operating system/version that matches your install. For CentOs choose Operating System: Linux and Version: Red Hat.

Memory

The next step will be memory. Understanding how the virtual machine uses your systems memory is pretty important. Whenever the virtual machine is on it will immediately take up all the memory it was given. For example, if your computer has 2gb of memory and your virtual machine is set to use 1gb of memory then as soon as your virtual machine turns on 50% of your memory is in use. Assigning too much memory or leaving unnecessary virtual machines turned on is a great way too eat up your computer’s resources and make your system crawl.

VirtualBox shows a slider with the bounds for safe memory. Stay within the green and you will be fine. The amount of memory can always be changed later on.

virtualbox-memory

Hard Disk

Next we have the hard drive, which I generally keep small, around 8gb for CentOs. I find that this is more than enough space. VirtualBox also allows your virtual machines to access files on your computer’s hard drive, so sharing files that already exist on your computer is very easy.

Setup

Your machine is all setup, but right now it is a bare machine with no operating system installed. Before booting the machine, go into the settings (right next to the ‘New’ button). These are settings that can be changed whenever your virtual machine is off. I’d recommend browsing each of these sections and tweaking with the settings. It’s pretty hard to break anything here, so experiment and do whatever you think is best. Remember that you can always change these things later.

Network

One setting I recommend changing right away is the network. By default, VirtualBox uses a NAT network type. I like to use the bridge adapter network, because it will make the virtual machine act more like a computer on the network. With a bridged network the virtual machine will actually contact the router through your computer’s network card and obtain a new IP address. This makes accessing the machine services, like httpd, extremely easy.

Installing the Os

If we try to start the virtual machine we will get an error telling us that no bootable medium was found. This is because there is no OS installed. To install an OS start (boot) the virtual machine.

On the bottom right of the virtual machine’s window you should see a grayed out CD. Right click this CD and click ‘more CD images’.

Virtual Machine Options

Click the Add button and find the ISO file for the operating system you downloaded. Select that and then reboot the machine. Easiest way to reboot is to use the Menu Bar -> Machine -> Reset. Also Right Ctrl + R works.

Once your machine reboots you should be able to install the OS from the ISO you mounted. After your OS has installed you can use your new virtual machine as if it were a new computer.

2 Responses leave one →
  1. Mark permalink
    May 26, 2010

    I had so many problems getting CentOS set up. I used the net installer, and after I got to the GUI, CentOS wasn’t able to find any hard drives on which to install itself.

Trackbacks and Pingbacks

  1. My Development Environment

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS