Archive for September 8, 2008

Creating and Managing CentOS virtual machine under Virtualbox

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.

September 8, 2008 at 8:33 am 27 comments


Calendar

September 2008
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Posts by Month

Posts by Category