How to install and run a Virtual Machine on your local machine (pc/laptop).

How to install and run a Virtual Machine on your local machine (pc/laptop).

Introduction

What is a Virtual Machine?

A virtual machine (VM) is a virtual environment that functions as a virtual computer system with its own CPU, memory, network interface, and storage, created on a physical hardware system (located off- or on-premises). Software called a hypervisor separates the machine’s resources from the hardware and provisions them appropriately so they can be used by the VM.

The physical machines, equipped with a hypervisor such as Kernel-based Virtual Machine (KVM), is called the host machine, host computer, host operating system, or simply host. The many VMs that use its resources are guest machines, guest computers, guest operating systems, or simply guests. The hypervisor treats compute resources—like CPU, memory, and storage—as a pool of resources that can easily be relocated between existing guests or to new virtual machines.

VMs allow multiple different operating systems to run simultaneously on a single computer—like a Linux® distro on a MacOS laptop. Each operating system runs in the same way an operating system or application normally would on the host hardware, so the end user experience emulated within the VM is nearly identical to a real-time operating system experience running on a physical machine.

Since, we have a DevOps centric approach, we will discuss key points that makes VMs a crucial part of DevOps.

Why do we need Virtual Machines?

Most operating system and application deployments only use a small amount of the physical resources available when deployed to bare metal. By virtualizing your servers, you can place many virtual servers onto each physical server to improve hardware utilization.

This keeps you from needing to purchase additional physical resources, like hard drives or hard disks, as well as reducing the need for power, space, and cooling in the datacenter. VMs provide additional disaster recovery options by enabling failover and redundancy that could previously only be achieved through additional hardware.

Because VMs are isolated, they are a good option for testing new applications or setting up a production environment. You can also run a single purpose VM to support a specific process.

What are the Software that can help you create these Virtual Machines?

It's called as virtualization software or hypervisors. You might have heard about VMWare ESX servers or Windows Hyper-V servers that can create virtual machines, These are known as type 1 hypervisors.

Type 1 hypervisors:

They are installed directly on bare metal such as laptop or server, and the VMs are created on top of that. These are are mainly used in enterprises and production environment due to it's high resource requirements, we can create and run a large number of VMs on them, but it needs to be configured directly on laptop, and they are expensive as well.

For our purpose, that is DevOps centric, there are another solutions that better suits our needs and are easy to manage, For this we use another kind of hypervisor knows as type 2 hypervisor.

Type 2 hypervisor:

They are hypervisor that runs on existing operating system(OS). Example- Oracle VirtualBox, and VMWare workstation. These allow you to get started.

In these type of hypervisors, Host OS is referred to the main OS on our laptop, while guest OS is refer to the VMs that we create on the hypervisor on the OS.

Features of Oracle VirtualBox and VMWare workstation:

Features of Oracle VirtualBox and VMWare workstation are give below:

Requirements:

The hardware requirements for installing a type 2 hypervisor is given below:

You can be really smart in managing resources by allocating VMs with only sufficient resources that it requires, and using lightweight OS images instead of full blown OS images.

We'll be installing Oracle VirtualBox considering the cost benefits and features.

Installation:

To install the Oracle VirtualBox run the given URL on the browser of your choice.

https://www.virtualbox.org/wiki/Downloads

We are installing it on windows host you can install it according to your need.

Once it's installed, open the VirtualBox tool by starting the executable. It should be available in your application section or in your programs section on windows.

To create a Virtual Machine, hit the new button at the top.

Then give your VM a name and specify the location, the VM itself and the disk of the VM are stored as file on the host.

Set the type of the OS to the Linux. Since. the VM we are creating here is CentOS machine, I have to choose RedHat 64-bit as my OS version, because CentOS is a community fork of the RedHat enterprises Linux. It has a lot more advance packages and built-in features. From the list of options available, we select RedHat.

Now, we'll assign the memory:

This step may differ between different OS, if your OS is lightweight you may assign small amount of memory. 1GB is usually good.

Next we create hard disk.

Here you can create and attach a new hard disk to the VM, but remember a new disk means it's empty so it does not have an OS on it, creating new VM is just like buying new pc/laptop. Just like we need to install an OS on laptop you need to install an OS on VM.

What if , disk that you attach already has OS on it, a pre configured, pre built OS? Is it possible?

In short, yes it is, there are a large numbers of such pre configured disk or images as it is called available on the internet and one of such website is OSboxes.org. They have a list of images for all kind of OS Like, Ubuntu, Debian, CentOS, Fedora, Etc.

Once an image is downloaded, use that as an existing disk file and create the VM.

Now we'll start the VM.

Start the VM by right clicking start and selecting normal start.

Congrats, you just ran a VM on your local machine.

Conclusion:

Thank you for reading my blog! I hope you found it informative and valuable. By following the steps outlined in this beginner's guide, you can install and run a virtual machine on your laptop/pc and enjoy the benefits of a VM.

If you learned something new, please consider sharing it with others on Twitter and tag me in your post so I can see it too.

Let's spread knowledge and help each other grow! ❤️