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:
- Enable Nesting: Configure the host KVM module to support hardware-assisted nesting.
- Cloud Image Prep: Download and customize a sparse Ubuntu Cloud Image.
- CLI Deployment: Use
virt-installwith "Host-Passthrough" to launch the guest. - 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.
- Check Current Status:
(Note: If on AMD, usecat /sys/module/kvm_intel/parameters/nestedkvm_amd). If it returns N, nesting is disabled. - Enable Nesting Temporarily:
sudo modprobe -r kvm_intel sudo modprobe kvm_intel nested=1 - Verify:
It should now return Y.cat /sys/module/kvm_intel/parameters/nested
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.
- Download the Image:
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img - 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
- Log into your new VM via
virsh console Cloud-Node-01or SSH. - Install the verification tool:
sudo apt update && sudo apt install cpu-checker -y - Run the KVM check:
kvm-ok - Success Output:
INFO: /dev/kvm exists. KVM acceleration can be used.
Lab Checkpoint
- Host KVM module has
nested=Y. - Cloud image has been resized for storage elasticity.
- VM deployed using
host-passthrough. -
kvm-okreturns success inside the guest.
Instructor Signature: ___ Date: ___