|
| 1 | +# Nested Virtualization Setup for Cloud Hypervisor |
| 2 | + |
| 3 | +This guide helps you enable and verify nested virtualization on your x86_64 hosts running cloud-hypervisor, allowing Windows VMs to run Docker containers and WSL2. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### 1. Check Current Status |
| 8 | + |
| 9 | +First, check which hosts have nested virtualization enabled: |
| 10 | + |
| 11 | +```bash |
| 12 | +cd ops |
| 13 | +ansible-playbook -i inventory.ini check_nested_virt.yml |
| 14 | +``` |
| 15 | + |
| 16 | +This will show you for each x86_64 host: |
| 17 | +- CPU vendor (Intel/AMD) |
| 18 | +- Whether nested virtualization is enabled |
| 19 | +- Cloud Hypervisor installation status |
| 20 | +- Number of running VMs |
| 21 | + |
| 22 | +**ARM hosts are automatically skipped** (only x86_64 hosts are checked). |
| 23 | + |
| 24 | +### 2. Enable Nested Virtualization |
| 25 | + |
| 26 | +To enable nested virtualization on all x86_64 hosts: |
| 27 | + |
| 28 | +```bash |
| 29 | +cd ops |
| 30 | +ansible-playbook -i inventory.ini enable_nested_virt.yml |
| 31 | +``` |
| 32 | + |
| 33 | +This playbook will: |
| 34 | +- Create persistent configuration in `/etc/modprobe.d/kvm-nested.conf` |
| 35 | +- Attempt to reload KVM modules immediately (if no VMs are running) |
| 36 | +- Show which hosts need a reboot |
| 37 | + |
| 38 | +### 3. Reboot Hosts (if required) |
| 39 | + |
| 40 | +If VMs were running or module reload failed, you'll need to reboot: |
| 41 | + |
| 42 | +```bash |
| 43 | +cd ops |
| 44 | +# Reboot specific hosts |
| 45 | +ansible staging -i inventory.ini -m reboot -b --limit "host1,host2" |
| 46 | + |
| 47 | +# Or reboot all hosts (be careful!) |
| 48 | +ansible staging -i inventory.ini -m reboot -b |
| 49 | +``` |
| 50 | + |
| 51 | +### 4. Verify After Reboot |
| 52 | + |
| 53 | +After rebooting, verify nested virtualization is working: |
| 54 | + |
| 55 | +```bash |
| 56 | +cd ops |
| 57 | +ansible-playbook -i inventory.ini check_nested_virt.yml |
| 58 | +``` |
| 59 | + |
| 60 | +You should see `✓ NESTED VIRTUALIZATION: ENABLED` for all x86_64 hosts. |
| 61 | + |
| 62 | +## What This Enables |
| 63 | + |
| 64 | +Once nested virtualization is enabled: |
| 65 | + |
| 66 | +1. **Cloud Hypervisor automatically exposes VMX/SVM to guest VMs** - no additional configuration needed |
| 67 | +2. **Windows VMs can enable Hyper-V** and run virtualized workloads |
| 68 | +3. **WSL2 will work** in Windows VMs (requires Hyper-V) |
| 69 | +4. **Docker Desktop can run** in Windows VMs using WSL2 backend |
| 70 | +5. **Linux containers in Docker** will work for your customers' test suites |
| 71 | + |
| 72 | +## How It Works |
| 73 | + |
| 74 | +### Intel CPUs |
| 75 | +- Sets `options kvm_intel nested=1` in `/etc/modprobe.d/kvm-nested.conf` |
| 76 | +- Exposes VMX (Virtual Machine Extensions) to guests |
| 77 | + |
| 78 | +### AMD CPUs |
| 79 | +- Sets `options kvm_amd nested=1` in `/etc/modprobe.d/kvm-nested.conf` |
| 80 | +- Exposes SVM (Secure Virtual Machine) to guests |
| 81 | + |
| 82 | +### In Cloud Hypervisor |
| 83 | +- Cloud Hypervisor uses KVM's `get_supported_cpuid()` function |
| 84 | +- If KVM has nested virtualization enabled, VMX/SVM features are automatically included |
| 85 | +- No changes needed to your cloud-hypervisor configuration |
| 86 | +- Windows VMs will automatically see the virtualization extensions |
| 87 | + |
| 88 | +## Manual Verification on a Host |
| 89 | + |
| 90 | +To manually check on a single host: |
| 91 | + |
| 92 | +```bash |
| 93 | +# SSH to the host |
| 94 | +ssh ubuntu@100.123.214.111 |
| 95 | + |
| 96 | +# Check if enabled (Intel) |
| 97 | +cat /sys/module/kvm_intel/parameters/nested |
| 98 | +# Should show: Y or 1 |
| 99 | + |
| 100 | +# Check if enabled (AMD) |
| 101 | +cat /sys/module/kvm_amd/parameters/nested |
| 102 | +# Should show: Y or 1 |
| 103 | + |
| 104 | +# Verify in a running Windows VM |
| 105 | +# From Windows PowerShell in the VM: |
| 106 | +systeminfo | findstr /C:"Hyper-V Requirements" |
| 107 | +# Should show "Yes" for all requirements |
| 108 | +``` |
| 109 | + |
| 110 | +## Performance Considerations |
| 111 | + |
| 112 | +- **L2 VMs are slower than L1 VMs** - this is expected with nested virtualization |
| 113 | +- For test suites, the performance is usually acceptable |
| 114 | +- Production workloads may see 10-30% performance degradation depending on workload |
| 115 | +- I/O-bound workloads (like Docker builds) are less affected than CPU-bound ones |
| 116 | + |
| 117 | +## Troubleshooting |
| 118 | + |
| 119 | +### Nested virtualization shows as disabled after reboot |
| 120 | +```bash |
| 121 | +# Check if config file exists |
| 122 | +cat /etc/modprobe.d/kvm-nested.conf |
| 123 | + |
| 124 | +# Reload modules manually |
| 125 | +sudo rmmod kvm_intel # or kvm_amd |
| 126 | +sudo rmmod kvm |
| 127 | +sudo modprobe kvm |
| 128 | +sudo modprobe kvm_intel nested=1 # or kvm_amd |
| 129 | +``` |
| 130 | + |
| 131 | +### Windows VM doesn't show virtualization support |
| 132 | +```bash |
| 133 | +# In Windows VM, run PowerShell as Administrator: |
| 134 | +Get-VMHost # Should not error if Hyper-V is available |
| 135 | +``` |
| 136 | + |
| 137 | +### Docker Desktop fails to start in Windows VM |
| 138 | +1. Ensure WSL2 is installed in Windows |
| 139 | +2. Enable "Use WSL2 based engine" in Docker Desktop settings |
| 140 | +3. Check Windows Features: Hyper-V and WSL2 should be enabled |
| 141 | + |
| 142 | +## Files |
| 143 | + |
| 144 | +- `inventory.ini` - Ansible inventory with host IPs |
| 145 | +- `check_nested_virt.yml` - Playbook to check status |
| 146 | +- `enable_nested_virt.yml` - Playbook to enable nested virtualization |
| 147 | +- `/etc/modprobe.d/kvm-nested.conf` - Created on each host (persistent config) |
| 148 | + |
| 149 | +## Your Inventory |
| 150 | + |
| 151 | +**x86_64 Hosts (will be configured):** |
| 152 | +- US: 6 hosts (Intel/AMD) |
| 153 | +- EU: 2 hosts (Intel/AMD) |
| 154 | + |
| 155 | +**ARM64 Hosts (automatically skipped):** |
| 156 | +- US: 2 ARM hosts |
| 157 | +- EU: 1 ARM host |
0 commit comments