2023-02-15 14:48:01 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#from https://github.com/spiritLHLS/pve
|
|
|
|
|
|
|
|
|
|
# 检查CPU是否支持硬件虚拟化
|
|
|
|
|
if [ "$(egrep -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
|
2023-02-15 15:34:21 +08:00
|
|
|
|
echo "CPU不支持硬件虚拟化,无法嵌套虚拟化KVM服务器"
|
|
|
|
|
exit 1
|
2023-02-15 14:48:01 +08:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查虚拟化选项是否启用
|
|
|
|
|
if [ "$(grep -E -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
|
2023-02-15 15:34:21 +08:00
|
|
|
|
echo "BIOS中未启用硬件虚拟化,无法嵌套虚拟化KVM服务器"
|
|
|
|
|
exit 1
|
2023-02-15 14:48:01 +08:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查KVM模块是否已加载
|
|
|
|
|
if lsmod | grep -q kvm; then
|
2023-02-15 15:02:15 +08:00
|
|
|
|
echo "KVM模块已经加载"
|
2023-02-15 14:48:01 +08:00
|
|
|
|
else
|
|
|
|
|
# 加载KVM模块并将其添加到/etc/modules文件中
|
|
|
|
|
modprobe kvm
|
|
|
|
|
echo "kvm" >> /etc/modules
|
2023-02-15 15:02:15 +08:00
|
|
|
|
echo "KVM模块已加载并添加到 /etc/modules"
|
2023-02-15 14:48:01 +08:00
|
|
|
|
fi
|