Virtualization

"Using virtualization, we can create a lab of multiple computers using a single computer."

The Pre-Virtualization Era

Before virtualization became widespread, organizations faced significant challenges in managing their computing resources:

  • Each server typically ran a single application or service

  • Inefficient resource utilization was common

  • Hardware costs were high

  • Power consumption was increased

  • Management and maintenance were complex

This approach, while ensuring isolation between different activities, often resulted in overestimated resource allocation and expensive infrastructure.

What is Virtualization?

Virtualization is a technology that allows you to create multiple simulated environments or dedicated resources from a single physical hardware system. It enables better utilization of hardware resources and provides flexibility in managing computing environments.

Key Components

  1. Host OS: The operating system of the physical machine.

  2. Guest OS: The operating system running inside a virtual machine.

  3. Hypervisor: Software that creates and manages virtual machines.

  4. Snapshot: A point-in-time image of a virtual machine's state.

Types of Hypervisors

  1. Type 1 (Bare-metal): Runs directly on the hardware.

  2. Type 2 (Hosted): Runs on top of a host operating system.

Setting Up Virtualization Manually in Windows

Prerequisites

  1. Enable VT-x in BIOS

  2. Disable default hypervisors in Windows services (e.g., Docker Desktop, Windows Hyper-V)

Steps

  1. Install Oracle VirtualBox

  2. Click "New" to create a virtual machine

  3. Select the appropriate Linux distribution (Red Hat for CentOS, Ubuntu 64-bit for Ubuntu)

  4. Allocate resources (storage, RAM, CPU)

  5. Download the ISO image (CentOS Stream 9 or Ubuntu Server)

  6. Configure VM settings:

    • Go to Settings > Storage

    • Add the ISO file

    • Set up network adapters (enable second one as bridged adapter)

Network Adapters Explained

Virtual machines can use different types of network adapters:

  1. NAT: Allows VM to access the internet through the host's network connection.

  2. Bridged: Connects VM directly to the physical network, assigning it a unique IP address.

  3. Host-only: Creates a private network between the host and VMs.

VM Setup

  1. Boot the VM

  2. Set up installation destination and partition scheme

  3. Enable SSH

  4. Set hostname and password

  5. Complete installation

  6. Shut down VM and remove ISO file to prevent reinstallation on next boot

SSH into Virtual Machine

SSH (Secure Shell) is a protocol for securely accessing remote systems. To SSH into your VM:

  1. Open a terminal or command prompt on your host machine

  2. Use the command: ssh username@vm_ip_address

You need a terminal for SSH because it's a text-based protocol. Direct connection isn't possible as the VM is a separate system with its own network identity.

Understanding Bash

Bash (Bourne Again Shell) is a command-line interface and scripting language commonly used in Unix-based systems, including most Linux distributions. Here's why Bash is important:

  1. Command Execution: Bash allows us to run commands and programs on the system.

  2. Scripting: We can write Bash scripts to automate tasks and manage our virtual environments.

  3. System Interaction: Bash provides a way to interact with the operating system, manage files, and control processes.

The Role of SSH

SSH (Secure Shell) is a network protocol that provides a secure way to access a remote system. Key points about SSH:

  1. Secure Communication: SSH encrypts all traffic between the client and server.

  2. Remote Access: It allows us to log into and execute commands on a remote system as if we were sitting at its console.

  3. Protocol, Not a Program: SSH is a protocol, not a program itself. We need programs that implement the SSH protocol to use it.

Why We Need Bash (or a Similar Shell) for SSH

When we SSH into a virtual machine:

  1. Command-Line Interface: SSH provides a text-based connection to the remote system. We need a shell like Bash to interpret our commands and interact with the system.

  2. Program Execution: Bash allows us to run the SSH client program (usually ssh on Unix-like systems) to initiate the connection.

  3. Remote Shell: Once connected via SSH, we're typically dropped into a Bash shell (or whatever the default shell is) on the remote system.

Automating VM Creation with Vagrant

Vagrant is an open-source tool for building and managing virtual machine environments. It simplifies the VM creation process and solves problems like:

  1. Inconsistent development environments

  2. Time-consuming setup processes

  3. Difficulty in sharing exact configurations

Vagrant Architecture

Vagrant uses a Vagrantfile to define VM configurations. When you run vagrant up, it:

  1. Downloads the specified box (OS image) from the cloud

  2. Creates a VM using the local hypervisor

  3. Applies the configurations specified in the Vagrantfile

    Vagrant for Virtual Machines. Introduction: | by Ghazanfar Ali | Medium

Basic Vagrant Commands

  • vagrant init: Initializes a new Vagrant environment.

  • vagrant up: Starts and provisions the VM.

  • vagrant ssh: Connects to the VM via SSH.

  • vagrant halt: Stops the VM.

  • vagrant destroy: Removes the VM.

  • vagrant status: Shows the status of the VM in the current directory.

  • vagrant global-status: Displays the status of all Vagrant environments on the system.

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "eurolinux-vagrant/centos-stream-9"
  # or "ubuntu/jammy64" for Ubuntu

  config.vm.network "private_network", type: "dhcp"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
    vb.cpus = 2
  end
end

This Vagrantfile sets up a CentOS Stream 9 VM with 1GB of RAM and 2 CPUs.

Conclusion

Virtualization has revolutionized how we manage computing resources, offering flexibility, efficiency, and cost savings. Whether you're setting up VMs manually or automating with tools like Vagrant, understanding these concepts is crucial for modern IT professionals.

By leveraging virtualization, organizations can optimize their infrastructure, reduce costs, and increase agility in their IT operations. As technology continues to evolve, virtualization remains a cornerstone of modern computing environments, enabling everything from local development environments to large-scale cloud deployments.

1
Subscribe to my newsletter

Read articles from Vedant Singh Chauhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vedant Singh Chauhan
Vedant Singh Chauhan