linux pci passthrough

ubuntu 虚拟机

jeff@ubuntu:~/workstaging/qemu-gdb/start_qemu$ cat start_qemu.sh
qemu-system-x86_64 -s \
-kernel /home/jeff/workstation/kernel_src/linux-hwe-5.11-5.11.0/arch/x86_64/boot/bzImage \
-boot c -m 2049M \
-device e1000,netdev=brdev0 \
-netdev bridge,id=brdev0,br=virbr0 \
-hda /home/jeff/workstaging/qemu-gdb/make_rootfs/rootfs.ext4 \
-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \
-serial mon:stdio -display none

自己编译内核模块和制作rootfs,具体可以参考我的github:make_rootfs

centos 虚拟机

安装包

yum groupinstall "Virtualization Host"

使用qemu-kvm命令行模式

/usr/libexec/qemu-kvm -s \
-kernel /home/jeff/workstation/kernel_src/linux-hwe-5.11-5.11.0/arch/x86_64/boot/bzImage \
-boot c -m 2049M \
-device e1000,netdev=brdev0 \
-netdev bridge,id=brdev0,br=virbr0 \
-hda /home/jeff/workstaging/qemu-gdb/make_rootfs/rootfs.ext4 \
-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \
-serial mon:stdio -display none

使用virt-install导入已有硬盘 --import

virt-install -n jeff-kvm-1 --memory 2048  --vcpus 4 \
--disk /root/rootfs \
--import \
--nographics \
--os-type=generic \
--graphics vnc,port=5999 \
--noautoconsole \
--noreboot \
--network bridge=virbr0 \
--boot kernel=/root/bzImage, \
kernel_args="root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" 

AMD开启虚拟化

  • BIOS开启SVM虚拟化功能
    在cpu高级设置,开启svm的功能
  • 内核参数
    amd_iommu=force_enable iommu.passthrough=1
  • 验证是否开启成功
    [root@localhost ~]# dmesg | grep IOMMU
    [    0.495195] pci 0000:00:00.2: IOMMU performance counters supported
    [    0.495831] pci 0000:00:00.2: Found IOMMU cap 0x40
    [    0.502960] perf/amd_iommu: Detected AMD IOMMU #0 (2 banks, 4 counters/bank).

    passthrough网卡到虚拟机

  • 查看810的pci的id号
    [root@localhost ~]# lspci | grep 810
    01:00.0 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
    01:00.1 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
  • detach pci设备
    [root@localhost ~]#  virsh nodedev-detach pci_0000_01_00_0
    Device pci_0000_01_00_0 detached
    [root@localhost ~]#  virsh nodedev-detach pci_0000_01_00_1
    Device pci_0000_01_00_1 detached
  • attach 网卡设备
    [root@localhost jeff.zhao]# virsh attach-device jeff-kvm passthrough.xml <--live>
    Device attached successfully

附件:

[root@localhost jeff.zhao]# cat passthrough.xml
<hostdev mode='subsystem' type='pci' managed='no'>
  <driver name='vfio'/>
  <source>
    <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
  </source>
  <alias name='hostdev0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</hostdev>

qemu命令行模式

-device vfio-pci,host=01:00.1,bus=pcie.1,addr=00.5
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇