Creating and Managing CentOS virtual machine under Virtualbox

September 8, 2008 at 8:33 am 25 comments

In this article, I will describe how I created a CentOS virtual machine under Virtualbox. The CentOS virtual machine will deviate from a default virtual machine create in the following way:

  • The CentOS virtual machine will use SATA instead of IDE drives. This will increase flexibility and performance.
  • We will use separate virtual disks instead of partitioning a single virtual disk. The separate disks will simplify maintenance and upgrades.
  • The virtual disk will be allocated as a very large dynamic disk. A partition will be created within the virtual disk that uses only a small part of the virtual disk. The virtual disk for example may be created to be a 200 Gb dynamic disk and then we allocate only 5 Gb as a partition, leaving the rest free. Because it is a dynamic disk, there is actually no wasted space. The free space can be used later to expand the partition.

The article is meant as a tutorial. Generally, here are the following steps.

  1. Create the Virtual disks.
  2. Creating the Virtual Machine.
  3. Installing CentOS.
  4. Installing the guest addition.
  5. Correcting the Video Resolution
  6. Expanding the Partition Size

Create the Virtual Disks

We’ll do things a bit differently than the default by creating the virtual disk first. We will create 3 virtual disks: root, home, and swap. The reason we have separate disk is to give us flexibility than having all 3 partitions on the same drive. If you run of out space on home for example, you can swap in a larger virtual disk without disturbing the other two volumes.

In addition, we will create a much larger drive than we need. Once created, you cannot extend a virtual disk volume. You have to create a new volume and copy the content over to the new volume. We will solve this problem by creating a really large volume like 200 Gb. Because we will be using dynamic size disk, the initial disk will be quite small.

  1. Launch the Virtualbox application.
  2. Select File->Virtual Disk Manager.
  3. Click New. This brings up the wizard. Press Next. Select dynamic disk and press Next. Enter the name of the your VM and append ” root” at the end. So if you name your machine “CentOS”, this disk would be called “CentOS root.vdi”. Set the disk size to a really large number like 200 Gb and press Next. Press Finish to complete.
  4. Click New. This brings up the wizard. Press Next. Select dynamic disk and press Next. Enter the name of the your VM and append ” home” at the end. So if you name your machine “CentOS”, this disk would be called “CentOS home.vdi”. Set the disk size to a really large number like 200 Gb and press Next. Press Finish to complete.
  5. Click New. This brings up the wizard. Press Next. Select fixed size disk and press Next. Enter the name of the your VM and append ” swap” at the end. So if you name your machine “CentOS”, this disk would be called “CentOS swap.vdi”. Set the disk size to 2x your intended virtual machine RAM (so if you intended to us 1 Gb RAM in your VM, use a disk size of 2x) and press Next. Press Finish to complete. Unlike home and root, you want swap to be a fixed disk size so that you won’t have an extend disk operation when you need virtual memory.

After these steps, you should have 3 different disk: root, home, and swap.

Creating the Virtual Machine

The follow step will create the virtual machine. We will also attached the disks we created earlier to the virtual machine.

  1. Launch Virtualbox.
  2. Select the menu Machine->New to create a new virtual machine. This will bring up a wizard.
  3. Click next to go to the next screen.
  4. You will be prompted for VM name and type. Enter the name like “CentOS”, and select the OS Type of RedHat (since CentOS is a derivative of RedHat). Press Next.
  5. You will be prompted to set the memory. I set mines to 512 Mb. Press Next.
  6. Now we are at the virtual disk screen. Click Next, you will be warned that you didn’t attach a hard disk. Press Continue. You will attach the disk later.
  7. Press finish.
  8. Select the machine and press on the settings button.
  9. Select Hard disks to bring up the hard disk settings.
  10. Check the “enable SATA controller”. The virtual SATA controller has greater flexibility and faster performance than the virtual IDE.
  11. Click Add disk button. Select the SATA Port 0 from the Slot’s drop down field. Assign the root disk you created.
  12. Click Add disk button again. Select the SATA Port 1 from the Slot’s drop down field. Assign the home disk you created.
  13. Click Add disk button again. Select the SATA Port 2 from the Slot’s drop down field. Assign the swap disk you created.
  14. Press OK to close the hard disk settings.
  15. Click on the audio setting. Check enable audio settings and select the appropriate audio driver.

Install the CentOS

Now we have a virtual machine but no operation system. Our next step is to install CentOS and configure it.

  1. Download CentOS. For this tutorial, I used CentOS 5.2.
  2. Launch Virtualbox.
  3. Select the new virtual machine you created and click on settings.
  4. Click on CD-ROM and mount the CentOS 3.2 image.
  5. Start the virtual machine.
  6. Once the CentOS title screen appears. Press Enter.
  7. Click on the Skip test button. Although it’s better to check your media, the test often result in the CD-ROM being ejected. After the CD is ejected, there seemed to be no easy way to get it to reappear.
  8. On the CentOS splash screen, press Next.
  9. Select the appropriate language and press Next.
  10. Select the appropriate keyboard and press Next.
  11. You will be warned that sda is unreadable and ask if it can format and erase all of the data. Press Yes (since your new virtual disk has no data).
  12. You will be warned that sdb is unreadable and ask if it can format and erase all of the data. Press Yes.
  13. You will be warned that sdc is unreadlable and ask if it can format and erase all of the data. Press Yes.
  14. On the partition screen, select custom layout and press Next.
  15. Click on the New button. Set the mount point to “/”. Uncheck all volume except sda. Set the size to what you think you will need. Press OK. We are meant to use a small percentage of the virtual disk for the partition. The idea is if we need to a larger disk, we can use a partition program to extended it.
  16. Click on the New button. Set the mount point to “/home”. Uncheck all volume except sdb. Set the size to what you think you will need for the home directory. Press OK.
  17. Click on the New button. Set the File System type to swap. Uncheck all volume except sdc. Set the size to fill to maximum size since we want to use all of it for swap. Press OK.
  18. Press the Next button.
  19. You will be prompted to ask if you want to install Grub. Press Next to select the default option of installing Grub on /dev/sda
  20. Press Next to use the active device of eth0 and DHCP.
  21. Select the appropriate country and press Next. WARNING: If you plan to run a mix of Linux and Windows machine, make sure you uncheck “System Clock uses UTC”. Press Next.
  22. Enter the root password and press Next. Make sure you record this somewhere.
  23. You will be prompted to select the software. The system will default to Gnome Desktop. Select the option “Customize Later” and press Next.
  24. The installer will check for dependencies and then display a screen telling you to press Next to continue the installation. Press Next.
  25. Installation will continue for half an hour and then you are presented with an option to reboot. Click on the reboot button and boot from the hard drive instead of the CD.
  26. After reboot, your configuration will continue on a welcome screen. Press Forward.
  27. Press Forward to accept the default firewall configuration.
  28. Press Forward to accept the default for SELinux.
  29. Press Forward to accept the date (note: do not turn on NTP).
  30. Enter the info for a user other than root. Press Forward.
  31. Press Forward to accept the sound config.
  32. Press Finish to complete configuration.
  33. Login as the user you just created.
  34. Wait until you get a notice that there are updates.
  35. Click on the notification and view update. Enter the root password when prompted.
  36. Click on the package updater’s apply updates. You may be prompted about dependencies. Press Continue if that is the case.
  37. Now wait for a while. The update may take several hours for the updates to complete.
  38. Open up a command line window and su to root by typing su and then entering the root password.
  39. Type the following commands to install the compiler and kernel source.yum install gcc -y
    yum install kernel-devel -y
  40. Select the menu Devices->Install Guest Additions from the virtual machine menus.
  41. In the command line, cd to the /media. There should be a Vbox folder within media. Change directory into that folder. There should be a .run file for your machine. For example, on my guest, I did the following:cd /media/VBOXADDITIONS_2.0.0_36011
    sh ./VBoxLinuxAdditions-x86.runYour actual command will vary according to your version of virtualbox.   
  42. Reboot your virtual machine.

Correcting the Video Resolution

On my laptop with a 1280×800 screen, the resolution was not correctly detected. Even when I went in and manually set my Monitor type to 1280×800 in Administrator->Display Settings. I had to manually set the xorg.conf file. Backup your config file and add or modify a subsection in the section screen.

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
	DefaultDepth     24
	SubSection "Display"
		Viewport   0 0
		Depth     24
		Modes   "1280x800" 
	EndSubSection
EndSection

The important line to add is ‘Modes “1280×800″‘. The addition of this line causes CentOS to go into 1280×800.

Virtualbox supports a dynamic video display where the size of the desktop is automatically adjusted with the size of the window. However, this is supported only on Xorg server version 1.3 or later. CentOS is using version 1.1, so it does not support dynamic display.

Expanding the Partition Size

Suppose you run out of space later on. If you use the default way of creating virtual disk, you will have to create a new disk, copy the content from one virtual disk to another. This is not trival to do.

If you have followed my instructions, we have created a really large virtual disk, but we really only use a small percentage of the disk. Now if we want to expand, we can boot your virtual machine into a live CD that has a partition editor like gparted. You wan to boot into your live CD because you can’t modify a partition when it is in use. You can use the gparted utility to expand your partition.

Advertisements

Entry filed under: CentOS, linux, Redhat, Virtualbox, Virtualization.

Error 401 when using ObjectDatasource to call a web service Switching to the Open source Athero driver after Mandriva 2009 upgrade

25 Comments Add your own

  • 1. hotcoder  |  October 24, 2008 at 7:01 am

    Great work, thanks alot

    Reply
  • 2. Murillo  |  February 5, 2009 at 6:14 pm

    Good job !

    Works fine to me.
    I´m a CentOS and VBox newbie and this script was the best that I found in the net!!

    Congratilations for the nice job!!

    Reply
  • 3. Jim  |  February 13, 2009 at 5:45 pm

    I had a problem installing the guest additions running CentOS 5.2 on WinXP wiht Virtual Box 2.1.2.

    The following commands will fix the problem (I found this from another forum: http://forums.virtualbox.org/viewtopic.php?t=4960&highlight=install+guest+addition):

    yum install kernel sources
    yum install kernel-devel
    yum install gcc
    ln -s /usr/src/kernels/2.6.18-92.1.18.el5-i686 /usr/src/linux
    sh VBoxLinuxAdditions-x86.run

    This should fix the problem.

    Reply
  • 5. pouctam  |  November 23, 2009 at 11:48 am

    Hello!

    I tried the exiting stuff about with the host as windows vista and the guest as Centos 5.4 but with no success.
    During the check of dependency, almost at before the ‘half an hour installation’ will start, the windows will stop working because of unknown problem and a pop up will sugest closing the Virtualbox!

    Can you give me an idea about this problem?

    Thank you!
    J. P.

    Reply
  • […] to this there’s probably 1,000’s of great tutorials out there (ok, here’s one: Creating and Managing  centOS virtual machine under virtualbox). The important point to note I suppose is that I called my virtual machine […]

    Reply
  • 7. DK  |  January 4, 2010 at 1:34 am

    Many Many Thanks for this great Job. It worked nice for me and i created a CentOS 5.3 VM inside the Win XP.

    There are some details missing in this manual like how to add the Sata Controller and how to make some settings of the virtual disks at the beginnig of this manual.

    But i navigated it a little bit and i found every thing.

    Reply
  • 8. ubu_fan  |  January 9, 2010 at 10:29 pm

    w0w ! !
    What a well put together Tutorial, i cant wait to try CENTOS after reading your post. I plan on installing it next week but i was looking for a comprehensive HOWTO to give me a jump-start
    Thanks Again……

    Reply
  • 9. Ben  |  April 4, 2010 at 4:56 am

    The information about changing the screen resolution on the CentOs guest worked for me, I can get it to 1440×900 on 15″ macbook pro.

    I must add that you need to give it enough video memory size, mine had 6Mb and it did not work, then I raised it to 16Mb. Maybe it could be less, but I did not try

    Reply
  • 10. Mike  |  May 10, 2010 at 8:59 pm

    Great writeup, very helpful step-by-step guide to setting up CentOS from scratch.

    For those wanting to install the older CentOS 4, you must stick to IDE instead of SATA, the default kernel doesn’t support SATA. I created a single IDE disk and let the installer auto-partition it.

    I had trouble with the kernel not booting once the install finished. Not sure if this is specific to CentOS 4, 32 vs 64-bit, or my version of VirtualBox, but I had to check the “Enable PAE/NX” option under the virtual machine settings. Without this option the (default) SMP kernel would not boot, period.

    Lastly, I had to add “divider=10” to the kernel command line as seen on many other forums, otherwise the guest system clock was way off and the keyboard repeat was crazy.

    Reply
  • […] you are running an older CentOS guest you may have to manually add additional resolutions to the xorg.conf file. Tags: […]

    Reply
  • 12. Brain  |  January 23, 2011 at 6:07 am

    Thanks for guide, I will create CentOS under Virtualbox.

    Reply
  • 13. farhan  |  March 28, 2011 at 7:44 pm

    Hi,

    I am trying to install centos on windows host, while installation i have selected ” Remove all linux partition on seleted drive and create default layout” and as soon as i press next I keep getting on prompted by the message :

    “No Drives Found An error has occurres – no valid devices
    were found on which to create new file systems, Please check your hardware for the cause of this problem”

    Please help

    Reply
  • 14. oren  |  April 19, 2011 at 5:42 am

    10x man, been great help.
    Thank god for people like you on the net with initiative and a will to help.

    cheers

    Reply
  • 15. Sam  |  June 10, 2011 at 3:39 pm

    EXCELLENT! Worked flawlessly with CentOS-5.6-i386 binaries (iso images 1-5). Thank you very much!!

    Reply
  • 16. Sajith Koroth  |  June 22, 2011 at 1:57 am

    how to share file between windows xp host and centos guest which is in vrtual box . Need to install vsftpd..

    Reply
  • 17. saurabhgupta2usaurabh  |  October 5, 2011 at 4:49 am

    Really well done article! Many, many thanks!

    Reply
  • […] tried editing my xorg.conf (based on this tutorial https://paulsiu.wordpress.com/2008/09/08/creating-and-managing-centos-virtual-machine-under-virtualbo…) but it doesn’t seem to have made a difference. Here is a snippet from the edited […]

    Reply
  • 19. Homepage  |  March 11, 2013 at 1:45 am

    Hello, I log on to your blog regularly. Your story-telling
    style is awesome, keep doing what you’re doing!

    Reply
  • 20. Barrett  |  May 2, 2013 at 9:39 pm

    Wow, superb blog layout! How long have you
    been blogging for? you made blogging look easy. The overall look of
    your site is excellent, let alone the content!

    Reply
  • 21. opciones binarias  |  May 3, 2014 at 2:15 am

    hi!,I like your writing very so much! percentage we keep up a correspondence extra approximately your post on AOL?
    I need a specialist in this space to resolve my problem.
    May be that’s you! Looking ahead to see you.

    Reply
  • 22. Johnb216  |  August 1, 2014 at 10:50 am

    Today, while I was at work, my sister stole my apple ipad and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone! ggkdkeeedfac

    Reply
  • […] tried editing my xorg.conf (based on this tutorial https://paulsiu.wordpress.com/2008/09/08/creating-and-managing-centos-virtual-machine-under-virtualbo&#8230😉 but it doesn’t seem to have made a difference. Here is a snippet from the edited […]

    Reply
  • […] tried editing my xorg.conf (based on this tutorial https://paulsiu.wordpress.com/2008/09/08/creating-and-managing-centos-virtual-machine-under-virtualbo&#8230😉 but it doesn’t seem to have made a difference. Here is a snippet from the edited […]

    Reply
  • 25. Taruhan Online  |  March 23, 2016 at 1:57 am

    Absolutely composed content , regards for selective information .

    Reply

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

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

September 2008
M T W T F S S
« Aug   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

Most Recent Posts


%d bloggers like this: