Wednesday, 18 July 2012

Centos 6/RHEL install VirtualBox, Guest OS and Guest Additions

VirtualBox is a well regarded virtualisation software used by many developers for testing code on multiple Operating Systems without having seperate machines or physical partitions. With VirtualBox or similar it's easy to backup the virtual disks created and install them on other machines, saving a lot of work.

If you haven't yet installed Centos 6 check out this tutorial which covers a minimal installation using Fluxbox, Thunar and Rxvt for a fast lightweight Desktop.

VirtualBox seems to be slightly less resource heavy than the VMWare equivalent, a factor to consider if you have limited hardware capabilities.

Install VirtualBox

Make sure you have required build packages installed 

$ sudo yum -y install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

You will need to create
  • A Sun Virtual Box .repo file.
First open a terminal and type

$ sudo vi /etc/yum.repos.d/virtualbox.repo

to create a blank repo file 

Go to https://www.virtualbox.org/wiki/Linux_Downloads and scroll right down to the very bottom of the page, click on the appropriate link to open the repo file in your browser.

They are tucked away at the end and you have to look carefully for them below the following dialogue.

'Note that importing the key is not necessary for yum users (Oracle Linux/Fedora/RHEL/CentOS) when using one of the virtualbox.repo files from below as yum downloads and imports the public key automatically!'

(There are repo files available for RHEL, Fedora and openSuse there, as well as deb, rpm and .run files for other distros at the top of page)

Once open, copy/paste the contents into the blank repo file you just created in vi and save it.

See Vim Editor for vi commands 

Below is the repo file contents for Centos/RHEL which you can use if you cant find it at the link above.

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc

That done, now we do a yum search to check

$ yum search all virtualbox

you should get similar to below

VirtualBox-3.2.i686 : Oracle VM VirtualBox
VirtualBox-4.0.i686 : Oracle VM VirtualBox
VirtualBox-4.1.i686 : Oracle VM VirtualBox
VirtualBox-4.2.i686 : Oracle VM VirtualBox

VirtualBox-3.2.x86_64 : Oracle VM VirtualBox
VirtualBox-4.0.x86_64 : Oracle VM VirtualBox
VirtualBox-4.1.x86_64 : Oracle VM VirtualBox
VirtualBox-4.2.x86_64 : Oracle VM VirtualBox

If not, CHECK that you have given the file .repo extension.

If using VirtualBox for WebOS then you will need the 4.1 version.

Now we can install one of them

$ sudo yum -y install VirtualBox-4.1.i686      
$ sudo yum -y install VirtualBox-4.2.x86_64    

Add your user to vboxusers group 

$ sudo usermod -a -G vboxusers <username>    

Log out & back in to check it was added

$ groups 

anton vboxusers

Run it with                        
   
$ virtualbox 

If using Fluxbox, you can add an entry at the top of the

/home/user/.fluxbox/keys file 

Mod1 v : ExecCommand virtualbox         hit Alt+v to run it

$ cd Desktop                        and create a shortcut with

$ ln -s /usr/bin/virtualbox

See Fluxbox key bindings for more. 

Install a Guest Operating System
.
Now to install a Guest Operating System on VirtualBox

I chose Windows XP 64 bit as I have a key and it is useful for quite a few things still although of course you can use any that you have. So first we run Virtualbox.

$ virtualbox

Click on 'New' and run the New Virtual Machine Wizard

Before you install a guest OS you have to create a Virtual Disk and set a few parameters, the wizard walks you through.

1.Select VM name and type.
    2.Select Memory Size.
      3.Create New Hard Disc.
        4.Select VD Disc Format. 


        If you have qemu installed options should show, I chose VMDK.


          5.Select Fixed Disc Method.  (Faster)
            6.Select Location and Disc size.

            7.Summarize, click 'Create' and let it run as below.



            After the Virtual Disk is created , place your OS installation disc in the computer CD Drive.

            In the left column of VirtualBox, double click on your newly created and named OS Virtual drive and let it run, it will detect the disc and install the OS as below.






            Follow the installation procedure to completion as you would on a physical machine, then reboot into your new Virtual Operating System as below.



            Now you have a Guest OS in VirtualBox.

            Guest Additions

            Guest Additions adds many extra features to your guest operating system and is a must have for improved performance.

            To install it make sure your machine is running as in the last screenshot above, then click on 'Devices' in the top menu. Scroll down to 'Install Guest Additions' and click on it.

            This will bring up the dialogue box and you will go through a few screens as below.








            There will be others dependent on the OS, but it is all pretty self explanatory, at the end reboot the OS in VirtualBox.

            Now you have Guest Additions installed and you will have USB support, Mouse capture and other goodies. It will show up as a virtual drive within your guest OS as below.



            That's VirtualBox, a Guest OS and Guest Additions on Centos6


            No comments:

            Post a Comment