啟動SR-IOV === # Install SR-IOV to server * 首先我們需要有SR-IOV driver然後我們要使用intel i40e driver去enable SR-IOV,但也請選擇適合你網卡的driver,我用Intel Corporation I350 Gigabit Network Connection為例 ### Install i40e driver ```shell= sudo apt install -y make gcc libelf-dev I40E_VER=2.4.10 wget https://downloadmirror.intel.com/28306/eng/i40e-${I40E_VER}.tar.gz && \ tar xvzf i40e-${I40E_VER}.tar.gz && cd i40e-${I40E_VER}/src && sudo make install && cd - ``` ### Update GRUB Settings ```shell= sudo sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/c\GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on"' /etc/default/grub sudo sed -i '/GRUB_CMDLINE_LINUX/c\GRUB_CMDLINE_LINUX="intel_iommu=on"' /etc/default/grub sudo update-grub ``` ### Setup vfio-pci module auto-load on boot ```shell= echo 'vfio-pci' | sudo tee /etc/modules-load.d/vfio-pci.conf wget -qO- https://fast.dpdk.org/rel/dpdk-17.11.2.tar.xz | sudo tar -xJC /opt sudo mv /opt/dpdk-* /opt/dpdk ``` ### Create SR-IOV Script for systemctl * 我們會寫一source code到/opt/scripts/sriov.sh我們需要佈署server 就要執行 ```shell= sudo mkdir -p /sriov-cni /opt/scripts sudo su cat << "EOF" > /opt/scripts/sriov.sh #!/bin/bash # Copied from infra/sriov.sh # Usage: ./sriov.sh ens785f0 NUM_VFS=$(cat /sys/class/net/$1/device/sriov_totalvfs) echo 0 | sudo tee /sys/class/net/$1/device/sriov_numvfs echo $NUM_VFS | sudo tee /sys/class/net/$1/device/sriov_numvfs sudo ip link set $1 up for ((i = 0 ; i < ${NUM_VFS} ; i++ )); do ip link set $1 vf $i spoofchk off; done for ((i = 0 ; i < ${NUM_VFS} ; i++ )); do ip link set dev $1 vf $i state enable; done EOF exit # Script perms sudo chmod 744 /opt/scripts/sriov.sh ``` * After we have the script, we can write a sriov.service to define a service and control this service by sudo systemctl enable sriov. ```shell= sudo su # Systemd unit to run the above script cat << "EOF" > /etc/systemd/system/sriov.service [Unit] Description=Create VFs for ens802f0 [Service] Type=oneshot ExecStart=/opt/scripts/sriov.sh ens802f0 [Install] WantedBy=default.target EOF exit # Enable the SRIOV systemd unit sudo systemctl enable sriov ```