PVE 优化 直通亿点点 🤏

PVE 换源、SR-IOV 核显直通、LXC 直通配置全流程。无图眼神版,不懂请勿乱来,PVE 炸了与我无关!

一、改源

1. 备份源

cp /etc/apt/sources.list /etc/apt/sources.list.backup

2. 添加国内源

注意:有两段代码,第一段整段一次性复制。

cat <<EOF > /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/debian/ bookworm main non-free-firmware
deb-src http://mirrors.ustc.edu.cn/debian/ bookworm main non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib
deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free-firmware
deb-src http://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free-firmware
EOF

echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list

3. PVE CT 源

sed -i.bak 's|http://download.proxmox.com|https://mirrors.ustc.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm

4. 屏蔽企业源

sed -i 's/^deb https:\/\/enterprise.proxmox.com\/debian\/pve/#deb https:\/\/enterprise.proxmox.com\/debian\/pve/' /etc/apt/sources.list.d/pve-enterprise.list

5. 屏蔽 Ceph 源

sed -i 's/^deb https:\/\/enterprise.proxmox.com\/debian\/ceph-quincy/#deb https:\/\/enterprise.proxmox.com\/debian\/ceph-quincy/' /etc/apt/sources.list.d/ceph.list

6. 更新源

apt-get update

二、直通 SR-IOV

1. 查看 PVE 当前版本

pveversion

2. 安装当前内核版本的头文件

apt install pve-headers-6.x.x-x-pve

三、配置直通的基础环境

1. 开启 IOMMU 直通功能

echo -e "vfio\nvfio_iommu_type1\nvfio_pci\nvfio_virqfd" | tee -a /etc/modules

2. 增加虚拟化驱动,加载 vfio 系统模块

echo -e "vfio\nvfio_iommu_type1\nvfio_pci\nvfio_virqfd" | tee -a /etc/modules

3. 取消屏蔽显卡驱动

nano /etc/modprobe.d/blacklist.conf

全部删除(如果有的话)。

四、更新 Grub 引导配置和 initramfs

update-grub
update-initramfs -u -k all

重启:

reboot

五、配置开启 SR-IOV 虚拟化核显

1. 安装编译环境依赖

apt-get install --no-install-recommends git mokutil sysfsutils -y
apt install --reinstall dkms -y

2. 添加一个临时的 KERNEL 环境变量

KERNEL=$(uname -r); KERNEL=${KERNEL%-pve}

3. 克隆项目

一行!一行!输入!!!

git clone https://github.com/strongtz/i915-sriov-dkms.git
cd i915-sriov-dkms/
sed -i 's/"@_PKGBASE@"/"i915-sriov-dkms"/g' ~/i915-sriov-dkms/dkms.conf
sed -i "s/^PACKAGE_VERSION=.*/PACKAGE_VERSION=\"$KERNEL\"/" ~/i915-sriov-dkms/dkms.conf

4. 检查 dkms.conf 配置

cat ~/i915-sriov-dkms/dkms.conf

5. 创建符号链接

dkms add .

6. 进入链接到的目录

cd /usr/src/i915-sriov-dkms-$KERNEL

7. 查看已安装的 DKMS 模块

dkms status

8. 编译内核加入 i915-sriov 驱动

dkms install -m i915-sriov-dkms -v $KERNEL -k $(uname -r) --force -j 1

注意:编译过程时间稍长,需要等待。

检查编译是否成功:

dkms status

9. 查询当前核显 ID

lspci | grep VGA

10. 修改核显 ID 和虚拟核显数

echo "devices/pci0000:00/0000:00:02.0/sriov_numvfs = 3" > /etc/sysfs.conf
# 0000:00:02.0 这个修改为你的 ID
# sriov_numvfs = 3 里面的 3 修改为其他值,不要超过 7

重启:

reboot

11. 检查是否开启成功

lspci | grep VGA

项目地址:https://github.com/strongtz/i915-sriov-dkms.git

六、LXC 直通核显配置

在 LXC 配置文件中添加:

lxc.cgroup2.devices.allow: c 226:0 rwm
lxc.cgroup2.devices.allow: c 226:128 rwm
lxc.mount.entry: /dev/dri/card0 dev/dri/card0 none bind,optional,create=file
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
lxc.apparmor.profile: unconfined
lxc.cap.drop:
← 返回首页