← Back to Course Index

Week 7 Lab 2: Project Cloud-Node (Advanced KVM & Nested Virtualization)

Module: Operating Systems 3 (Virtualisation & Cloud Technologies)

Estimated Time: 60 Minutes
Lab Type: Advanced Infrastructure / CLI


Lab Overview

In Lab 1, we used VirtualBox (the "Easy Way") to import a cloud environment. In this lab, you will act as a Cloud Infrastructure Engineer for "Project Blue-Stack." You will use KVM/libvirt (the "Professional Way") to enable Nested Virtualization and deploy a cloud-ready Ubuntu node from the command line.

Definition: Nested Virtualization allows you to run a hypervisor (like KVM or Proxmox) inside another virtual machine. This is how major cloud providers (AWS, Azure) allow you to run your own lab environments in the cloud.

Objectives:

  1. Enable Nesting: Configure the host KVM module to support hardware-assisted nesting.
  2. Cloud Image Prep: Download and customize a sparse Ubuntu Cloud Image.
  3. CLI Deployment: Use virt-install with "Host-Passthrough" to launch the guest.
  4. Verification: Confirm that the Guest VM is capable of running its own virtual machines.

Part 1: Enabling Nested Virtualization on the Host

Before launching a guest that can virtualize, we must tell the Linux kernel and KVM module to pass through the hardware acceleration features.

  1. Check Current Status:
    cat /sys/module/kvm_intel/parameters/nested
    (Note: If on AMD, use kvm_amd). If it returns N, nesting is disabled.
  2. Enable Nesting Temporarily:
    sudo modprobe -r kvm_intel
    sudo modprobe kvm_intel nested=1
  3. Verify:
    cat /sys/module/kvm_intel/parameters/nested
    It should now return Y.

Part 2: Preparing the Cloud Image

Cloud providers don't use ISOs; they use specialized Cloud Images (often .qcow2) that are pre-installed and ready to boot.

  1. Download the Image:
    wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
  2. Create a Sparse Working Copy (The "Golden Master" concept):
    cp jammy-server-cloudimg-amd64.img cloud-node-01.qcow2
    qemu-img resize cloud-node-01.qcow2 +10G

Part 3: Deploying the Cloud Node via CLI

We will use virt-install to launch the VM. The critical flag is --cpu host-passthrough.

sudo virt-install \
  --name Cloud-Node-01 \
  --memory 4096 \
  --vcpus 2 \
  --disk path=./cloud-node-01.qcow2,format=qcow2 \
  --import \
  --os-variant ubuntu22.04 \
  --network bridge=virbr0 \
  --cpu host-passthrough \
  --graphics none \
  --noautoconsole

Why host-passthrough? This passes the physical CPU's "VMX" (Virtual Machine Extensions) into the guest.


Part 4: The Nested Verification Test

  1. Log into your new VM via virsh console Cloud-Node-01 or SSH.
  2. Install the verification tool:
    sudo apt update && sudo apt install cpu-checker -y
  3. Run the KVM check:
    kvm-ok
  4. Success Output: INFO: /dev/kvm exists. KVM acceleration can be used.

Lab Checkpoint


Instructor Signature: ___ Date: ___

← Back to Course Index