Skip to content

Instantly share code, notes, and snippets.

@VMatrix1900
Created August 11, 2024 12:26
Show Gist options
  • Save VMatrix1900/02e333e72c9071d18a27067937a97e1f to your computer and use it in GitHub Desktop.
Save VMatrix1900/02e333e72c9071d18a27067937a97e1f to your computer and use it in GitHub Desktop.
Configure PVE
!/bin/bash
sver=`cat /etc/debian_version |awk -F"." '{print $1}'`
currentDebianVersion=${sver}
case "$sver" in
12 )
sver="bookworm"
;;
11 )
sver="bullseye"
;;
10 )
sver="buster"
;;
9 )
sver="stretch"
;;
8 )
sver="jessie"
;;
7 )
sver="wheezy"
;;
6 )
sver="squeeze"
;;
* )
sver=""
esac
# Configure powersave mode
echo "ondemand" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# remove enterprise source
rm /etc/apt/sources.list.d/pve-enterprise.list
# Change Debian source to tuna
cat > /etc/apt/sources.list <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
EOF
# Change pve source
echo "deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list
# Change Ceph source
sed -i -e 's/enterprise\.proxmox\.com/mirrors.ustc.edu.cn\/proxmox/g' -e 's/enterprise/main/' /etc/apt/sources.list.d/ceph.list
apt update
apt upgrade -y
# install cpu frequency tools
apt install cpufrequtils -y
echo 'GOVERNOR="ondemand"' | tee /etc/default/cpufrequtils > /dev/null
systemctl restart cpufrequtils
# Enable IOMMU
getIommu(){
ppv=`/usr/bin/pveversion`
OS=`echo $ppv|awk -F'-' 'NR==1{print $1}'`
ver=`echo $ppv|awk -F'/' 'NR==1{print $2}'|awk -F'-' '{print $1}'`
bver=`echo $ppv|awk -F'/' 'NR==1{print $2}'|awk -F'.' '{print $1}'`
if [ `cat /proc/cpuinfo|grep Intel|wc -l` = 0 ];then
iommu="amd_iommu=on"
else
iommu="intel_iommu=on"
fi
if [ ${bver} -gt 6 ];then
iommu=$iommu" iommu=pt pcie_acs_override=downstream"
fi
}
getIommu
if [ `grep "$iommu" /etc/default/grub|wc -l` = 0 ];then
sed -i.bak "s|quiet|quiet $iommu|" /etc/default/grub
update-grub
if [ `grep "vfio" /etc/modules|wc -l` = 0 ];then
cat <<EOF >> /etc/modules
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
EOF
fi
cat "Success need to reboot to apply! Please reboot. 安装好后需要重启系统,请稍后重启。"
else
cat "Warnning You already configed!您已经配置过这个了!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment