Sunday, February 12, 2017

Setting up Centos7 with Virtualbox

As more and more companies embrace the "Cloud", where I work was no exception. In recent 2+ years, I have been in PaaS team setting up platform for various application development teams.  In a nut shell, the work is about automation! Provisioning VMs, configuring VM with platform level components and services. Many times in the earlier stage, I felt like it would be very helpful to help junior team members to study and understand the corner stone - Virtual Machine - of the cloud paradigm. JVM, the most common virtual machine that we work with almost every single day. But, once being asked if the person has provisioned a Linux machine, the answer was normally no. In this blog, I am trying to capture the steps of setting up a Linux VM on windows.

Before we start, a few jargon or concepts to clarify:

  • Guest Machine: the virtual machine you get. 
  • Hypervisor: a piece of software that is responsible to create and manage virtual machines. Specifically, from infrastructure's angle, the resources to be managed are compute (CPU and memory), storage and network. In our example, Virtualbox is the Hypervisor.
  • Host Machine: the machine where virtual machines are created and run

In this example, the goal is to provision a Linux machine running in Windows. We will select Oracle's Virtualbox as hypervisor to create and manage our Linux VMs.

1a. Download "Centos DVD ISO" image from https://www.centos.org/download/ .
1b. Download Virtualbox for Windows Hosts from https://www.virtualbox.org/ For this exercise I am using version 5.1.10
2. Install Virtualbox on the windows machine. I am using windows 10.
3. Launch Virtualbox. You are presented with a console from which you can manage existing VMs or create a new VM. Click New button to create a new VM:

4. Give a name and select Redhat Linux (Centos in the list, but it is the community version fo Redhat Linux, so selecting Redhat is perfectly OK)

5. Memory allocation: depends on your host machine, select 6G as the minimum RAM setting

6. Storage allocation: for basic setup with Centos OS image, allocate 30G of host machine's hard disk.....



7. Upon hitting Create button, a new VM entry is created in the console list.

Let's continue setting up the new VM. Virtualbox provides you with many customization options. We will perform some basic ones below.

8. System: since there is no floppy dive here, disable boot from Floppy.

9. Display: give 32Mb video memory

10. Storage: Select the Centos7 image file we just downloaded for Optical Drive

11. Network: for demo and simple use cases, attach the network adapter to NAT and set the adapter type to be: Paravirtualized Network (virtio-net)

There are many options to config a VM's network setup. Refer to Virtualbox's official guidelines (https://www.virtualbox.org/manual/ch06.html).  I will explore in another post.
12. Done. Click on Start to set up the newly created VM.

Install Centos and Launch the VM
13. Complete the general setups (you may want to select the Gnu Desktop as well).

14. Create a root password and a new user which you can log on after the VM is ready.

15. Reboot and your VM is ready.

Update operating system with latest Centos updates
16. log in as the user you just created and then change to root: su -
17. yum -y update
      (if you see an error message like: Cannot find a valid baseurl for repo: base/7/x86_64
try to ping a web site, if unsuccessful, issue command dhclient should solve it. If not, as root, edit this file: 
>vi /etc/sysconfig/network-scripts/ifcfg-eth0
assure NM_CONTROLLED=no save it and issue
>ifdown eth0

>ifup eth0
 

It should take care of the issue.)
18. Install guest additions utilities packages: yum install kernel-devel
19. Install gcc compiler: yum install gcc* compiler
20. Now the new Centos 7 VM is ready to use.

No comments:

Post a Comment