You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LXC Windows 11容器频繁崩溃:原因分析与修复方案咨询

Windows 11 LXC虚拟机频繁崩溃的原因分析与修复方案

关键故障日志

lxc info win11 --show-log

Name: win11
Status: STOPPED
Type: virtual-machine
Architecture: x86_64
Created: 2023/09/12 16:26 UTC
Last Used: 2023/09/15 16:49 UTC

Log:

virtio_input_handle_event: unmapped key: 0 [unmapped]
KVM: entry failed, hardware error 0x80000021

If you're running a guest on an Intel machine without unrestricted mode
support, the failure can be most likely due to the guest entering an invalid
state for Intel VT. For example, the guest maybe running in big real mode
which is not supported on less recent Intel processors.

EAX=000003d0 EBX=95bac080 ECX=00000000 EDX=8b09c850
ESI=8b108440 EDI=00000000 EBP=a953a9c0 ESP=6dcd7fb0
EIP=00008000 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=1 HLT=0
ES =0000 00000000 ffffffff 00809300
CS =be00 7ffbe000 ffffffff 00809300
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =0000 00000000 ffffffff 00809300
LDT=0000 00000000 ffffffff 00c00000
TR =0040 6dc76000 00000067 00008b00
GDT=     6dc77fb0 00000057
IDT=     00000000 00000000
CR0=00050032 CR2=a8416a61 CR3=b535f000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=qemu-system-x86_64: ../hw/core/cpu-sysemu.c:76: cpu_asidx_from_attrs: Assertion `ret < cpu->num_ases && ret >= 0' failed.

故障原因

  1. CPU虚拟化特性缺失:Intel处理器未启用Unrestricted Guest模式,Windows 11运行时进入了KVM不兼容的CPU模式(如大实模式),触发硬件错误0x80000021。
  2. QEMU/LXC版本bug:当前使用的QEMU版本存在CPU地址空间索引处理的断言失败问题,直接导致虚拟机崩溃。
  3. 配置参数不合理:CPU型号匹配错误、内存分配不足,或virtio输入设备映射异常,引发系统运行状态异常。

修复方案

1. 启用Intel处理器Unrestricted Guest模式

  • 检查CPU支持情况:
    grep -E 'vmx|unrestricted' /proc/cpuinfo
    
    输出包含unrestricted_guest则说明支持该特性。
  • 启用该模式:
    编辑/etc/modprobe.d/kvm.conf,添加:
    options kvm_intel unrestricted_guest=1
    
    重新加载KVM模块:
    rmmod kvm_intel && modprobe kvm_intel
    
    验证启用状态:
    cat /sys/module/kvm_intel/parameters/unrestricted_guest
    
    输出为Y则成功。

2. 调整LXC虚拟机配置

  • 编辑容器配置文件(路径通常为/var/lib/lxc/win11/config),修改CPU与内存参数:
    lxc.cpu.mode=host-model
    lxc.cpu.allowance=100%
    lxc.memory.size=8GiB
    
  • 若virtio输入设备异常,可替换为PS/2设备:
    lxc.device.remove=input
    lxc.device.add=input,type=ps2-kbd
    

3. 更新QEMU与LXC到稳定版

  • Debian/Ubuntu系:
    apt update && apt upgrade qemu-system-x86 lxc lxd
    
  • RHEL/CentOS系:
    dnf update qemu-kvm lxc
    

4. 重新创建容器(以上方法无效时)

  • 备份数据后,用官方模板重新创建并配置:
    lxc launch images:windows/11 win11-new --vm
    lxc config set win11-new cpu.mode host-model
    lxc config set win11-new memory.size 8GiB
    

内容的提问来源于stack exchange,提问作者Gleb Vishnevsky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 12:17:44