Cloud Computing (2): Virtualization Technology Deep Dive
Chen Kai BOSS

Virtualization technology forms the bedrock of modern cloud computing. Without it, the elastic, scalable, and cost-effective infrastructure we take for granted today would be impossible. This article provides a comprehensive exploration of virtualization technologies, from fundamental concepts to hands-on implementation, performance optimization, and real-world case studies.

Understanding Virtualization Fundamentals

Virtualization is the process of creating a virtual representation of something — hardware, storage, networks, or operating systems — rather than the actual physical entity. At its core, virtualization allows multiple virtual machines (VMs) or containers to run on a single physical machine, each appearing to have its own dedicated resources.

Historical Evolution

The concept of virtualization dates back to the 1960s with IBM's CP/CMS system, which allowed multiple users to share mainframe resources. However, virtualization as we know it today emerged in the early 2000s with the introduction of x86 virtualization solutions.

Key Milestones:

  • 1960s-1970s: IBM mainframe virtualization (CP/CMS, later VM/370)
  • 1999: VMware introduces first x86 virtualization product
  • 2003: Xen hypervisor released as open-source
  • 2005: Intel VT-x and AMD-V hardware-assisted virtualization
  • 2006: KVM integrated into Linux kernel
  • 2013: Docker revolutionizes containerization
  • 2015: Kubernetes emerges for container orchestration

Core Concepts

Hypervisor (Virtual Machine Monitor)

The hypervisor is the software layer that enables virtualization. It sits between the hardware and operating systems, managing resource allocation and ensuring isolation between VMs.

Virtual Machine (VM)

A VM is a software emulation of a physical computer. Each VM runs its own operating system and applications, completely isolated from other VMs on the same host.

Guest OS vs Host OS

  • Host OS: The operating system running directly on physical hardware
  • Guest OS: The operating system running inside a virtual machine

Resource Overcommitment

Virtualization allows allocating more virtual resources than physically available (e.g., 200GB RAM across VMs when only 128GB physical RAM exists). This works because not all VMs use peak resources simultaneously.

Classification of Virtualization Technologies

Virtualization technologies can be classified along multiple dimensions. Understanding these classifications helps in selecting the right approach for specific use cases.

Full Virtualization

Full virtualization provides complete simulation of underlying hardware, allowing unmodified guest operating systems to run. The hypervisor intercepts and translates all hardware calls.

Characteristics:

  • Guest OS runs without modification
  • Complete hardware abstraction
  • Higher overhead due to binary translation
  • Best compatibility with any OS

Example: VMware ESXi, Microsoft Hyper-V

Para-virtualization

In para-virtualization, the guest OS is modified to be aware it's running in a virtualized environment. The guest communicates directly with the hypervisor through hypercalls, reducing overhead.

Characteristics:

  • Guest OS must be modified
  • Lower overhead than full virtualization
  • Better performance
  • Limited OS compatibility

Example: Xen (in PV mode), early VMware experiments

Hardware-Assisted Virtualization

Modern CPUs include virtualization extensions (Intel VT-x, AMD-V) that allow the hypervisor to run guest OS code directly on the CPU, with hardware handling privilege level transitions.

Characteristics:

  • Uses CPU virtualization extensions
  • Near-native performance
  • No binary translation needed
  • Requires compatible CPU

Example: KVM, VMware ESXi (with VT-x/AMD-V), Hyper-V

Operating System-Level Virtualization (Containers)

Containers share the host OS kernel while providing isolated user spaces. This is lighter than VMs but less isolated.

Characteristics:

  • Shared kernel with host
  • Minimal overhead
  • Fast startup times
  • Less isolation than VMs

Example: Docker, LXC, OpenVZ

Comparison Matrix

Feature Full Virtualization Para-virtualization Hardware-Assisted Containers
Guest OS Modification Not required Required Not required Not applicable
Performance Overhead High Medium Low Very Low
Isolation Level Complete Complete Complete Process-level
Startup Time Slow (minutes) Slow (minutes) Slow (minutes) Fast (seconds)
Resource Efficiency Low Medium Medium High
OS Compatibility Excellent Limited Excellent Limited (Linux/Windows)
Use Case Legacy apps, mixed OS High-performance Linux General purpose Microservices, DevOps

Server Virtualization: Hands-On Implementation

Server virtualization is the most common form of virtualization, allowing multiple server instances to run on a single physical server. explore the major hypervisor platforms.

VMware vSphere/ESXi

VMware ESXi is a Type 1 (bare-metal) hypervisor that runs directly on server hardware without requiring a host operating system.

Installation and Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ESXi is typically installed via ISO on bare metal
# Once installed, access via vSphere Client or Web UI

# SSH into ESXi host (if enabled)
ssh root@esxi-host-ip

# View VM list
vim-cmd vmsvc/getallvms

# Get VM power state
vim-cmd vmsvc/power.getstate <vmid>

# Start a VM
vim-cmd vmsvc/power.on <vmid>

# Stop a VM
vim-cmd vmsvc/power.shutdown <vmid>

VM Configuration File for Production Performance

VMware VMX Configuration: Enterprise-Grade Performance Tuning

VMware virtual machines are defined by .vmx configuration files that control every aspect of VM hardware. While the default configuration works for most use cases, production environments with high I/O demands (databases, web servers, big data workloads) require careful tuning to achieve near-native performance. This section provides a comprehensive guide to optimizing VMX settings for maximum performance.

Problem Background: Default VMware configurations use emulated hardware (LSI Logic SCSI, E1000 network adapter) that suffers from significant performance penalties. For example: - LSI Logic SCSI: Provides broad compatibility but limits IOPS to ~80,000-100,000 (modern NVMe SSDs can deliver 500,000+ IOPS) - E1000 Network: Limited to ~1Gbps throughput even on 10Gbps networks - vCPU Topology: Incorrect CPU topology (sockets vs cores) causes NUMA penalties, reducing performance by 20-40% These limitations make default configurations unsuitable for production workloads that demand high performance.

Solution Approach: 1. PVSCSI Controller: Replace LSI Logic with VMware Paravirtual SCSI, reducing CPU overhead by 30-50% and increasing IOPS by 2-3x 2. VMXNET3 Network: Replace E1000 with VMXNET3 paravirtualized network adapter, achieving near-line-rate performance (9.5Gbps on 10Gbps links) 3. CPU Topology Optimization: Configure CPU topology to match physical CPU layout (sockets, cores per socket) to minimize NUMA memory access latency 4. Virtual Hardware Version: Use the latest hardware version (19 for vSphere 7.0+) to access new features and performance improvements 5. Memory Reservation: Reserve all allocated memory to eliminate swapping and memory ballooning overhead

Design Considerations: - PVSCSI/VMXNET3 require VMware Tools: These paravirtualized drivers are only available after installing VMware Tools in the guest OS. During OS installation, you must use LSI Logic and E1000, then switch to PVSCSI/VMXNET3 after installation. - Performance vs Compatibility: PVSCSI and VMXNET3 provide best performance but require recent guest OS versions (Linux 2.6.32+, Windows Server 2008+). Legacy OS may require emulated drivers. - NUMA Awareness: For VMs with > 8 vCPUs, NUMA topology becomes critical. Incorrect configuration causes remote NUMA node access, increasing memory latency by 2-3x. - CPU Overcommitment: Production databases should avoid CPU overcommitment (keep vCPU:pCPU ratio < 2:1). Overcommitment causes CPU ready time, degrading performance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# ========== Basic VM Information ==========
# Character encoding for VMX file (UTF-8 recommended for international characters)
.encoding = "UTF-8"

# VM display name (shown in vCenter/vSphere Client)
displayName = "Ubuntu-Server-22.04"

# Guest OS type (determines default hardware compatibility and drivers)
# Options: ubuntu-64, centos-64, windows9Server64Guest, rhel8-64, etc.
# Choosing correct guestOS ensures optimal default settings
guestOS = "ubuntu-64"

# Virtual hardware version (19 = vSphere 7.0 Update 2+)
# Higher versions unlock new features: NVMe, Precision Time, improved vMotion
# Note: Upgrading hardware version requires VM power-off and may break snapshots
# Recommendation: Use latest version for new VMs, keep stable version for existing VMs
virtualHW.version = "19"

# ========== CPU Configuration ==========
# Number of virtual CPUs (vCPUs) assigned to this VM
# Rule of thumb: For production, keep vCPU:pCPU ratio < 2:1 to avoid CPU contention
# Over-allocation causes "CPU Ready" time, where vCPU waits for physical CPU
numvcpus = "4"

# Cores per socket (CPU topology)
# Formula: numvcpus = sockets × cores per socket × threads per core
# Example: 4 vCPUs = 2 sockets × 2 cores × 1 thread
# Why it matters: OS licensing (SQL Server, Windows Server charge per socket)
# NUMA impact: Incorrect topology causes remote NUMA access (2-3x latency penalty)
# Best practice: Match physical CPU topology when possible
# - Single-socket systems: cpuid.coresPerSocket = numvcpus (e.g., 1 socket × 4 cores)
# - Multi-socket systems: Balance cores across sockets (e.g., 2 sockets × 2 cores)
cpuid.coresPerSocket = "2"

# ========== Memory Configuration ==========
# VM memory size in MB (8192 MB = 8 GB)
# Note: Memory is allocated from host RAM, ensure host has sufficient memory
# For production: Reserve all allocated memory to prevent swapping/ballooning
memory = "8192"

# Memory reservation (MB) - guarantees this amount of physical RAM
# Setting reservation = memory eliminates swapping and ballooning overhead
# Trade-off: Prevents memory overcommitment, reduces VM density on host
# Recommendation: Reserve memory for latency-sensitive workloads (databases, real-time systems)
# sched.mem.min = "8192"

# ========== Storage Configuration ==========
# Enable SCSI controller 0
# SCSI controllers manage virtual disks attached to the VM
scsi0.present = "TRUE"

# SCSI controller type: pvscsi (VMware Paravirtual SCSI)
# Performance comparison:
# - lsilogic (default): ~80,000 IOPS, high CPU overhead, broad compatibility
# - pvscsi: ~300,000+ IOPS, 30-50% lower CPU overhead, requires VMware Tools
# Why pvscsi wins: Bypasses hardware emulation, uses optimized driver path
# Limitation: Not available during OS installation (use lsilogic first, then change)
# Requirement: VMware Tools must be installed for pvscsi driver
# Use case: All production VMs, especially databases and high I/O workloads
scsi0.virtualDev = "pvscsi"

# Virtual disk 0 on SCSI controller 0
# This is the primary boot disk for the VM
scsi0:0.fileName = "Ubuntu-Server-22.04.vmdk"
scsi0:0.present = "TRUE"

# Disk mode (persistent = changes are immediately written to disk)
# Options: persistent, nonpersistent (discards changes on power-off), independent
# Production systems always use persistent mode
# scsi0:0.mode = "persistent"

# ========== Network Configuration ==========
# Enable network adapter 0
ethernet0.present = "TRUE"

# Network adapter type: vmxnet3 (VMware Paravirtualized NIC)
# Performance comparison:
# - e1000 (default): ~1 Gbps, high CPU overhead, broad compatibility
# - vmxnet3: ~9.5 Gbps (on 10 Gbps link), 70-80% lower CPU overhead
# Why vmxnet3 wins: Paravirtualized driver eliminates hardware emulation overhead
# Requirement: VMware Tools must be installed for vmxnet3 driver
# Limitation: Not available during OS installation (use e1000 first, then change)
# Use case: All production VMs, especially web servers and network-intensive workloads
ethernet0.virtualDev = "vmxnet3"

# Port group/network name (must match vSwitch port group in vSphere)
# "VM Network" is the default standard switch port group
# For production: Use distributed vSwitch (dvSwitch) for advanced features
ethernet0.networkName = "VM Network"

# MAC address assignment (generated = vSphere assigns unique MAC automatically)
# Options: generated, static (manually specified), vpx (vCenter manages)
# Recommendation: Use generated for most cases, static only for specific licensing
# ethernet0.addressType = "generated"

# ========== Advanced Performance Tuning ==========
# Disable memory page sharing (transparent page sharing)
# TPS shares identical memory pages across VMs to save RAM
# Security concern: Potential side-channel attacks (disabled by default in vSphere 6.0+)
# Performance: Disabling TPS may reduce VM density but improves security
# sched.mem.pshare.enable = "FALSE"

# Enable hypervisor-assisted guest memory swapping (vmem swapping)
# Allows hypervisor to swap VM memory to disk when host memory is overcommitted
# Recommendation: Disable for production (use memory reservation instead)
# sched.swap.derivedName = "/vmfs/volumes/datastore1/Ubuntu-Server-22.04/Ubuntu-Server-22.04.vswp"

# CPU affinity (pin vCPUs to specific physical CPUs)
# Use only for special cases (NUMA optimization, CPU isolation)
# Warning: Reduces vMotion flexibility and load balancing
# sched.cpu.affinity = "0,1,2,3"

# ========== Monitoring and Logging ==========
# Enable VMware Tools heartbeat monitoring
# Allows vSphere to detect guest OS health and automate recovery
# tools.syncTime = "TRUE"

# Disable logging (reduces disk I/O overhead)
# For production: Enable logging only for troubleshooting
# logging = "FALSE"

In-Depth Analysis:

Key Points Explained:

  1. PVSCSI vs LSI Logic Performance: The PVSCSI controller is VMware's paravirtualized SCSI adapter that dramatically outperforms the default LSI Logic controller:
    • IOPS: PVSCSI delivers 300,000+ IOPS vs LSI Logic's 80,000-100,000 IOPS (3-4x improvement)
    • CPU Overhead: PVSCSI reduces CPU overhead by 30-50% compared to LSI Logic, freeing up CPU for application workloads
    • Latency: PVSCSI reduces average I/O latency from ~10ms to ~2-3ms (emulation overhead eliminated)
    • How it works: PVSCSI bypasses hardware emulation by using a paravirtualized driver that communicates directly with the hypervisor, eliminating the binary translation overhead of full virtualization.
    • Limitation: PVSCSI requires VMware Tools to be installed in the guest OS. During OS installation, you must use LSI Logic or BusLogic, then change to PVSCSI after installation.
  2. VMXNET3 Network Performance: VMXNET3 is VMware's paravirtualized network adapter that eliminates the performance bottleneck of emulated NICs:
    • Throughput: VMXNET3 achieves 9.5Gbps on 10Gbps links vs E1000's ~1Gbps (10x improvement)
    • CPU Overhead: VMXNET3 reduces CPU overhead by 70-80% compared to E1000, crucial for network-intensive workloads
    • Latency: VMXNET3 reduces network latency from ~200μ s to ~50μ s
    • Features: Supports jumbo frames (MTU 9000), TCP/UDP checksum offload, TSO/LRO, multiple TX/RX queues
    • Limitation: Like PVSCSI, VMXNET3 requires VMware Tools. During OS installation, use E1000 or E1000E, then switch to VMXNET3.
  3. CPU Topology and NUMA Optimization: CPU topology (sockets, cores per socket) significantly impacts performance, especially for VMs with > 8 vCPUs:
    • NUMA Architecture: Modern servers have NUMA (Non-Uniform Memory Access) architecture where each CPU socket has local memory. Accessing remote memory (on another socket) is 2-3x slower.
    • Topology Impact: If you configure a 16-vCPU VM as 1 socket × 16 cores, but the physical host has 2 sockets × 8 cores, the VM will span NUMA nodes, causing remote memory access and performance degradation.
    • Best Practice: Match the VM's CPU topology to the physical host's topology. For a 2-socket host with 8 cores per socket, configure VMs as multiples of the physical topology (e.g., 4 vCPUs = 1 socket × 4 cores, 16 vCPUs = 2 sockets × 8 cores).
    • Checking NUMA: Use esxtop (press 'm' for memory, then 'n' for NUMA) to check NUMA statistics. High "Remote Memory %" indicates NUMA misalignment.
  4. Virtual Hardware Version: The virtualHW.version parameter determines which features and performance enhancements are available:
    • Version 19 (vSphere 7.0 U2+): NVMe storage, Precision Time Protocol, improved vMotion
    • Version 14 (vSphere 6.5/6.7): Up to 128 vCPUs, 6TB RAM
    • Version 10 (vSphere 5.5/6.0): Up to 64 vCPUs, 4TB RAM
    • Upgrade Consideration: Upgrading hardware version requires VM power-off and may invalidate snapshots. Test thoroughly before upgrading production VMs.

Design Trade-offs:

Configuration Option Advantages Disadvantages Use Case
SCSI Controller LSI Logic Broad compatibility, no VMware Tools needed Low IOPS (~80K), high CPU overhead OS installation, legacy systems
PVSCSI High IOPS (300K+), low CPU overhead Requires VMware Tools, not for OS install Production VMs, databases
Network Adapter E1000 Universal compatibility Limited to ~1Gbps, high CPU overhead OS installation, legacy systems
VMXNET3 Near line-rate (9.5Gbps), low CPU overhead Requires VMware Tools Production VMs, web servers
CPU Topology Single Socket Simplifies licensing (per-socket) May cause NUMA penalties Small VMs (≤ 8 vCPU)
Multi-Socket NUMA-aware, better scalability Higher licensing costs Large VMs (> 8 vCPU)
Memory Reservation No Reservation Allows memory overcommitment Risk of swapping/ballooning Non-critical VMs
Full Reservation Guaranteed performance Reduces VM density Databases, latency-sensitive apps

Common Issues and Solutions:

Issue Cause Solution
Poor disk performance after changing to PVSCSI VMware Tools not installed or outdated Install/update VMware Tools, verify driver is loaded (lsmod | grep vmw_pvscsi)
Network drops to 1Gbps after changing to VMXNET3 VMware Tools missing vmxnet3 driver Install VMware Tools, verify driver (ethtool -i eth0)
VM fails to boot after changing to PVSCSI OS doesn't have PVSCSI driver in initramfs Boot from rescue disk, rebuild initramfs to include PVSCSI driver
High CPU Ready time (> 5%) vCPU overcommitment (too many vCPUs vs pCPUs) Reduce vCPU count or migrate VMs to less loaded host
Inconsistent performance NUMA misalignment (remote memory access) Adjust CPU topology to match physical host, enable NUMA affinity
VM cannot power on (hardware version too new) ESXi host version too old Downgrade VM hardware version or upgrade ESXi host
Poor performance despite PVSCSI/VMXNET3 Virtual hardware version too old (< 10) Upgrade VM hardware version (requires power-off)

Production Best Practices:

  1. Standardize Configuration Templates: Create VM templates with optimized settings (PVSCSI, VMXNET3, correct hardware version) to ensure consistency across your environment. Use vSphere Content Library to share templates across data centers.

  2. Post-Deployment Checklist:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # Verify PVSCSI driver is loaded (Linux)
    lsmod | grep vmw_pvscsi

    # Verify VMXNET3 driver is loaded
    ethtool -i eth0 # Should show "vmxnet3"

    # Check for high CPU Ready time (vSphere)
    # CPU Ready > 5% indicates CPU contention
    esxtop # Press 'c' for CPU view, check '%RDY' column

    # Verify NUMA alignment
    esxtop # Press 'm', then 'n' for NUMA stats
    # Look for low "Remote Memory %" (< 10%)

  3. Monitoring:

    • Disk IOPS: Monitor esxtop (press 'd' for disk view) to verify PVSCSI delivers expected IOPS (> 100K for NVMe)
    • Network Throughput: Use iperf3 to verify VMXNET3 achieves near line-rate (9Gbps+ on 10Gbps)
    • CPU Ready Time: Alert if CPU Ready > 5% (indicates CPU overcommitment)
    • Memory Ballooning: Alert if ballooning > 100MB (indicates memory overcommitment)
  4. Upgrade Strategy:

    • Test hardware version upgrades in dev/test environment first
    • Schedule upgrades during maintenance windows (requires VM reboot)
    • Take VM snapshot before upgrading (allows rollback)
    • Verify application functionality after upgrade
  5. Security Considerations:

    • Disable TPS (Transparent Page Sharing) to prevent side-channel attacks: sched.mem.pshare.enable = "FALSE"
    • Enable Secure Boot for VMs running trusted operating systems (requires hardware version 13+)
    • Use encrypted vMotion for VMs with sensitive data
    • Regularly update VMware Tools to patch vulnerabilities

Best Practices:

  • Use VMXNET3 network adapters for better performance
  • Enable CPU hot-add/hot-remove for flexibility
  • Configure memory reservations for critical VMs
  • Use thin provisioning for storage efficiency
  • Enable vMotion for live migration capabilities

KVM (Kernel-based Virtual Machine)

KVM is a Linux kernel module that turns Linux into a hypervisor. It's open-source and widely used in cloud environments.

Installation on Ubuntu/Debian

1
2
3
4
5
6
7
8
9
10
# Install KVM and management tools
sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

# Add user to libvirt group
sudo usermod -aG libvirt$USER
sudo usermod -aG kvm$USER

# Verify installation
virsh list --all

Creating a VM with virt-install

1
2
3
4
5
6
7
8
9
10
11
12
13
# Create a new VM
virt-install \
--name ubuntu-server \
--ram 4096 \
--vcpus 4 \
--disk path=/var/lib/libvirt/images/ubuntu-server.qcow2,size=50 \
--os-type linux \
--os-variant ubuntu22.04 \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://archive.ubuntu.com/ubuntu/dists/jammy/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'

VM Configuration with virsh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Edit VM configuration
virsh edit ubuntu-server

# Start VM
virsh start ubuntu-server

# Shutdown VM gracefully
virsh shutdown ubuntu-server

# Force stop VM
virsh destroy ubuntu-server

# View VM info
virsh dominfo ubuntu-server

# View VM XML configuration
virsh dumpxml ubuntu-server

Example libvirt XML Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<domain type='kvm'>
<name>ubuntu-server</name>
<uuid>12345678-1234-1234-1234-123456789abc</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-q35-7.2'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='host-passthrough' check='none'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/ubuntu-server.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</disk>
<interface type='bridge'>
<mac address='52:54:00:12:34:56'/>
<source bridge='virbr0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<console type='pty'>
<target type='serial' port='0'/>
</console>
</devices>
</domain>

Performance Tuning

1
2
3
4
5
6
7
8
9
10
11
# Enable CPU pinning for better performance
virsh vcpupin ubuntu-server 0 0
virsh vcpupin ubuntu-server 1 1
virsh vcpupin ubuntu-server 2 2
virsh vcpupin ubuntu-server 3 3

# Set CPU governor to performance mode
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

# Enable huge pages for memory-intensive workloads
echo 1024 | sudo tee /proc/sys/vm/nr_hugepages

Xen Hypervisor

Xen is an open-source Type 1 hypervisor that supports both para-virtualization and hardware-assisted virtualization.

Installation on Debian/Ubuntu

1
2
3
4
5
6
7
8
9
# Install Xen hypervisor
sudo apt install xen-hypervisor-amd64 xen-tools

# Set Xen as default boot option
sudo dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
sudo update-grub

# Reboot into Xen
sudo reboot

Creating a PV (Para-Virtualized) Domain

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Create a PV domain configuration
sudo xen-create-image \
--hostname=debian-pv \
--memory=1024mb \
--vcpus=2 \
--lvm=vg0 \
--size=20gb \
--ip=192.168.1.100 \
--gateway=192.168.1.1 \
--netmask=255.255.255.0 \
--nameserver=8.8.8.8 \
--dist=bookworm \
--mirror=http://deb.debian.org/debian/

# Start the domain
sudo xl create /etc/xen/debian-pv.cfg

# List domains
sudo xl list

Xen Configuration File Example

1
2
3
4
5
6
7
8
9
10
11
12
13
# /etc/xen/debian-pv.cfg
kernel = "/usr/lib/xen-4.17/boot/vmlinuz-6.1.0-10-amd64"
ramdisk = "/usr/lib/xen-4.17/boot/initrd.img-6.1.0-10-amd64"
root = "/dev/xvda1 ro"
extra = "console=hvc0"
memory = 1024
vcpus = 2
name = "debian-pv"
disk = ['phy:/dev/vg0/debian-pv-disk,xvda,w']
vif = ['bridge=xenbr0']
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'

Microsoft Hyper-V

Hyper-V is Microsoft's native hypervisor, available in Windows Server and Windows 10/11 Pro.

PowerShell: Creating a VM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Enable Hyper-V feature
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

# Create a new VM
New-VM -Name "WindowsServer2022" `
-MemoryStartupBytes 4GB `
-Generation 2 `
-NewVHDPath "C:\VMs\WindowsServer2022.vhdx" `
-NewVHDSizeBytes 100GB `
-SwitchName "Default Switch"

# Configure VM
Set-VMProcessor -VMName "WindowsServer2022" -Count 4
Set-VMMemory -VMName "WindowsServer2022" -DynamicMemoryEnabled $true `
-MinimumBytes 2GB -MaximumBytes 8GB -StartupBytes 4GB

# Add network adapter
Add-VMNetworkAdapter -VMName "WindowsServer2022" -SwitchName "ExternalSwitch"

# Start VM
Start-VM -Name "WindowsServer2022"

Hyper-V Best Practices:

  • Use Generation 2 VMs for modern Windows/Linux guests
  • Enable Dynamic Memory for better resource utilization
  • Use VHDX format instead of VHD for better performance
  • Configure checkpoints (snapshots) before major changes
  • Use PowerShell DSC for automated VM configuration

Storage Virtualization Deep Dive

Storage virtualization abstracts physical storage resources and presents them as logical storage pools. This enables features like thin provisioning, snapshots, and storage migration.

Storage Virtualization Concepts

Storage Abstraction Layers

  1. Block-level: Virtualizes storage at the block level (SAN)
  2. File-level: Virtualizes at the file system level (NAS)
  3. Object-level: Virtualizes as objects with metadata (Object Storage)

Key Technologies:

  • LVM (Logical Volume Manager): Linux volume management
  • ZFS: Advanced file system with built-in virtualization
  • Storage Pools: Aggregated storage resources
  • Thin Provisioning: Allocate storage on-demand
  • Snapshots: Point-in-time copies
  • Cloning: Full copies of volumes

LVM Implementation

Setting Up LVM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Create physical volumes
sudo pvcreate /dev/sdb1 /dev/sdc1

# Create volume group
sudo vgcreate vg_storage /dev/sdb1 /dev/sdc1

# Create logical volume
sudo lvcreate -L 100G -n lv_data vg_storage

# Create file system
sudo mkfs.ext4 /dev/vg_storage/lv_data

# Mount
sudo mkdir /mnt/data
sudo mount /dev/vg_storage/lv_data /mnt/data

Advanced LVM Operations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Extend logical volume
sudo lvextend -L +50G /dev/vg_storage/lv_data
sudo resize2fs /dev/vg_storage/lv_data

# Create snapshot
sudo lvcreate -L 10G -s -n lv_data_snapshot /dev/vg_storage/lv_data

# Restore from snapshot
sudo umount /mnt/data
sudo lvconvert --merge /dev/vg_storage/lv_data_snapshot
sudo mount /dev/vg_storage/lv_data /mnt/data

# Remove snapshot
sudo lvremove /dev/vg_storage/lv_data_snapshot

ZFS Storage Pools

ZFS provides advanced storage virtualization with built-in features like snapshots, clones, compression, and deduplication.

Creating ZFS Pool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Create a simple pool
sudo zpool create tank /dev/sdb /dev/sdc

# Create pool with RAID-Z (similar to RAID-5)
sudo zpool create tank raidz /dev/sdb /dev/sdc /dev/sdd

# Create pool with mirror
sudo zpool create tank mirror /dev/sdb /dev/sdc

# List pools
zpool list

# Create ZFS file system
sudo zfs create tank/data
sudo zfs set mountpoint=/mnt/data tank/data

ZFS Snapshots and Clones

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Create snapshot
sudo zfs snapshot tank/data@backup-2024-12-31

# List snapshots
zfs list -t snapshot

# Clone snapshot
sudo zfs clone tank/data@backup-2024-12-31 tank/data-clone

# Rollback to snapshot
sudo zfs rollback tank/data@backup-2024-12-31

# Send/receive for backup
sudo zfs send tank/data@backup-2024-12-31 | sudo zfs receive backup-pool/data

ZFS Advanced Features

1
2
3
4
5
6
7
8
9
10
11
# Enable compression
sudo zfs set compression=lz4 tank/data

# Enable deduplication (requires significant RAM)
sudo zfs set dedup=on tank/data

# Set quota
sudo zfs set quota=100G tank/data

# Enable encryption
sudo zfs create -o encryption=aes-256-gcm -o keyformat=passphrase tank/encrypted

Storage Performance Optimization

I/O Scheduler Tuning

1
2
3
4
5
6
7
8
# Check current scheduler
cat /sys/block/sda/queue/scheduler

# Set deadline scheduler for better VM performance
echo deadline | sudo tee /sys/block/sda/queue/scheduler

# Make permanent in /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline"

QEMU/KVM Storage Optimization

1
2
3
4
5
6
7
8
9
# Use virtio-blk with cache=none for better performance
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source file='/var/lib/libvirt/images/vm.qcow2'/>
<target dev='vda' bus='virtio'/>
</disk>

# Use raw format instead of qcow2 for production
qemu-img convert -f qcow2 -O raw vm.qcow2 vm.raw

Network Virtualization

Network virtualization abstracts network resources, enabling multiple virtual networks to coexist on the same physical infrastructure.

VLAN (Virtual LAN)

VLANs segment a physical network into multiple logical networks, improving security and reducing broadcast traffic.

Linux VLAN Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Load VLAN module
sudo modprobe 8021q

# Create VLAN interface
sudo ip link add link eth0 name eth0.100 type vlan id 100

# Configure IP
sudo ip addr add 192.168.100.1/24 dev eth0.100
sudo ip link set dev eth0.100 up

# Persistent configuration in /etc/netplan/00-config.yaml
network:
version: 2
ethernets:
eth0:
dhcp4: false
vlans:
eth0.100:
id: 100
link: eth0
addresses:

- 192.168.100.1/24

VLAN on VMware ESXi

1
2
3
4
# In ESXi, VLANs are configured at vSwitch level
# Via vSphere Client: Network -> Virtual Switch -> Edit -> VLAN ID
# Or via esxcli:
esxcli network vswitch standard portgroup policy set -p "VM Network" -v 100

VXLAN (Virtual eXtensible LAN)

VXLAN extends Layer 2 networks over Layer 3 infrastructure, enabling network virtualization across data centers.

VXLAN Architecture

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
+------------------+     +------------------+
| VM 1 | | VM 2 |
| 10.1.1.10 | | 10.1.1.20 |
+------------------+ +------------------+
| |
+------------------+ +------------------+
| VTEP 1 | | VTEP 2 |
| VNI: 100 | | VNI: 100 |
+------------------+ +------------------+
| |
+-----------+--------------+
|
+----------------+
| Underlay |
| Network |
| (L3) |
+----------------+

Linux VXLAN Configuration

1
2
3
4
5
6
7
8
9
# Create VXLAN interface
sudo ip link add vxlan100 type vxlan id 100 dstport 4789 group 239.1.1.1 dev eth0

# Add IP address
sudo ip addr add 10.1.1.1/24 dev vxlan100
sudo ip link set vxlan100 up

# Add remote endpoint (point-to-point)
sudo ip link add vxlan100 type vxlan id 100 dstport 4789 remote 192.168.1.100 dev eth0

VXLAN with Linux Bridge

1
2
3
4
5
6
7
8
9
10
11
12
13
# Create bridge
sudo ip link add br-vxlan type bridge
sudo ip link set br-vxlan up

# Create VXLAN
sudo ip link add vxlan100 type vxlan id 100 dstport 4789 group 239.1.1.1 dev eth0

# Add VXLAN to bridge
sudo ip link set vxlan100 master br-vxlan

# Add VM interfaces to bridge
sudo ip link set vnet0 master br-vxlan
sudo ip link set vnet1 master br-vxlan

Software-Defined Networking (SDN) Introduction

SDN separates the control plane from the data plane, enabling centralized network management and programmability.

Key SDN Concepts:

  • Control Plane: Makes decisions about where traffic is sent
  • Data Plane: Forwards traffic based on control plane decisions
  • Northbound API: Interface between applications and SDN controller
  • Southbound API: Interface between controller and network devices (e.g., OpenFlow)

OpenFlow Example

OpenFlow is a communication protocol that enables SDN controllers to program flow tables in network switches.

1
2
3
4
5
6
7
8
Controller                    Switch
| |
|--- Flow Mod (add rule) -->|
| |
|<-- Packet In (unknown) ---|
| |
|--- Flow Mod (rule) ------->|
| |

Open vSwitch (OVS) Basics

Open vSwitch is a production-quality virtual switch for SDN.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Install Open vSwitch
sudo apt install openvswitch-switch

# Create bridge
sudo ovs-vsctl add-br br0

# Add ports
sudo ovs-vsctl add-port br0 eth0
sudo ovs-vsctl add-port br0 vnet0

# List bridges
sudo ovs-vsctl show

# Add flow rule
sudo ovs-ofctl add-flow br0 "in_port=1,actions=output:2"

# View flows
sudo ovs-ofctl dump-flows br0

Desktop Virtualization (VDI)

Virtual Desktop Infrastructure (VDI) delivers desktop environments from centralized servers to end-user devices.

VDI Architecture

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
                    +------------------+
| VDI Broker |
| (Connection |
| Manager) |
+------------------+
|
+------------------+------------------+
| | |
+------------------+ +------------------+ +------------------+
| Hypervisor 1 | | Hypervisor 2 | | Hypervisor 3 |
| +------------+ | | +------------+ | | +------------+ |
| | Desktop VM | | | | Desktop VM | | | | Desktop VM | |
| +------------+ | | +------------+ | | +------------+ |
+------------------+ +------------------+ +------------------+
| | |
+------------------+------------------+
|
+------------------+
| Shared Storage |
+------------------+

VDI Deployment Models

Persistent Desktops

Each user gets a dedicated VM that retains data and customization between sessions.

Non-Persistent Desktops

Users receive a fresh desktop from a pool each session. Changes are discarded after logout.

Pooled Desktops

Multiple users share a pool of desktops, with personalization stored separately.

VDI Protocols

RDP (Remote Desktop Protocol)

Microsoft's protocol for remote desktop access.

1
2
# Connect via RDP
xfreerdp /u:username /p:password /v:server-ip /size:1920x1080

PCoIP (PC-over-IP)

Teradici's protocol optimized for WAN connections.

Blast Protocol

VMware's protocol with adaptive encoding.

HDX

Citrix's protocol with advanced optimization.

VDI Implementation Example

Using KVM for VDI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Create desktop VM template
virt-install \
--name desktop-template \
--ram 4096 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/desktop-template.qcow2,size=50 \
--os-type linux \
--os-variant ubuntu22.04 \
--network bridge=virbr0 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole

# Clone template for user
virt-clone \
--original desktop-template \
--name user-desktop-001 \
--file /var/lib/libvirt/images/user-desktop-001.qcow2

# Configure RDP server in guest
# Install xrdp
sudo apt install xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp

Performance Optimization Strategies

Optimizing virtualization performance requires understanding resource bottlenecks and applying appropriate tuning techniques.

CPU Optimization

CPU Pinning

Binding VMs to specific CPU cores reduces cache misses and improves performance.

1
2
3
4
5
6
# KVM CPU pinning
virsh vcpupin ubuntu-server 0 0-3
virsh vcpupin ubuntu-server 1 4-7

# VMware ESXi CPU affinity
# Via vSphere Client: VM -> Edit Settings -> CPU -> Advanced -> CPU Affinity

CPU Topology

Configuring proper CPU topology helps guest OS optimize scheduling.

1
2
3
4
5
<!-- libvirt XML -->
<cpu mode='host-passthrough'>
<topology sockets='1' cores='4' threads='2'/>
<cache mode='passthrough'/>
</cpu>

NUMA Configuration

Non-Uniform Memory Access (NUMA) awareness improves performance on multi-socket systems.

1
2
3
4
5
# Check NUMA topology
numactl --hardware

# Pin VM to NUMA node
virsh numatune ubuntu-server --nodeset 0 --mode strict

Memory Optimization

Memory Ballooning

Allows dynamic memory reallocation between VMs.

1
2
3
4
5
6
# Enable balloon driver in guest
# Install virtio-balloon driver

# Set memory limits
virsh setmem ubuntu-server 2G --live
virsh setmaxmem ubuntu-server 8G

Transparent Huge Pages (THP)

Reduces TLB misses for memory-intensive workloads.

1
2
3
4
# Enable THP
echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

# For VMs, ensure guest also uses THP

Memory Overcommitment

1
2
3
# Calculate safe overcommit ratio
# Monitor with: virsh dommemstat <vm>
# Typical safe ratio: 1.5:1 to 2:1

Storage I/O Optimization

I/O Scheduler Selection

1
2
# For VMs, use mq-deadline or none
echo mq-deadline | sudo tee /sys/block/nvme0n1/queue/scheduler

Storage Caching

1
2
3
4
<!-- Use writeback cache for better performance (with UPS!) -->
<disk>
<driver cache='writeback'/>
</disk>

Storage Format

  • Raw: Best performance, no overhead
  • QCOW2: Features (snapshots, compression) but overhead
  • VMDK: VMware format, good compatibility

Async I/O

1
2
3
4
5
# Enable libaio for better async I/O
# In VM XML:
<disk>
<driver name='qemu' type='raw' cache='none' io='native'/>
</disk>

Network Optimization

SR-IOV (Single Root I/O Virtualization)

Direct hardware access for network-intensive workloads.

1
2
3
4
5
6
7
# Enable SR-IOV
echo 4 | sudo tee /sys/class/net/eth0/device/sriov_numvfs

# Assign VF to VM
virsh nodedev-list --cap pci
virsh nodedev-dettach pci_0000_02_00_1
virsh attach-device ubuntu-server vf-pci.xml

Virtio Network Drivers

Always use virtio drivers for best performance in KVM.

1
2
3
4
<interface type='bridge'>
<model type='virtio'/>
<driver name='vhost'/>
</interface>

Jumbo Frames

1
2
3
4
# Enable jumbo frames on host
sudo ip link set eth0 mtu 9000

# Configure in VM network settings

Security and Isolation

Security is paramount in virtualized environments where multiple tenants share physical resources.

Hypervisor Security

Hypervisor Hardening

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Disable unnecessary services
sudo systemctl disable avahi-daemon
sudo systemctl disable cups

# Configure firewall
sudo ufw enable
sudo ufw allow from 192.168.1.0/24 to any port 22
sudo ufw allow from 192.168.1.0/24 to any port 16509 # libvirt

# Secure libvirt
# Edit /etc/libvirt/libvirtd.conf
listen_tls = 1
listen_tcp = 0
auth_tls = "sasl"

VM Isolation

  • Each VM runs in isolated memory space
  • CPU isolation via hardware virtualization
  • Network isolation via VLANs/VXLAN
  • Storage isolation via access controls

VM Security Best Practices

Minimal Guest OS

Install only necessary components in guest OS.

Regular Updates

1
2
3
# Automated updates in guest
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Security Monitoring

1
2
3
4
5
# Monitor VM resource usage
virsh domstats ubuntu-server

# Check for anomalies
# Use tools like AIDE, OSSEC in guests

Encryption

1
2
3
4
5
6
# Encrypt VM disk
qemu-img create -f qcow2 -o encryption=on,encrypt.format=luks vm-encrypted.qcow2 50G

# Use LUKS in guest
sudo cryptsetup luksFormat /dev/vda2
sudo cryptsetup luksOpen /dev/vda2 encrypted

Network Security

Firewall Rules

1
2
3
4
# iptables rules for VM network
sudo iptables -A FORWARD -i virbr0 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -o eth0 -j MASQUERADE

VLAN Segmentation

Isolate VMs into different VLANs based on security requirements.

VPN Integration

Connect VMs to VPN for secure remote access.

Troubleshooting Guide

Common virtualization issues and their solutions.

VM Won't Start

Symptoms: VM fails to boot or start

Diagnosis:

1
2
3
4
5
6
7
8
9
# Check VM status
virsh dominfo ubuntu-server

# View VM logs
virsh dumpxml ubuntu-server | grep -A 10 '<devices>'
journalctl -u libvirtd

# Check disk space
df -h

Solutions:

  • Ensure sufficient disk space
  • Verify disk image integrity: qemu-img check vm.qcow2
  • Check permissions on disk files
  • Verify CPU compatibility (check /proc/cpuinfo for virtualization flags)

Performance Issues

Symptoms: Slow VM performance

Diagnosis:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Check CPU usage
top
htop

# Check I/O wait
iostat -x 1

# Check memory
free -h
virsh dommemstat ubuntu-server

# Check network
iftop

Solutions:

  • Enable CPU pinning
  • Use virtio drivers
  • Increase memory allocation
  • Optimize storage (raw format, proper cache settings)
  • Check for resource contention on host

Network Connectivity Problems

Symptoms: VM cannot reach network

Diagnosis:

1
2
3
4
5
6
7
8
9
10
# Check bridge status
ip link show virbr0
brctl show

# Check VM network config
virsh domiflist ubuntu-server
virsh domifaddr ubuntu-server

# Test connectivity from host
ping -c 4 192.168.122.50

Solutions:

  • Verify bridge is up: sudo ip link set virbr0 up
  • Check iptables rules
  • Verify VM network configuration
  • Check DHCP server (dnsmasq) status
  • Verify routing tables

Storage Issues

Symptoms: Disk full, I/O errors

Diagnosis:

1
2
3
4
5
6
7
8
9
# Check disk usage
df -h
du -sh /var/lib/libvirt/images/*

# Check disk health
smartctl -a /dev/sda

# Check for I/O errors
dmesg | grep -i error

Solutions:

  • Expand disk: qemu-img resize vm.qcow2 +20G
  • Check and repair file system in guest
  • Migrate to larger storage
  • Enable thin provisioning
  • Monitor disk I/O and optimize

Migration Failures

Symptoms: Live migration fails

Diagnosis:

1
2
3
4
# Check migration requirements
# - Shared storage
# - Network connectivity
# - Sufficient resources on destination

Solutions:

  • Ensure shared storage accessible from both hosts
  • Verify network connectivity between hosts
  • Check available resources on destination
  • Use pre-copy migration for better success rate
  • Monitor migration progress: virsh migrate --verbose

Case Studies

Case Study 1: Enterprise Data Center Consolidation

Scenario:

A financial services company needed to consolidate 200 physical servers into a virtualized environment to reduce costs and improve manageability.

Solution:

  • Deployed VMware vSphere cluster with 20 physical hosts
  • Implemented shared SAN storage with replication
  • Used vMotion for live migrations
  • Implemented DRS (Distributed Resource Scheduler) for load balancing

Results:

  • Reduced physical servers by 90% (200 → 20)
  • Achieved 60% cost reduction in hardware and power
  • Improved disaster recovery with vSphere HA
  • Reduced deployment time from weeks to hours

Key Learnings:

  • Proper capacity planning is critical
  • Network bandwidth crucial for vMotion
  • Storage performance is often the bottleneck
  • Regular performance monitoring essential

Case Study 2: Development/Testing Environment

Scenario:

A software development company needed isolated environments for multiple teams working on different projects.

Solution:

  • Implemented KVM-based virtualization on Linux hosts
  • Used libvirt for management
  • Created VM templates for rapid provisioning
  • Implemented automated snapshot and rollback

Configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Automated VM creation script
#!/bin/bash
VM_NAME=$1
VM_IP=$2

virt-clone --original template-ubuntu \
--name$VM_NAME \
--file /var/lib/libvirt/images/${VM_NAME}.qcow2

virsh start$VM_NAME

# Wait for VM to boot and configure IP
# ... configuration scripts ...

Results:

  • Reduced environment setup time from days to minutes
  • Improved resource utilization from 30% to 80%
  • Enabled parallel development streams
  • Simplified environment cleanup and reset

Key Learnings:

  • Automation is essential for scale
  • Template management critical
  • Network isolation important for testing
  • Snapshot management prevents sprawl

Case Study 3: High-Performance Computing (HPC)

Scenario:

A research institution needed to run scientific computing workloads with near-native performance.

Solution:

  • Used KVM with CPU pinning and NUMA awareness
  • Implemented SR-IOV for network I/O
  • Used raw disk format for storage
  • Configured huge pages for memory-intensive workloads

Optimization Configuration:

1
2
3
4
5
6
7
8
9
# CPU pinning script
for vm in compute-{1..10}; do
virsh vcpupin$vm 0 0-7
virsh vcpupin $vm 1 8-15
virsh numatune$vm --nodeset 0 --mode strict
done

# Enable huge pages
echo 1024 | sudo tee /proc/sys/vm/nr_hugepages

Results:

  • Achieved 95%+ of native performance
  • Successfully virtualized HPC workloads
  • Improved resource sharing across projects
  • Maintained performance while gaining flexibility

Key Learnings:

  • Hardware-assisted virtualization essential
  • Proper resource allocation critical
  • Monitoring performance continuously
  • Some workloads still benefit from bare metal

Q&A Section

Q1: What's the difference between Type 1 and Type 2 hypervisors?

A: Type 1 (bare-metal) hypervisors run directly on hardware without a host OS (e.g., VMware ESXi, Hyper-V, Xen). Type 2 hypervisors run on top of a host OS (e.g., VMware Workstation, VirtualBox, Parallels). Type 1 generally offers better performance and security, while Type 2 is easier to set up and manage.

Q2: Can I run macOS in a VM on non-Apple hardware?

A: Technically possible but violates Apple's EULA. macOS virtualization is only legally allowed on Apple hardware. Even on Apple hardware, running macOS VMs requires specific configurations and may have limitations.

Q3: How do containers compare to VMs for cloud deployments?

A: Containers share the host OS kernel, making them lighter and faster to start than VMs. VMs provide stronger isolation but higher overhead. Containers excel for microservices and DevOps, while VMs are better for legacy applications, mixed OS environments, and stronger isolation requirements.

Q4: What is the maximum number of VMs I can run on a single host?

A: Depends on host resources, VM sizes, and workload characteristics. Practical limits:

  • CPU: Number of cores × overcommit ratio (typically 4:1 to 8:1)
  • Memory: Physical RAM ÷ average VM memory
  • I/O: Storage and network bandwidth
  • Typical: 10-50 VMs per host, but can reach 100+ with proper sizing

Q5: How does live migration work?

A: Live migration (e.g., vMotion, KVM migration) transfers a running VM between hosts without downtime: 1. Pre-copy phase: Memory pages copied iteratively 2. Stop-and-copy: Final sync while VM paused briefly 3. Resume on destination: VM continues execution Requires shared storage and network connectivity between hosts.

Q6: What are the security implications of virtualization?

A: Virtualization introduces new attack surfaces:

  • Hypervisor vulnerabilities could affect all VMs
  • VM escape attacks (breaking isolation)
  • Side-channel attacks (extracting information via shared resources) Mitigation: Keep hypervisors updated, use hardware-assisted virtualization, implement proper network segmentation, monitor for anomalies.

Q7: How do I choose between KVM, VMware, and Hyper-V?

A: Consider:

  • KVM: Open-source, Linux-native, cost-effective, good performance
  • VMware: Enterprise features, excellent management tools, higher cost
  • Hyper-V: Windows integration, included with Windows Server, good for Microsoft shops Choose based on existing infrastructure, budget, feature requirements, and support needs.

Q8: What is storage overcommitment and is it safe?

A: Storage overcommitment allocates more virtual disk space than physically available (e.g., 1TB virtual disks on 500GB storage). Works if not all VMs use full capacity simultaneously. Risks: Running out of space, performance degradation. Mitigation: Monitor usage, set alerts, use thin provisioning carefully.

Q9: Can I virtualize GPU workloads?

A: Yes, through:

  • GPU passthrough: Direct hardware access (best performance, one VM per GPU)
  • GPU sharing: vGPU (NVIDIA GRID, AMD MxGPU) allows multiple VMs to share GPU
  • Software rendering: Lower performance, compatibility issues Common for VDI, machine learning, video processing workloads.

Q10: How do I backup virtual machines?

A: Multiple approaches:

  • Snapshot-based: Quick, space-efficient, but not true backups
  • Image-level: Full VM disk images (e.g., qemu-img convert)
  • Agent-based: Backup software inside guest OS
  • Storage-level: SAN/NAS snapshots Best practice: Combine approaches, test restores regularly, follow 3-2-1 backup rule (3 copies, 2 media types, 1 offsite).

Summary Cheat Sheet

Quick Reference: Hypervisor Commands

KVM/libvirt:

1
2
3
4
5
6
7
8
virsh list --all              # List VMs
virsh start <vm> # Start VM
virsh shutdown <vm> # Graceful shutdown
virsh destroy <vm> # Force stop
virsh suspend <vm> # Suspend
virsh resume <vm> # Resume
virsh snapshot-create <vm> # Create snapshot
virsh domstats <vm> # VM statistics

VMware ESXi:

1
2
3
4
5
vim-cmd vmsvc/getallvms       # List VMs
vim-cmd vmsvc/power.on <id> # Power on
vim-cmd vmsvc/power.off <id> # Power off
esxcli vm process list # Running VMs
esxcli storage vmfs list # List datastores

Hyper-V (PowerShell):

1
2
3
4
5
Get-VM                        # List VMs
Start-VM <name> # Start
Stop-VM <name> # Stop
Checkpoint-VM <name> # Snapshot
Get-VMProcessor <name> # CPU info

Performance Tuning Checklist

Security Checklist

Troubleshooting Quick Guide

Issue Check Solution
VM won't start Disk space, permissions, logs Free space, fix permissions, check logs
Slow performance CPU, memory, I/O stats Optimize resources, use virtio, check host load
Network issues Bridge status, iptables Verify bridge, check firewall rules
Storage full Disk usage, thin provisioning Expand storage, cleanup snapshots
Migration fails Shared storage, network Verify connectivity, check resources

Resource Sizing Guidelines

CPU:

  • Light workload: 1-2 vCPUs
  • Medium workload: 2-4 vCPUs
  • Heavy workload: 4-8+ vCPUs
  • Overcommit ratio: 4:1 to 8:1 typical

Memory:

  • Windows Server: 4GB minimum, 8GB+ recommended
  • Linux Server: 2GB minimum, 4GB+ recommended
  • Desktop: 4-8GB typical
  • Overcommit: 1.5:1 to 2:1 safe ratio

Storage:

  • OS disk: 20-50GB typical
  • Application data: Varies by workload
  • Use thin provisioning when possible
  • Plan for snapshots (20-30% overhead)

Network:

  • 1 Gbps sufficient for most workloads
  • 10 Gbps for high-throughput applications
  • Consider SR-IOV for network-intensive VMs

Virtualization technology continues to evolve, with new innovations in containerization, serverless computing, and edge computing building upon these foundational concepts. Understanding virtualization deeply enables better cloud architecture decisions, cost optimization, and performance tuning. Whether you're running a small development environment or managing enterprise data centers, the principles and practices covered in this article provide a solid foundation for successful virtualization deployments.

  • Post title:Cloud Computing (2): Virtualization Technology Deep Dive
  • Post author:Chen Kai
  • Create time:2023-01-15 00:00:00
  • Post link:https://www.chenk.top/en/cloud-computing-virtualization-deep-dive/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments