searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

基于塔式消费级硬件的sriov vgpu主机开通流程

2023-11-28 07:05:37
36
0

1. 内核准备环节

CentOS 7.6.1810, 最小化安装的情况下,加载以下配置以便后续使用其缓存包.

使能缓存存储:

# vi /etc/yum.conf
...
keepcache=1
...

i915 firmware需要替换为版本需要的,否则内核将无法启动:

mv /lib/firmware/i915/ /lib/firmware/i915.back
tar xzvf materials/i915.tar.gz -C /lib/firmware/

安装指定版本的内核并使能其启动:

# rpm -ivh materials/kernel-5.15.85+-1.x86_64.rpm
# vi /boot/grub2/grubenv
saved_entry=CentOS Linux (5.15.85+) 7 (Core)
# vi /etc/default/grub
Add "i915.enable_guc=0x7 udmabuf.list_limit=8192 intel_iommu=on i915.force_probe=*" to 
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet i915.enable_guc=0x7 udmabuf.list_limit=8192 intel_iommu=on i915.force_probe=*"
# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
# reboot

 检查重启后的状态:

[root@i3 ~]# dmesg | grep SR-IOV
[    1.025680] i915 0000:00:02.0: Running in SR-IOV PF mode
[root@i3 ~]# dmesg | grep GuC
[    1.157064] i915 0000:00:02.0: [drm] GuC error state capture buffer maybe too small: 2097152 < 2163708 (min = 721236)
[    1.161653] i915 0000:00:02.0: [drm] GuC firmware i915/tgl_guc_70.bin version 70.5.1
[    1.166302] i915 0000:00:02.0: [drm] GuC submission enabled
[    1.166304] i915 0000:00:02.0: [drm] GuC SLPC enabled
[    1.166591] i915 0000:00:02.0: [drm] GuC RC: enabled
[root@i3 ~]# dmesg | grep HuC
[    1.161660] i915 0000:00:02.0: [drm] HuC firmware i915/tgl_huc.bin version 7.9.3
[    1.166031] i915 0000:00:02.0: [drm] HuC authenticated

2. Qemu

安装以下编译Qemu所需要的依赖包,之后将用于编译Qemu:

# yum install -y libvirt libvirt-python libguestfs-tools virt-install pciutils gcc gcc-c++ python3 git glib2-devel pixman-devel zlib-devel libusb-devel libusb libusbx-devel pulseaudio-libs-devel libcap-ng-devel libattr-devel spice-server-devel usbredir-devel centos-release-scl  unzip OVMF
# yum install -y devtoolset-8-gcc-c++
# cp materials/ninja /usr/bin
# chmod 777 /usr/bin/ninja 

Build Qemu编译需要打开以下选项:

# tar xJvf qemu-6.2.0.tar.xz
# scl enable devtoolset-8 bash
# mkdir /opt/local
# cd qemu-6.2.0
# scl enable devtoolset-8 bash
# ./configure --target-list=x86_64-softmmu --enable-debug --disable-docs --disable-virglrenderer --prefix=/opt/local --enable-virtfs --enable-libusb --disable-debug-tcg --audio-drv-list=pa  --enable-spice --enable-usb-redir
# make -j4
# make install
# /opt/local/bin/qemu-system-x86_64 --version
QEMU emulator version 6.2.0
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

启动并使能libvirtd服务 :

# systemctl enable libvirtd
# systemctl start libvirrtd

为确保每次启动时都能自动切分i915 vf,需要在以下文件中添加自动配置脚本,编辑 /etc/rc.local:

## start of create vf
sudo modprobe i2c-algo-bit
sudo modprobe video
echo '0' | sudo tee -a /sys/bus/pci/devices/0000\:00\:02.0/sriov_drivers_autoprobe > /dev/null
echo 7 | sudo tee -a /sys/class/drm/card0/device/sriov_numvfs > /dev/null
echo '1' | sudo tee -a /sys/bus/pci/devices/0000\:00\:02.0/sriov_drivers_autoprobe > /dev/null
sudo modprobe vfio-pci
vendor=$(cat /sys/bus/pci/devices/0000:00:02.0/iommu_group/devices/0000:00:02.0/vendor)
device=$(cat /sys/bus/pci/devices/0000:00:02.0/iommu_group/devices/0000:00:02.0/device)
echo $vendor $device  | sudo tee -a /sys/bus/pci/drivers/vfio-pci/new_id
## endof create vf

3. 虚机的创建及保持

从定义的模板文件创建虚机空实例:

virsh define materials/wwin10.xml

载入自定义镜像:

# scp /var/lib/libvirt/images/winpure.qcow2 root@192.168.1.120:/var/lib/libvirt/images/

此时可通过定义好的远程访问端口访问并控制该vf instance.

4. 附录- r8168

网卡在内核下可能需要重新编译,使用以下命令:

rpm -ivh kernel-devel-5.15.85+-1.x86_64.rpm
yum remove kernel-headers
rpm -ivh kernel-headers-5.15.85+-1.x86_64.rpm
yum install -y centos-release-scl
yum install devtoolset-7
scl enable devtoolset-7 bash
cd r8168-8.051.02/src/
make
modprobe r8168

注意要将modprobe r8168 加入到 /etc/rc.local文件中

 5. 附录- 编译qemu7.1版本的详细命令

devtoolset-11需要被激活以便编译qemu7.1版本:

scl enable devtoolset-11 bash
yum install -y git glib2-devel pixman-devel zlib-devel libusb-devel libusb libusbx-devel pulseaudio-libs-devel libcap-ng-devel libattr-devel spice-server-devel usbredir-devel python3 bzip2 
 ./configure --enable-modules --target-list=x86_64-softmmu --enable-debug --disable-docs --disable-virglrenderer --prefix=/opt/local --enable-virtfs --enable-libusb --disable-debug-tcg --audio-drv-list=pa
make -j4
make install
0条评论
作者已关闭评论
yangyy
13文章数
0粉丝数
yangyy
13 文章 | 0 粉丝
原创

基于塔式消费级硬件的sriov vgpu主机开通流程

2023-11-28 07:05:37
36
0

1. 内核准备环节

CentOS 7.6.1810, 最小化安装的情况下,加载以下配置以便后续使用其缓存包.

使能缓存存储:

# vi /etc/yum.conf
...
keepcache=1
...

i915 firmware需要替换为版本需要的,否则内核将无法启动:

mv /lib/firmware/i915/ /lib/firmware/i915.back
tar xzvf materials/i915.tar.gz -C /lib/firmware/

安装指定版本的内核并使能其启动:

# rpm -ivh materials/kernel-5.15.85+-1.x86_64.rpm
# vi /boot/grub2/grubenv
saved_entry=CentOS Linux (5.15.85+) 7 (Core)
# vi /etc/default/grub
Add "i915.enable_guc=0x7 udmabuf.list_limit=8192 intel_iommu=on i915.force_probe=*" to 
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet i915.enable_guc=0x7 udmabuf.list_limit=8192 intel_iommu=on i915.force_probe=*"
# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
# reboot

 检查重启后的状态:

[root@i3 ~]# dmesg | grep SR-IOV
[    1.025680] i915 0000:00:02.0: Running in SR-IOV PF mode
[root@i3 ~]# dmesg | grep GuC
[    1.157064] i915 0000:00:02.0: [drm] GuC error state capture buffer maybe too small: 2097152 < 2163708 (min = 721236)
[    1.161653] i915 0000:00:02.0: [drm] GuC firmware i915/tgl_guc_70.bin version 70.5.1
[    1.166302] i915 0000:00:02.0: [drm] GuC submission enabled
[    1.166304] i915 0000:00:02.0: [drm] GuC SLPC enabled
[    1.166591] i915 0000:00:02.0: [drm] GuC RC: enabled
[root@i3 ~]# dmesg | grep HuC
[    1.161660] i915 0000:00:02.0: [drm] HuC firmware i915/tgl_huc.bin version 7.9.3
[    1.166031] i915 0000:00:02.0: [drm] HuC authenticated

2. Qemu

安装以下编译Qemu所需要的依赖包,之后将用于编译Qemu:

# yum install -y libvirt libvirt-python libguestfs-tools virt-install pciutils gcc gcc-c++ python3 git glib2-devel pixman-devel zlib-devel libusb-devel libusb libusbx-devel pulseaudio-libs-devel libcap-ng-devel libattr-devel spice-server-devel usbredir-devel centos-release-scl  unzip OVMF
# yum install -y devtoolset-8-gcc-c++
# cp materials/ninja /usr/bin
# chmod 777 /usr/bin/ninja 

Build Qemu编译需要打开以下选项:

# tar xJvf qemu-6.2.0.tar.xz
# scl enable devtoolset-8 bash
# mkdir /opt/local
# cd qemu-6.2.0
# scl enable devtoolset-8 bash
# ./configure --target-list=x86_64-softmmu --enable-debug --disable-docs --disable-virglrenderer --prefix=/opt/local --enable-virtfs --enable-libusb --disable-debug-tcg --audio-drv-list=pa  --enable-spice --enable-usb-redir
# make -j4
# make install
# /opt/local/bin/qemu-system-x86_64 --version
QEMU emulator version 6.2.0
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

启动并使能libvirtd服务 :

# systemctl enable libvirtd
# systemctl start libvirrtd

为确保每次启动时都能自动切分i915 vf,需要在以下文件中添加自动配置脚本,编辑 /etc/rc.local:

## start of create vf
sudo modprobe i2c-algo-bit
sudo modprobe video
echo '0' | sudo tee -a /sys/bus/pci/devices/0000\:00\:02.0/sriov_drivers_autoprobe > /dev/null
echo 7 | sudo tee -a /sys/class/drm/card0/device/sriov_numvfs > /dev/null
echo '1' | sudo tee -a /sys/bus/pci/devices/0000\:00\:02.0/sriov_drivers_autoprobe > /dev/null
sudo modprobe vfio-pci
vendor=$(cat /sys/bus/pci/devices/0000:00:02.0/iommu_group/devices/0000:00:02.0/vendor)
device=$(cat /sys/bus/pci/devices/0000:00:02.0/iommu_group/devices/0000:00:02.0/device)
echo $vendor $device  | sudo tee -a /sys/bus/pci/drivers/vfio-pci/new_id
## endof create vf

3. 虚机的创建及保持

从定义的模板文件创建虚机空实例:

virsh define materials/wwin10.xml

载入自定义镜像:

# scp /var/lib/libvirt/images/winpure.qcow2 root@192.168.1.120:/var/lib/libvirt/images/

此时可通过定义好的远程访问端口访问并控制该vf instance.

4. 附录- r8168

网卡在内核下可能需要重新编译,使用以下命令:

rpm -ivh kernel-devel-5.15.85+-1.x86_64.rpm
yum remove kernel-headers
rpm -ivh kernel-headers-5.15.85+-1.x86_64.rpm
yum install -y centos-release-scl
yum install devtoolset-7
scl enable devtoolset-7 bash
cd r8168-8.051.02/src/
make
modprobe r8168

注意要将modprobe r8168 加入到 /etc/rc.local文件中

 5. 附录- 编译qemu7.1版本的详细命令

devtoolset-11需要被激活以便编译qemu7.1版本:

scl enable devtoolset-11 bash
yum install -y git glib2-devel pixman-devel zlib-devel libusb-devel libusb libusbx-devel pulseaudio-libs-devel libcap-ng-devel libattr-devel spice-server-devel usbredir-devel python3 bzip2 
 ./configure --enable-modules --target-list=x86_64-softmmu --enable-debug --disable-docs --disable-virglrenderer --prefix=/opt/local --enable-virtfs --enable-libusb --disable-debug-tcg --audio-drv-list=pa
make -j4
make install
文章来自个人专栏
Linux
13 文章 | 1 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
0