In this post we will install CentOS 5.5 as a guest operating system in Virtualbox. In order to do this, we need to have some kind of installation media handy. Virtualbox will allow us to install via DVD or, more conveniently, an ISO located on the host operating system's hard disk.
If you don't have a CentOS DVD or ISO handy, you're going to need to download one; in order to download it, you're going to need a bittorrent client, a good one for Windows is uTorrent. Hop on over to the CentOS mirrors page and grab a copy of the DVD torrent for your computer's architecture. If your computer is 64 bit, choose x86_64, otherwise if it is 32 bit or you are unsure, get the i386 version. After selecting an architecure, choose a mirror from the list to be taken to a download page. The file that you are interested in is either CentOS-5.5-i386-bin-DVD.torrent or CentOS-5.5-x86_64-bin-DVD.torrent, depending on your architecture. The torrent will download two DVDs, but we really only need the first one.
After downloading a copy of the media to your hard disk, it's time to get started. Go ahead and fire up Virtualbox. You should be presented with a screen that looks something like this:
Click the button labeled "New" in the upper lefthand corner to create a new virtual machine. This will start a wizard to take you through the process of creating a new machine. After clicking "Next," the Wizard will ask you for the VM Name and OS Type, like so:
Give your machine a name. If you give it the name CentOS, it will automatically change the operating system to Linux and version to Red Hat. Red Hat is the correct version, because CentOS is a clone of Red Hat. It is important that if you downloaded a 64 bit image to change the version to "Red Hat (64 bit)."
After clicking next, the wizard takes us to a screen where we can select the amount of memory that the guest operating system will have available to it:
Virtualbox recommends 512 megabytes and that is a good number to go with, since setting up a virtual lab is going to require us to run multiple guest OS at once, and each one is going to need it's own block of RAM. You can always change the amount of RAM the guest has available to it later in the virtual machine's settings.
Click next and move on to the virtual hard disk setup:
Here, we basically have the option of creating a new hard disk, using an existing disk, or attaching disks later. We're going to go with the first option and create a new disk, so go ahead and click next.
This will open up another wizard, where we create the disk for the machine. Go ahead and click next again, which should bring you to a window that looks like this:
This screen gives us the option to choose whether we want to use dynamically expanding or fixed-size storage. Since the guest operating system will live in a .vdi file on your hard disk, it's nice to just have the file increase in size as the guest operating system grows. Dynamic disks save space on the host and make backups easier because you end up with a smaller file. Click next and move on to the next screen, where we will define the size of the virtual disk.
When we first get to this screen, Virtualbox gives us a recommended default size of 8GB. That's fine if you don't want to use a custom partition layout or install all the packages, but for the purposes of this tutorial, we'll be using a 15GB disk, since it will allow us to install all of the packages if we choose to do so, and also give us enough room to play around with. Change the size of the disk to where you want it, and click next.
Both wizards are at the end now, and are going to display a summary. Go ahead and click finish for both of them, and there should be a new virtual machine in your list:
Now that that's taken care of, click the green start arrow to fire up the virtual machine. At various points while running the machine, Virtualbox will pop up with some windows with various information about keyboard and mouse capture:
These dialogs are confusing at first, but they are basically telling you that once you use your mouse or keyboard inside the guest OS, in order to make them available to the host you have to press the host key, which is defined as the right control key. The left control key functions as normal in the guest, but pushing the right one will release the mouse and keyboard back to the host operating system.
The first time you run the machine, it will bring up the first run wizard. Go ahead and click next to get started.
Click the folder with the green arrow to select the ISO file we downloaded to install from. This will take us to the Virtual Media Manager, which should be empty. Click the "Add" button and browse to the folder where you downloaded the CentOS DVD ISO and select it. The Virtual Media Manager should now look something like this:
Highlight the ISO you want to install from and click select. The ISO should now be available in the wizard's drop down box:
Make sure it's selected and click next. Next a summary screen will be displayed. Click "Finish." This will boot into the CentOS installer.
The rest of the tutorial will focus on the actual CentOS install process. Hit enter to begin.
This screen will perform an optional check on our installation media. Since we are installing our system from an ISO we downloaded and not a scratched DVD, we'll skip this step. Push tab to highlight the "Skip" option and select it with the spacebar. This will load the graphical installer. Click "Next," which will take us to a screen where you can select the language you want to use for installation. Click "Next," and select your appropriate keyboard, which is most likely "U.S. English" if you are in the United States. Click "Next," and you should be presented with the following dialog:
This screen is informing us that we are going to erase all of the data on our virtual hard disk. This is okay, it will not delete all of the files on your host operating system. Go ahead and click "Yes."
At this screen, the installer is going to ask us how we want to partition the disk. You could use the default layout, but we will be creating a custom layout, which is the more advanced option. Select "Create custom layout" from the dropdown box and click "Next" to define the partitions.
From here, click "New" to get started adding the first partition.
Select "/" for the first mountpoint from the dropdown box, and give it a size of 1 GB (technically 1GB is equal to 1024MB, but we will just use multiples of 1000 for simplicity's sake). Click "OK." You should now see the new partition in the editor, which should now look something like this:
Go ahead and click "New" again to create another partition. This time, we are going to create the swap partition:
Typically, it is a good idea to set the swap size to twice the size of your RAM. Since we setup our virtual machine with 512MB of RAM, we want a swap size of 1024MB. Set the filesystem type to swap and enter the proper number of megabytes, then click "OK." Continue adding partitions just like before, with a layout as follows:
|/usr||8 GB||/usr/local||1 GB||/home||1 GB|
After setting up your partitions, you should notice that there is a little bit of free space left at the end of the drive.
Let's take care of that free space, by adding it to the /home partition. Highlight the /home partition in the list, and click "Edit."
We want to leave everything the way we had it, only selecting "Fill to maximum allowable size" from the section labeled "Additional Size Options." This will add the rest of the free space to the partition.
Finally, our partitions are set up, so click "Next." This will take us to the boot loader configuration, and we can just accept the default option and use GRUB, so click "Next." Next is the network configuration, and we want to accept the default here and use DCHP. Click "Next" again. You should now be at a map where you can select your timezone:
Select your timezone, either from the dropdown menu or by clicking one of the locations on the map. Then click "Next" where you will be asked to setup the root password:
The root user is the administrative user for the system that can change anything, so it is a good idea to set a strong password. Enter your password twice, then click "Next."
Now it's time to select the packages we want to install on the system. I just checked the "Server" and "Server GUI" packages in addition the default GNOME package. If you think there is something else you want, feel free to add it, otherwise, don't worry, you can always add more packages later. If you choose the "Customize now" option, you will be taken to a page where you can do a more detailed package selection. For the sake of speeding things along, we are just going to leave the default, "Customize later."
After selecting packages, click "Next." This will take us to a page that will tell us installation is about to begin, so go ahead and click "Next" to get things going.
The installation process takes a bit of time, so now would be a good time to go do something else. After it is finished, the installer will tell you installation is complete, but that's not true. Click "Reboot," and after the system reboots, you will be taken to a configuration phase of the install process. Click "Next" through the "Welcome," "Firewall," "SELinux," "KDump," and "Date and Time" screens, accepting the defaults for each. Now you should be at the screen where you create your regular user that you will be logging in with to do most day to day tasks. It is good to have a user besides the root user to do most work on a system, to prevent accidentally misconfiguration. Go ahead and enter your credentials:
After creating a user, you will be taken to a screen to configure the sound card. It should work, but feel free to test it. After testing, click "Next" and you will be taken to a screen asking for additional CDs. We don't have any additional CDs, so just click "Finish" to complete the installation.
At long last, our system is now ready to use! Login with the user you created, and enjoy the benefits of using Linux as a virtual machine!