File size: 7,361 Bytes
279efce |
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# Check Virtualization Setup
You are helping the user check if the system is properly set up to run virtualized workloads and remediate any issues.
## Your tasks:
1. **Check if CPU supports virtualization:**
**Intel (VT-x):**
```bash
grep -E "vmx" /proc/cpuinfo
```
**AMD (AMD-V):**
```bash
grep -E "svm" /proc/cpuinfo
```
If no output, virtualization is not supported or not enabled in BIOS.
2. **Check if virtualization is enabled in BIOS:**
```bash
sudo apt install cpu-checker
sudo kvm-ok
```
If it says KVM can be used, virtualization is enabled.
If not, user needs to enable it in BIOS/UEFI.
3. **Check current virtualization software:**
**KVM/QEMU:**
```bash
which qemu-system-x86_64
lsmod | grep kvm
```
**VirtualBox:**
```bash
which virtualbox
VBoxManage --version
```
**VMware:**
```bash
which vmware
systemctl status vmware
```
**Docker (containerization):**
```bash
docker --version
systemctl status docker
```
4. **Check KVM kernel modules:**
```bash
lsmod | grep kvm
```
Should show:
- `kvm_intel` (for Intel)
- `kvm_amd` (for AMD)
- `kvm` (base module)
If not loaded, try:
```bash
sudo modprobe kvm
sudo modprobe kvm_intel # or kvm_amd
```
5. **Install KVM and related tools (if not installed):**
```bash
sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
```
6. **Check libvirt status:**
```bash
sudo systemctl status libvirtd
```
If not running:
```bash
sudo systemctl enable libvirtd
sudo systemctl start libvirtd
```
7. **Add user to required groups:**
```bash
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
```
User needs to log out and back in for group changes to take effect.
8. **Verify user permissions:**
```bash
groups
```
Should include: `libvirt` and `kvm`
9. **Check libvirt connectivity:**
```bash
virsh list --all
```
If permission denied, user is not in libvirt group or not logged back in.
10. **Check virtualization networking:**
**Default network:**
```bash
virsh net-list --all
```
If default network is not active:
```bash
virsh net-start default
virsh net-autostart default
```
**Bridge networking:**
```bash
ip link show
brctl show # if bridge-utils installed
```
11. **Check nested virtualization (if needed):**
**For Intel:**
```bash
cat /sys/module/kvm_intel/parameters/nested
```
**For AMD:**
```bash
cat /sys/module/kvm_amd/parameters/nested
```
If shows `N` or `0`, nested virtualization is disabled.
To enable:
```bash
echo "options kvm_intel nested=1" | sudo tee /etc/modprobe.d/kvm-intel.conf
# or for AMD:
echo "options kvm_amd nested=1" | sudo tee /etc/modprobe.d/kvm-amd.conf
```
Then reload:
```bash
sudo modprobe -r kvm_intel
sudo modprobe kvm_intel
```
12. **Check IOMMU for PCIe passthrough (if needed):**
```bash
dmesg | grep -i iommu
```
If IOMMU is needed, add to kernel parameters in `/etc/default/grub`:
```
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on"
# or for AMD:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on"
```
Then update grub:
```bash
sudo update-grub
sudo reboot
```
13. **Check available storage pools:**
```bash
virsh pool-list --all
```
Create default pool if needed:
```bash
virsh pool-define-as default dir --target /var/lib/libvirt/images
virsh pool-start default
virsh pool-autostart default
```
14. **Check system resources for virtualization:**
```bash
free -h
df -h /var/lib/libvirt/images
cat /proc/cpuinfo | grep "processor" | wc -l
```
Recommendations:
- At least 4GB RAM for light VMs
- At least 20GB free disk space
- Multiple CPU cores recommended
15. **Test VM creation (small test):**
```bash
virt-install --name test-vm \
--ram 512 \
--disk size=1 \
--cdrom /path/to/iso \
--graphics vnc \
--check all=off \
--dry-run
```
16. **Check for conflicting virtualization:**
VirtualBox and KVM can sometimes conflict. Check if both are installed:
```bash
dpkg -l | grep -E "virtualbox|qemu-kvm"
```
VirtualBox kernel modules can conflict with KVM:
```bash
lsmod | grep vbox
```
17. **Check virtualization acceleration:**
```bash
ls -l /dev/kvm
```
Should be:
```
crw-rw---- 1 root kvm /dev/kvm
```
18. **Install virt-manager (GUI) if desired:**
```bash
sudo apt install virt-manager
```
Test launch:
```bash
virt-manager
```
19. **Check for Secure Boot issues:**
Secure Boot can prevent some virtualization modules from loading:
```bash
mokutil --sb-state
```
If Secure Boot is enabled and causing issues, user may need to:
- Sign modules
- Disable Secure Boot in BIOS
- Use signed versions
20. **Performance tuning:**
**Enable hugepages for better performance:**
```bash
sudo sysctl vm.nr_hugepages=1024
echo "vm.nr_hugepages=1024" | sudo tee -a /etc/sysctl.conf
```
**Check CPU governor:**
```bash
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
```
For virtualization, `performance` governor is recommended:
```bash
sudo apt install cpufrequtils
sudo cpufreq-set -g performance
```
21. **Report findings:**
Summarize:
- CPU virtualization support status
- BIOS/UEFI virtualization enabled status
- KVM modules loaded status
- libvirt status
- User group membership
- Network configuration
- Nested virtualization status
- Storage pools status
- Available resources
- Any conflicts or issues
- Recommendations
22. **Provide recommendations:**
- Enable VT-x/AMD-V in BIOS if not enabled
- Install KVM/QEMU if not present
- Add user to libvirt and kvm groups
- Set up default network
- Enable nested virtualization if needed
- Configure IOMMU for PCIe passthrough if needed
- Install virt-manager for GUI management
- Allocate sufficient resources
- Resolve any conflicts (VirtualBox vs KVM)
- Performance tuning suggestions
23. **Basic virtualization commands to share:**
- `virsh list --all` - List all VMs
- `virsh start <vm>` - Start a VM
- `virsh shutdown <vm>` - Shutdown a VM
- `virsh destroy <vm>` - Force stop a VM
- `virsh console <vm>` - Connect to VM console
- `virsh net-list` - List networks
- `virsh pool-list` - List storage pools
- `virt-manager` - Launch GUI
- `virt-install` - Create new VM from command line
## Important notes:
- Virtualization must be enabled in BIOS/UEFI
- User must be in kvm and libvirt groups
- Log out and back in after adding to groups
- VirtualBox and KVM can conflict
- Nested virtualization is disabled by default
- IOMMU required for PCIe passthrough
- Secure Boot may prevent module loading
- Sufficient RAM and disk space needed
- Performance governor recommended for VMs
- Check if system is itself a VM before enabling nested virtualization
|