pve/scripts/check_kernal.sh

111 lines
5.8 KiB
Bash
Raw Normal View History

2023-02-15 14:48:01 +08:00
#!/bin/bash
2023-06-22 14:42:39 +08:00
# from
# https://github.com/spiritLHLS/pve
2023-06-29 21:41:08 +08:00
# 2023.06.29
2023-02-15 14:48:01 +08:00
2023-02-26 11:36:29 +08:00
# 用颜色输出信息
2023-02-15 17:26:13 +08:00
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
2023-04-24 09:19:40 +08:00
reading(){ read -rp "$(_green "$1")" "$2"; }
2023-04-27 11:26:53 +08:00
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8")
2023-04-27 11:08:53 +08:00
if [[ -z "$utf8_locale" ]]; then
2023-04-27 11:26:53 +08:00
echo "No UTF-8 locale found"
2023-04-24 08:56:06 +08:00
else
2023-04-27 11:08:53 +08:00
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
2023-04-27 11:26:53 +08:00
echo "Locale set to $utf8_locale"
2023-04-24 08:56:06 +08:00
fi
2023-04-24 08:35:39 +08:00
2023-04-27 17:18:15 +08:00
check_config(){
2023-06-29 21:41:08 +08:00
_green "The machine configuration should meet the minimum requirements of at least 2 cores 2G RAM 20G hard drive"
2023-05-28 18:16:57 +08:00
_green "本机配置应当满足至少2核2G内存20G硬盘的最低要求"
# 检查硬盘大小
total_disk=$(df -h / | awk '/\//{print $2}')
2023-06-06 18:02:08 +08:00
total_disk_num=$(echo $total_disk | sed -E 's/([0-9.]+)([GT])/\1 \2/')
total_disk_num=$(awk '{printf "%.0f", $1 * ($2 == "T" ? 1024 : 1)}' <<< "$total_disk_num")
2023-05-28 18:16:57 +08:00
if [ "$total_disk_num" -lt 20 ]; then
2023-06-29 21:41:08 +08:00
_red "The machine configuration does not meet the minimum requirements: at least 20G hard drive"
_red "This machine's hard drive configuration does not allow for the installation of PVE"
2023-05-28 18:16:57 +08:00
_red "本机配置不满足最低要求至少20G硬盘"
_red "本机硬盘配置无法安装PVE"
fi
2023-04-27 17:18:15 +08:00
# 检查CPU核心数
cpu_cores=$(grep -c ^processor /proc/cpuinfo)
if [ "$cpu_cores" -lt 2 ]; then
2023-06-29 21:41:08 +08:00
_red "The local machine configuration does not meet the minimum requirements: at least 2 core CPU"
_red "The number of CPUs on this machine is configured in such a way that PVE cannot be installed"
2023-04-27 17:18:15 +08:00
_red "本机配置不满足最低要求至少2核CPU"
2023-05-28 18:16:57 +08:00
_red "本机CPU数量配置无法安装PVE"
2023-04-27 17:18:15 +08:00
fi
2023-05-28 18:16:57 +08:00
2023-04-27 17:18:15 +08:00
# 检查内存大小
total_mem=$(free -m | awk '/^Mem:/{print $2}')
if [ "$total_mem" -lt 2048 ]; then
2023-06-29 21:41:08 +08:00
_red "The machine configuration does not meet the minimum requirements: at least 2G RAM"
_red "The local memory configuration cannot install PVE (SWAP is not calculated, if the virtual memory of SWAP plus the actual memory of the local machine is greater than 2G please ignore this prompt)"
2023-04-27 17:18:15 +08:00
_red "本机配置不满足最低要求至少2G内存"
2023-05-28 18:16:57 +08:00
_red "本机内存配置无法安装PVE (未计算SWAP如若SWAP的虚拟内存加上本机实际内存大于2G请忽略本提示)"
2023-04-27 17:18:15 +08:00
fi
}
check_config
2023-02-15 14:48:01 +08:00
# 检查CPU是否支持硬件虚拟化
if [ "$(egrep -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
2023-06-29 21:41:08 +08:00
_yellow "CPU does not support hardware virtualization, cannot nest virtualized KVM servers, but can open LXC servers (CT)"
2023-04-25 14:26:48 +08:00
_yellow "CPU不支持硬件虚拟化无法嵌套虚拟化KVM服务器但可以开LXC服务器(CT)"
2023-02-15 15:34:21 +08:00
exit 1
2023-02-26 11:36:29 +08:00
else
2023-06-29 21:41:08 +08:00
_green "The local CPU supports KVM hardware nested virtualization"
2023-02-26 11:36:29 +08:00
_green "本机CPU支持KVM硬件嵌套虚拟化"
2023-02-15 14:48:01 +08:00
fi
# 检查虚拟化选项是否启用
if [ "$(grep -E -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
2023-06-29 21:41:08 +08:00
_yellow "Hardware virtualization is not enabled in BIOS, cannot nest virtualized KVM servers, but can open LXC servers (CT)"
2023-04-25 14:26:48 +08:00
_yellow "BIOS中未启用硬件虚拟化无法嵌套虚拟化KVM服务器但可以开LXC服务器(CT)"
2023-02-15 15:34:21 +08:00
exit 1
2023-02-26 11:36:29 +08:00
else
2023-06-29 21:41:08 +08:00
_green "This machine BIOS is enabled to support KVM hardware nested virtualization"
2023-05-06 22:03:44 +08:00
_green "本机BIOS已启用支持KVM硬件嵌套虚拟化"
2023-02-15 14:48:01 +08:00
fi
2023-02-26 10:03:02 +08:00
# 查询系统是否支持
2023-04-25 14:31:00 +08:00
if [ -e "/sys/module/kvm_intel/parameters/nested" ] && [ "$(cat /sys/module/kvm_intel/parameters/nested | tr '[:upper:]' '[:lower:]')" = "y" ]; then
2023-05-06 22:03:44 +08:00
CPU_TYPE="intel"
elif [ -e "/sys/module/kvm_amd/parameters/nested" ] && [ "$(cat /sys/module/kvm_amd/parameters/nested | tr '[:upper:]' '[:lower:]')" = "1" ]; then
CPU_TYPE="amd"
2023-02-26 10:03:02 +08:00
else
2023-06-29 21:41:08 +08:00
_yellow "The local system configuration file identifies that KVM hardware nested virtualization is not supported, the KVM server virtualized using PVE may not be able to turn on KVM hardware virtualization in the options, if you have problems using NOVNC remember to turn it off in the open out KVM server options, subject to whether you can actually use it"
2023-05-06 22:51:48 +08:00
_yellow "本机系统配置文件识别到不支持KVM硬件嵌套虚拟化使用PVE虚拟化出来的KVM服务器可能不能在选项中开启KVM硬件虚拟化如果使用NOVNC有问题记得在开出来的KVM服务器选项中关闭以实际能否使用为准"
2023-02-26 20:51:02 +08:00
exit 1
2023-02-26 10:03:02 +08:00
fi
2023-05-06 22:08:02 +08:00
if ! lsmod | grep -q kvm; then
2023-06-29 21:41:08 +08:00
if [ "$CPU_TYPE" = "intel" ]; then
_yellow "KVM module not loaded, can't use PVE virtualized KVM server, but can open LXC server (CT)"
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
elif [ "$CPU_TYPE" = "amd" ]; then
_yellow "KVM module not loaded, can't use PVE virtualized KVM server, but can open LXC server (CT)"
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
fi
2023-05-06 22:08:02 +08:00
else
2023-06-29 21:41:08 +08:00
_green "This machine meets the requirements: it can use PVE to virtualize the KVM server and can turn on KVM hardware virtualization in the KVM server option that is opened"
_green "本机符合要求可以使用PVE虚拟化KVM服务器并可以在开出来的KVM服务器选项中开启KVM硬件虚拟化"
2023-05-06 22:03:44 +08:00
fi
2023-02-26 10:03:02 +08:00
2023-02-26 11:36:29 +08:00
# 如果KVM模块未加载则加载KVM模块并将其添加到/etc/modules文件中
if ! lsmod | grep -q kvm; then
2023-06-29 21:41:08 +08:00
_yellow "Trying to load KVM module ......"
2023-02-26 11:38:15 +08:00
_yellow "尝试加载KVM模块……"
2023-02-15 14:48:01 +08:00
modprobe kvm
echo "kvm" >> /etc/modules
2023-06-29 21:41:08 +08:00
_green "KVM module has tried to load and add to /etc/modules, you can try to use PVE virtualized KVM server, you can also open LXC server (CT)"
2023-05-06 22:08:02 +08:00
_green "KVM模块已尝试加载并添加到 /etc/modules可以尝试使用PVE虚拟化KVM服务器也可以开LXC服务器(CT)"
2023-02-15 14:48:01 +08:00
fi