[{"data":1,"prerenderedAt":1423},["ShallowReactive",2],{"wiki-page-/en-us/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji":3,"wiki-doc-items-/en-us/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji":1356,"language-switcher-data-/en-us/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji":1407,"wiki-i18n-paths-/en-us/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji":1422},{"id":4,"title":5,"body":6,"canonicalPath":1337,"chapter":1338,"chapterSort":1339,"date":1340,"description":12,"docI18nKey":1341,"docKey":1342,"docRoot":1343,"docTitle":1344,"extension":1345,"i18nKey":1346,"isBlogPost":1347,"isWikiDoc":214,"isWikiIndex":1347,"layout":1348,"legacyPath":1348,"locale":1349,"localeSlug":1350,"meta":1351,"navigation":214,"path":1337,"seo":1352,"sourcePath":1353,"sourceStem":1346,"stem":1354,"wikiDepth":35,"__hash__":1355},"content/_i18n/en-us/wiki/2024-03-30-Linux教程/ch7-QEMU-KVM虚拟机.md","QEMU-KVM virtual machine",{"type":7,"value":8,"toc":1328},"minimark",[9,13,18,21,87,90,124,131,154,161,165,168,187,202,205,261,264,294,298,301,326,333,337,344,386,400,406,409,412,423,429,444,447,735,738,756,760,763,787,790,799,802,806,809,818,825,829,834,837,842,847,858,882,889,894,897,937,940,965,968,978,1067,1070,1082,1092,1097,1100,1109,1123,1128,1144,1149,1192,1200,1203,1226,1229,1251,1254,1274,1281,1286,1292,1324],[10,11,12],"p",{},"QEMU-KVM is a high-performance virtual machine. The following uses the installation of Rocky Linux 9 as an example.",[14,15,17],"h3",{"id":16},"install-the-required-software","Install the required software",[10,19,20],{},"Make sure the host has QEMU, KVM, and related tools installed. For Debian/Ubuntu-based systems, run the following command:",[22,23,28],"pre",{"className":24,"code":25,"language":26,"meta":27,"style":27},"language-bash shiki shiki-themes github-light github-dark","sudo apt update\nsudo apt install qemu-kvm qemu-img virt-manager virt-install virt-viewer libvirt libvirt-daemon libvirt-daemon-qemu bridge-utils virglrenderer\n","bash","",[29,30,31,47],"code",{"__ignoreMap":27},[32,33,36,40,44],"span",{"class":34,"line":35},"line",1,[32,37,39],{"class":38},"sScJk","sudo",[32,41,43],{"class":42},"sZZnC"," apt",[32,45,46],{"class":42}," update\n",[32,48,50,52,54,57,60,63,66,69,72,75,78,81,84],{"class":34,"line":49},2,[32,51,39],{"class":38},[32,53,43],{"class":42},[32,55,56],{"class":42}," install",[32,58,59],{"class":42}," qemu-kvm",[32,61,62],{"class":42}," qemu-img",[32,64,65],{"class":42}," virt-manager",[32,67,68],{"class":42}," virt-install",[32,70,71],{"class":42}," virt-viewer",[32,73,74],{"class":42}," libvirt",[32,76,77],{"class":42}," libvirt-daemon",[32,79,80],{"class":42}," libvirt-daemon-qemu",[32,82,83],{"class":42}," bridge-utils",[32,85,86],{"class":42}," virglrenderer\n",[10,88,89],{},"For systems based on Fedora/CentOS/Rocky Linux, the command may be:",[22,91,93],{"className":24,"code":92,"language":26,"meta":27,"style":27},"sudo dnf install qemu-kvm qemu-img virt-manager virt-install virt-viewer libvirt libvirt-daemon libvirt-daemon-qemu bridge-utils virglrenderer\n",[29,94,95],{"__ignoreMap":27},[32,96,97,99,102,104,106,108,110,112,114,116,118,120,122],{"class":34,"line":35},[32,98,39],{"class":38},[32,100,101],{"class":42}," dnf",[32,103,56],{"class":42},[32,105,59],{"class":42},[32,107,62],{"class":42},[32,109,65],{"class":42},[32,111,68],{"class":42},[32,113,71],{"class":42},[32,115,74],{"class":42},[32,117,77],{"class":42},[32,119,80],{"class":42},[32,121,83],{"class":42},[32,123,86],{"class":42},[10,125,126,127,130],{},"After installation, ensure the current user is in the ",[29,128,129],{},"kvm"," group (otherwise they may not have permission to use KVM acceleration):",[22,132,134],{"className":24,"code":133,"language":26,"meta":27,"style":27},"sudo usermod -aG kvm $USER\n",[29,135,136],{"__ignoreMap":27},[32,137,138,140,143,147,150],{"class":34,"line":35},[32,139,39],{"class":38},[32,141,142],{"class":42}," usermod",[32,144,146],{"class":145},"sj4cs"," -aG",[32,148,149],{"class":42}," kvm",[32,151,153],{"class":152},"sVt8B"," $USER\n",[10,155,156,160],{},[157,158,159],"strong",{},"Note:"," You may need to log out and log back in for the group change to take effect.",[14,162,164],{"id":163},"enable-kvm-hardware-acceleration","Enable KVM hardware acceleration",[10,166,167],{},"Run the following command to check if KVM is enabled:",[22,169,171],{"className":24,"code":170,"language":26,"meta":27,"style":27},"egrep -c '(vmx|svm)' /proc/cpuinfo\n",[29,172,173],{"__ignoreMap":27},[32,174,175,178,181,184],{"class":34,"line":35},[32,176,177],{"class":38},"egrep",[32,179,180],{"class":145}," -c",[32,182,183],{"class":42}," '(vmx|svm)'",[32,185,186],{"class":42}," /proc/cpuinfo\n",[10,188,189,190,193,194,197,198,201],{},"If the output is ",[29,191,192],{},"0",", it means the CPU does not support KVM or VT-x (Intel) / SVM (AMD) is not enabled. You need to enable ",[157,195,196],{},"Intel VT-x"," or ",[157,199,200],{},"AMD SVM"," in the BIOS.",[10,203,204],{},"Then check whether the KVM module is loaded:",[22,206,208],{"className":24,"code":207,"language":26,"meta":27,"style":27},"\n# 验证 KVM 加速可用\nlsmod | grep kvm\n\n# 验证当前用户有权限访问 /dev/kvm\nls -l /dev/kvm\n",[29,209,210,216,222,238,243,249],{"__ignoreMap":27},[32,211,212],{"class":34,"line":35},[32,213,215],{"emptyLinePlaceholder":214},true,"\n",[32,217,218],{"class":34,"line":49},[32,219,221],{"class":220},"sJ8bj","# 验证 KVM 加速可用\n",[32,223,225,228,232,235],{"class":34,"line":224},3,[32,226,227],{"class":38},"lsmod",[32,229,231],{"class":230},"szBVR"," |",[32,233,234],{"class":38}," grep",[32,236,237],{"class":42}," kvm\n",[32,239,241],{"class":34,"line":240},4,[32,242,215],{"emptyLinePlaceholder":214},[32,244,246],{"class":34,"line":245},5,[32,247,248],{"class":220},"# 验证当前用户有权限访问 /dev/kvm\n",[32,250,252,255,258],{"class":34,"line":251},6,[32,253,254],{"class":38},"ls",[32,256,257],{"class":145}," -l",[32,259,260],{"class":42}," /dev/kvm\n",[10,262,263],{},"If there is no output, load the KVM module:",[22,265,267],{"className":24,"code":266,"language":26,"meta":27,"style":27},"sudo modprobe kvm_intel  # Intel 处理器\nsudo modprobe kvm_amd    # AMD 处理器\n",[29,268,269,282],{"__ignoreMap":27},[32,270,271,273,276,279],{"class":34,"line":35},[32,272,39],{"class":38},[32,274,275],{"class":42}," modprobe",[32,277,278],{"class":42}," kvm_intel",[32,280,281],{"class":220},"  # Intel 处理器\n",[32,283,284,286,288,291],{"class":34,"line":49},[32,285,39],{"class":38},[32,287,275],{"class":42},[32,289,290],{"class":42}," kvm_amd",[32,292,293],{"class":220},"    # AMD 处理器\n",[14,295,297],{"id":296},"create-a-virtual-hard-disk-file","Create a virtual hard disk file",[10,299,300],{},"You need to create a hard disk image file for the virtual machine. Here, using qcow2 format and 100GB as an example (you can adjust the size as needed). Run the following in the terminal:",[22,302,304],{"className":24,"code":303,"language":26,"meta":27,"style":27},"qemu-img create -f qcow2 disk.qcow2 100G\n",[29,305,306],{"__ignoreMap":27},[32,307,308,311,314,317,320,323],{"class":34,"line":35},[32,309,310],{"class":38},"qemu-img",[32,312,313],{"class":42}," create",[32,315,316],{"class":145}," -f",[32,318,319],{"class":42}," qcow2",[32,321,322],{"class":42}," disk.qcow2",[32,324,325],{"class":42}," 100G\n",[10,327,328,329,332],{},"This will generate a virtual hard disk file named ",[29,330,331],{},"disk.qcow2"," in the current directory.",[14,334,336],{"id":335},"prepare-the-ovmf-uefi-firmware-files","Prepare the OVMF (UEFI firmware) files.",[10,338,339,340,343],{},"Install the ",[29,341,342],{},"OVMF"," package. For example, on Ubuntu it can be installed with the following command:",[22,345,347],{"className":24,"code":346,"language":26,"meta":27,"style":27},"\n# 一般电脑都默认安装过了\nsudo apt install ovmf # Debian/Ubuntu\nsudo dnf install edk2-ovmf # RHEL/CentOS/Fedora\n",[29,348,349,353,358,372],{"__ignoreMap":27},[32,350,351],{"class":34,"line":35},[32,352,215],{"emptyLinePlaceholder":214},[32,354,355],{"class":34,"line":49},[32,356,357],{"class":220},"# 一般电脑都默认安装过了\n",[32,359,360,362,364,366,369],{"class":34,"line":224},[32,361,39],{"class":38},[32,363,43],{"class":42},[32,365,56],{"class":42},[32,367,368],{"class":42}," ovmf",[32,370,371],{"class":220}," # Debian/Ubuntu\n",[32,373,374,376,378,380,383],{"class":34,"line":240},[32,375,39],{"class":38},[32,377,101],{"class":42},[32,379,56],{"class":42},[32,381,382],{"class":42}," edk2-ovmf",[32,384,385],{"class":220}," # RHEL/CentOS/Fedora\n",[10,387,388,389,197,392,395,396,399],{},"After installation, locate the file path, usually at ",[29,390,391],{},"/usr/share/OVMF/OVMF_CODE.fd",[29,393,394],{},"/usr/share/ovmf/OVMF.fd",". Use the correct path directly in the command. (There is an example in the script below; you just need to ensure that these two files are present under your ",[29,397,398],{},"/usr/share/OVMF/",".)",[10,401,402],{},[403,404],"img",{"alt":27,"src":405},"https://cdn.tungchiahui.cn/tungwebsite/assets/images/2024/03/30/image329.webp",[10,407,408],{},"You can also download the following file:",[10,410,411],{},"Unable to display this content outside of Feishu documents for now.",[413,414,415],"ol",{},[416,417,418,419,422],"li",{},"Write or adjust the ",[29,420,421],{},"run.sh"," script.",[10,424,425,426,428],{},"Write the following content into your ",[29,427,421],{}," file (you can use a text editor).",[22,430,432],{"className":24,"code":431,"language":26,"meta":27,"style":27},"sudo vim ./run.sh\n",[29,433,434],{"__ignoreMap":27},[32,435,436,438,441],{"class":34,"line":35},[32,437,39],{"class":38},[32,439,440],{"class":42}," vim",[32,442,443],{"class":42}," ./run.sh\n",[10,445,446],{},"The following script example uses QEMU to start a virtual machine and load an ISO image:",[22,448,450],{"className":24,"code":449,"language":26,"meta":27,"style":27},"#!/bin/bash\n\nqemu-system-x86_64 \\\n    -machine q35,vmport=off,kernel_irqchip=on \\\n    -accel kvm \\\n    -cpu host,kvm=on,vmx=on,migratable=on,+invtsc \\\n    -smp 8,sockets=1,cores=4,threads=2 \\\n    -m 8G,slots=4,maxmem=32G \\\n    -device virtio-gpu-gl-pci,max_outputs=1 \\\n    -vga none \\\n    -display sdl,gl=on \\\n    -audiodev pa,id=pa1,server=unix:/run/user/1000/pulse/native \\\n    -device ich9-intel-hda \\\n    -device hda-micro,audiodev=pa1 \\\n    -device qemu-xhci,id=xhci \\\n    -device virtio-tablet-pci \\\n    -device usb-kbd,bus=xhci.0 \\\n    -bios OVMF-pure-efi64.fd \\\n    -boot d \\\n    -blockdev driver=qcow2,node-name=disk1,file.driver=file,file.cache.direct=on,file.aio=io_uring,file.filename=disk.qcow2 \\\n    -device virtio-blk-pci,drive=disk1 \\\n    -drive file=kubuntu-20.04.6-desktop-amd64.iso,media=cdrom,if=none,id=cdrom \\\n    -device usb-storage,drive=cdrom,removable=on \\\n    -nic user,model=virtio-net-pci,hostfwd=tcp::8022-:22 \\\n    -monitor stdio \\\n    -parallel none \\\n    -serial none \\\n    -msg timestamp=on\n\n",[29,451,452,457,461,469,479,488,498,512,523,537,548,559,570,580,590,600,610,620,631,642,653,663,674,684,695,706,716,726],{"__ignoreMap":27},[32,453,454],{"class":34,"line":35},[32,455,456],{"class":220},"#!/bin/bash\n",[32,458,459],{"class":34,"line":49},[32,460,215],{"emptyLinePlaceholder":214},[32,462,463,466],{"class":34,"line":224},[32,464,465],{"class":38},"qemu-system-x86_64",[32,467,468],{"class":145}," \\\n",[32,470,471,474,477],{"class":34,"line":240},[32,472,473],{"class":145},"    -machine",[32,475,476],{"class":42}," q35,vmport=off,kernel_irqchip=on",[32,478,468],{"class":145},[32,480,481,484,486],{"class":34,"line":245},[32,482,483],{"class":145},"    -accel",[32,485,149],{"class":42},[32,487,468],{"class":145},[32,489,490,493,496],{"class":34,"line":251},[32,491,492],{"class":145},"    -cpu",[32,494,495],{"class":42}," host,kvm=on,vmx=on,migratable=on,+invtsc",[32,497,468],{"class":145},[32,499,501,504,507,510],{"class":34,"line":500},7,[32,502,503],{"class":145},"    -smp",[32,505,506],{"class":42}," 8,sockets=1,cores=4,threads=",[32,508,509],{"class":145},"2",[32,511,468],{"class":145},[32,513,515,518,521],{"class":34,"line":514},8,[32,516,517],{"class":145},"    -m",[32,519,520],{"class":42}," 8G,slots=4,maxmem=32G",[32,522,468],{"class":145},[32,524,526,529,532,535],{"class":34,"line":525},9,[32,527,528],{"class":145},"    -device",[32,530,531],{"class":42}," virtio-gpu-gl-pci,max_outputs=",[32,533,534],{"class":145},"1",[32,536,468],{"class":145},[32,538,540,543,546],{"class":34,"line":539},10,[32,541,542],{"class":145},"    -vga",[32,544,545],{"class":42}," none",[32,547,468],{"class":145},[32,549,551,554,557],{"class":34,"line":550},11,[32,552,553],{"class":145},"    -display",[32,555,556],{"class":42}," sdl,gl=on",[32,558,468],{"class":145},[32,560,562,565,568],{"class":34,"line":561},12,[32,563,564],{"class":145},"    -audiodev",[32,566,567],{"class":42}," pa,id=pa1,server=unix:/run/user/1000/pulse/native",[32,569,468],{"class":145},[32,571,573,575,578],{"class":34,"line":572},13,[32,574,528],{"class":145},[32,576,577],{"class":42}," ich9-intel-hda",[32,579,468],{"class":145},[32,581,583,585,588],{"class":34,"line":582},14,[32,584,528],{"class":145},[32,586,587],{"class":42}," hda-micro,audiodev=pa1",[32,589,468],{"class":145},[32,591,593,595,598],{"class":34,"line":592},15,[32,594,528],{"class":145},[32,596,597],{"class":42}," qemu-xhci,id=xhci",[32,599,468],{"class":145},[32,601,603,605,608],{"class":34,"line":602},16,[32,604,528],{"class":145},[32,606,607],{"class":42}," virtio-tablet-pci",[32,609,468],{"class":145},[32,611,613,615,618],{"class":34,"line":612},17,[32,614,528],{"class":145},[32,616,617],{"class":42}," usb-kbd,bus=xhci.0",[32,619,468],{"class":145},[32,621,623,626,629],{"class":34,"line":622},18,[32,624,625],{"class":145},"    -bios",[32,627,628],{"class":42}," OVMF-pure-efi64.fd",[32,630,468],{"class":145},[32,632,634,637,640],{"class":34,"line":633},19,[32,635,636],{"class":145},"    -boot",[32,638,639],{"class":42}," d",[32,641,468],{"class":145},[32,643,645,648,651],{"class":34,"line":644},20,[32,646,647],{"class":145},"    -blockdev",[32,649,650],{"class":42}," driver=qcow2,node-name=disk1,file.driver=file,file.cache.direct=on,file.aio=io_uring,file.filename=disk.qcow2",[32,652,468],{"class":145},[32,654,656,658,661],{"class":34,"line":655},21,[32,657,528],{"class":145},[32,659,660],{"class":42}," virtio-blk-pci,drive=disk1",[32,662,468],{"class":145},[32,664,666,669,672],{"class":34,"line":665},22,[32,667,668],{"class":145},"    -drive",[32,670,671],{"class":42}," file=kubuntu-20.04.6-desktop-amd64.iso,media=cdrom,if=none,id=cdrom",[32,673,468],{"class":145},[32,675,677,679,682],{"class":34,"line":676},23,[32,678,528],{"class":145},[32,680,681],{"class":42}," usb-storage,drive=cdrom,removable=on",[32,683,468],{"class":145},[32,685,687,690,693],{"class":34,"line":686},24,[32,688,689],{"class":145},"    -nic",[32,691,692],{"class":42}," user,model=virtio-net-pci,hostfwd=tcp::8022-:22",[32,694,468],{"class":145},[32,696,698,701,704],{"class":34,"line":697},25,[32,699,700],{"class":145},"    -monitor",[32,702,703],{"class":42}," stdio",[32,705,468],{"class":145},[32,707,709,712,714],{"class":34,"line":708},26,[32,710,711],{"class":145},"    -parallel",[32,713,545],{"class":42},[32,715,468],{"class":145},[32,717,719,722,724],{"class":34,"line":718},27,[32,720,721],{"class":145},"    -serial",[32,723,545],{"class":42},[32,725,468],{"class":145},[32,727,729,732],{"class":34,"line":728},28,[32,730,731],{"class":145},"    -msg",[32,733,734],{"class":42}," timestamp=on\n",[10,736,737],{},"After saving, give the script execute permissions:",[22,739,741],{"className":24,"code":740,"language":26,"meta":27,"style":27},"sudo chmod +x run.sh\n",[29,742,743],{"__ignoreMap":27},[32,744,745,747,750,753],{"class":34,"line":35},[32,746,39],{"class":38},[32,748,749],{"class":42}," chmod",[32,751,752],{"class":42}," +x",[32,754,755],{"class":42}," run.sh\n",[14,757,759],{"id":758},"start-the-virtual-machine","Start the virtual machine.",[10,761,762],{},"Make sure the following files are in the current directory:",[764,765,766,770,775,781],"ul",{},[416,767,768],{},[29,769,421],{},[416,771,772,774],{},[29,773,331],{}," (the virtual hard disk you just created)",[416,776,777,780],{},[29,778,779],{},"Rocky-9.4-x86_64-dvd.iso"," (Rocky Linux 9 Installation ISO)",[416,782,783,786],{},[29,784,785],{},"OVMF-pure-efi64.fd"," file",[10,788,789],{},"Then run the script in the terminal:",[22,791,793],{"className":24,"code":792,"language":26,"meta":27,"style":27},"./run.sh\n",[29,794,795],{"__ignoreMap":27},[32,796,797],{"class":34,"line":35},[32,798,792],{"class":38},[10,800,801],{},"At this point, QEMU should launch a window and load the ISO image to enter the installation interface.",[14,803,805],{"id":804},"install-the-system","Install the system",[10,807,808],{},"In the virtual machine window, you will see the Linux installation screen. Follow the steps in the installation wizard to complete the installation. After installation, you may need to adjust the boot order to set the hard drive as the boot medium (if it still defaults to booting from the CD).",[10,810,811,814,815,817],{},[157,812,813],{},"Tip:"," After installing the system, shut down the virtual machine, then modify ",[29,816,421],{}," to remove the ISO image or change it to an optional boot device. This way, the next time you start up, it will boot directly from the hard drive.",[10,819,820,821,824],{},"For example, remove ",[29,822,823],{},"-drive file=Rocky-9.5-x86_64-dvd.iso,media=cdrom",", or replace it with a startup sequence parameter.",[14,826,828],{"id":827},"other-operations","Other operations",[830,831,833],"h4",{"id":832},"gpu-passthrough-proceed-with-caution-do-not-attempt-if-you-are-unsure","GPU Passthrough (Proceed with caution; do not attempt if you are unsure)",[10,835,836],{},"This operation means dedicating the GPU entirely to the virtual machine, so the physical host machine can no longer use the graphics card.",[413,838,839],{},[416,840,841],{},"Host and IOMMU Configuration",[10,843,844],{},[157,845,846],{},"(1) Enable IOMMU (using Intel as an example)",[10,848,849,850,853,854,857],{},"Edit ",[29,851,852],{},"/etc/default/grub",", add to ",[29,855,856],{},"GRUB_CMDLINE_LINUX_DEFAULT",":",[22,859,861],{"className":24,"code":860,"language":26,"meta":27,"style":27},"intel_iommu=on iommu=pt\n",[29,862,863],{"__ignoreMap":27},[32,864,865,868,871,874,877,879],{"class":34,"line":35},[32,866,867],{"class":152},"intel_iommu",[32,869,870],{"class":230},"=",[32,872,873],{"class":42},"on",[32,875,876],{"class":152}," iommu",[32,878,870],{"class":230},[32,880,881],{"class":42},"pt\n",[10,883,884,885,888],{},"For AMD hosts, set ",[29,886,887],{},"amd_iommu=on",".",[10,890,891],{},[403,892],{"alt":27,"src":893},"https://cdn.tungchiahui.cn/tungwebsite/assets/images/2024/03/30/image330.webp",[10,895,896],{},"After updating grub, restart:",[22,898,900],{"className":24,"code":899,"language":26,"meta":27,"style":27},"sudo grub2-mkconfig -o /boot/grub2/grub.cfg   # CentOS/Fedora/Rocky 系列\n\n# 或者\nsudo update-grub   # Ubuntu/Debian 系统\n",[29,901,902,918,922,927],{"__ignoreMap":27},[32,903,904,906,909,912,915],{"class":34,"line":35},[32,905,39],{"class":38},[32,907,908],{"class":42}," grub2-mkconfig",[32,910,911],{"class":145}," -o",[32,913,914],{"class":42}," /boot/grub2/grub.cfg",[32,916,917],{"class":220},"   # CentOS/Fedora/Rocky 系列\n",[32,919,920],{"class":34,"line":49},[32,921,215],{"emptyLinePlaceholder":214},[32,923,924],{"class":34,"line":224},[32,925,926],{"class":220},"# 或者\n",[32,928,929,931,934],{"class":34,"line":240},[32,930,39],{"class":38},[32,932,933],{"class":42}," update-grub",[32,935,936],{"class":220},"   # Ubuntu/Debian 系统\n",[10,938,939],{},"You can use the following command after a reboot to confirm whether IOMMU is enabled:",[22,941,943],{"className":24,"code":942,"language":26,"meta":27,"style":27},"dmesg | grep -e DMAR -e IOMMU\n",[29,944,945],{"__ignoreMap":27},[32,946,947,950,952,954,957,960,962],{"class":34,"line":35},[32,948,949],{"class":38},"dmesg",[32,951,231],{"class":230},[32,953,234],{"class":38},[32,955,956],{"class":145}," -e",[32,958,959],{"class":42}," DMAR",[32,961,956],{"class":145},[32,963,964],{"class":42}," IOMMU\n",[10,966,967],{},"If you see information like \"DMAR: IOMMU enabled\", it means it has taken effect.",[10,969,970,973,974,977],{},[157,971,972],{},"(2) Find your NVIDIA graphics card device ID"," Use ",[29,975,976],{},"lspci -nn|","grep NVIDIA` searches for graphics cards, for example:",[22,979,981],{"className":24,"code":980,"language":26,"meta":27,"style":27},"tungchiahui@Dell-G15-5511:~/Downloads$ lspci -nn | grep NVIDIA \n01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / M\nax-Q] [10de:2560] (rev a1) \n01:00.1 Audio device [0403]: NVIDIA Corporation GA106 High Definition Audio Controller [10de:228\ne] (rev a1)\n",[29,982,983,1004,1027,1041,1055],{"__ignoreMap":27},[32,984,985,988,991,994,996,998,1001],{"class":34,"line":35},[32,986,987],{"class":38},"tungchiahui@Dell-G15-5511:~/Downloads$",[32,989,990],{"class":42}," lspci",[32,992,993],{"class":145}," -nn",[32,995,231],{"class":230},[32,997,234],{"class":38},[32,999,1000],{"class":42}," NVIDIA",[32,1002,1003],{"class":152}," \n",[32,1005,1006,1009,1012,1015,1018,1021,1024],{"class":34,"line":49},[32,1007,1008],{"class":38},"01:00.0",[32,1010,1011],{"class":42}," VGA",[32,1013,1014],{"class":42}," compatible",[32,1016,1017],{"class":42}," controller",[32,1019,1020],{"class":152}," [0300]: NVIDIA Corporation GA106M [GeForce RTX ",[32,1022,1023],{"class":145},"3060",[32,1025,1026],{"class":152}," Mobile / M\n",[32,1028,1029,1032,1035,1038],{"class":34,"line":224},[32,1030,1031],{"class":152},"ax-Q] [10de:2560] (",[32,1033,1034],{"class":38},"rev",[32,1036,1037],{"class":42}," a1",[32,1039,1040],{"class":152},") \n",[32,1042,1043,1046,1049,1052],{"class":34,"line":240},[32,1044,1045],{"class":38},"01:00.1",[32,1047,1048],{"class":42}," Audio",[32,1050,1051],{"class":42}," device",[32,1053,1054],{"class":152}," [0403]: NVIDIA Corporation GA106 High Definition Audio Controller [10de:228\n",[32,1056,1057,1060,1062,1064],{"class":34,"line":245},[32,1058,1059],{"class":152},"e] (",[32,1061,1034],{"class":38},[32,1063,1037],{"class":42},[32,1065,1066],{"class":152},")\n",[10,1068,1069],{},"Write down the PCI address and device ID above.",[10,1071,1072,1075,1076,1078,1079],{},[157,1073,1074],{},"Graphics Card"," PCI Address: ",[29,1077,1008],{}," Device ID: ",[29,1080,1081],{},"10de:2560",[10,1083,1084,1075,1087,1078,1089],{},[157,1085,1086],{},"Graphics Card Audio",[29,1088,1045],{},[29,1090,1091],{},"10de:228e",[10,1093,1094],{},[157,1095,1096],{},"(3) Binding the device to the vfio driver",[10,1098,1099],{},"Another way is to create a modprobe configuration file so that vfio-pci binds these devices at load time.",[413,1101,1102],{},[416,1103,1104,1105,1108],{},"Create the file (e.g., ",[29,1106,1107],{},"/etc/modprobe.d/vfio.conf","):",[22,1110,1112],{"className":24,"code":1111,"language":26,"meta":27,"style":27},"sudo vim /etc/modprobe.d/vfio.conf\n",[29,1113,1114],{"__ignoreMap":27},[32,1115,1116,1118,1120],{"class":34,"line":35},[32,1117,39],{"class":38},[32,1119,440],{"class":42},[32,1121,1122],{"class":42}," /etc/modprobe.d/vfio.conf\n",[413,1124,1125],{"start":49},[416,1126,1127],{},"Write into the file:",[22,1129,1131],{"className":24,"code":1130,"language":26,"meta":27,"style":27},"options vfio-pci ids=10de:2560,10de:228e\n",[29,1132,1133],{"__ignoreMap":27},[32,1134,1135,1138,1141],{"class":34,"line":35},[32,1136,1137],{"class":38},"options",[32,1139,1140],{"class":42}," vfio-pci",[32,1142,1143],{"class":42}," ids=10de:2560,10de:228e\n",[413,1145,1146],{"start":224},[416,1147,1148],{},"After saving the file, update the initramfs:",[22,1150,1152],{"className":24,"code":1151,"language":26,"meta":27,"style":27},"\n# debian系选这个\nsudo update-initramfs -u\n\n# 红帽系选这个\nsudo dracut --force\n",[29,1153,1154,1158,1163,1173,1177,1182],{"__ignoreMap":27},[32,1155,1156],{"class":34,"line":35},[32,1157,215],{"emptyLinePlaceholder":214},[32,1159,1160],{"class":34,"line":49},[32,1161,1162],{"class":220},"# debian系选这个\n",[32,1164,1165,1167,1170],{"class":34,"line":224},[32,1166,39],{"class":38},[32,1168,1169],{"class":42}," update-initramfs",[32,1171,1172],{"class":145}," -u\n",[32,1174,1175],{"class":34,"line":240},[32,1176,215],{"emptyLinePlaceholder":214},[32,1178,1179],{"class":34,"line":245},[32,1180,1181],{"class":220},"# 红帽系选这个\n",[32,1183,1184,1186,1189],{"class":34,"line":251},[32,1185,39],{"class":38},[32,1187,1188],{"class":42}," dracut",[32,1190,1191],{"class":145}," --force\n",[413,1193,1194,1197],{"start":240},[416,1195,1196],{},"Restart the system.",[416,1198,1199],{},"Check the device binding status.",[10,1201,1202],{},"After rebooting, you can use the following command to check whether the device has been taken over by the vfio-pci driver:",[22,1204,1206],{"className":24,"code":1205,"language":26,"meta":27,"style":27},"lspci -nnk | grep -A3 \"10de:2560\"\n",[29,1207,1208],{"__ignoreMap":27},[32,1209,1210,1213,1216,1218,1220,1223],{"class":34,"line":35},[32,1211,1212],{"class":38},"lspci",[32,1214,1215],{"class":145}," -nnk",[32,1217,231],{"class":230},[32,1219,234],{"class":38},[32,1221,1222],{"class":145}," -A3",[32,1224,1225],{"class":42}," \"10de:2560\"\n",[10,1227,1228],{},"You should see something like:",[22,1230,1234],{"className":1231,"code":1232,"language":1233,"meta":27,"style":27},"language-YAML shiki shiki-themes github-light github-dark","01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] [10de:2560]\n        Subsystem: ...\n        Kernel driver in use: vfio-pci\n","YAML",[29,1235,1236,1241,1246],{"__ignoreMap":27},[32,1237,1238],{"class":34,"line":35},[32,1239,1240],{},"01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] [10de:2560]\n",[32,1242,1243],{"class":34,"line":49},[32,1244,1245],{},"        Subsystem: ...\n",[32,1247,1248],{"class":34,"line":224},[32,1249,1250],{},"        Kernel driver in use: vfio-pci\n",[10,1252,1253],{},"Use a similar command to check the audio device (10de:228e).",[22,1255,1257],{"className":24,"code":1256,"language":26,"meta":27,"style":27},"lspci -nnk | grep -A3 \"10de:228e\"\n",[29,1258,1259],{"__ignoreMap":27},[32,1260,1261,1263,1265,1267,1269,1271],{"class":34,"line":35},[32,1262,1212],{"class":38},[32,1264,1215],{"class":145},[32,1266,231],{"class":230},[32,1268,234],{"class":38},[32,1270,1222],{"class":145},[32,1272,1273],{"class":42}," \"10de:228e\"\n",[10,1275,1276,1277,1280],{},"If you see ",[29,1278,1279],{},"Kernel driver in use: vfio-pci",", it means the binding was successful.",[10,1282,1283],{},[157,1284,1285],{},"(4) Startup Options",[10,1287,1288,1289,1291],{},"In ",[29,1290,421],{},", add the following two lines:",[22,1293,1295],{"className":24,"code":1294,"language":26,"meta":27,"style":27},"\n    # 直通 NVIDIA 显卡\n    -device vfio-pci,host=01:00.0,multifunction=on,x-vga=on \\\n    -device vfio-pci,host=01:00.1 \\\n",[29,1296,1297,1301,1306,1315],{"__ignoreMap":27},[32,1298,1299],{"class":34,"line":35},[32,1300,215],{"emptyLinePlaceholder":214},[32,1302,1303],{"class":34,"line":49},[32,1304,1305],{"class":220},"    # 直通 NVIDIA 显卡\n",[32,1307,1308,1310,1313],{"class":34,"line":224},[32,1309,528],{"class":38},[32,1311,1312],{"class":42}," vfio-pci,host=01:00.0,multifunction=on,x-vga=on",[32,1314,468],{"class":145},[32,1316,1317,1319,1322],{"class":34,"line":240},[32,1318,528],{"class":145},[32,1320,1321],{"class":42}," vfio-pci,host=01:00.1",[32,1323,468],{"class":145},[1325,1326,1327],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":27,"searchDepth":49,"depth":49,"links":1329},[1330,1331,1332,1333,1334,1335,1336],{"id":16,"depth":224,"text":17},{"id":163,"depth":224,"text":164},{"id":296,"depth":224,"text":297},{"id":335,"depth":224,"text":336},{"id":758,"depth":224,"text":759},{"id":804,"depth":224,"text":805},{"id":827,"depth":224,"text":828},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","7",7000000,"2024-03-30","wiki/2024-03-30-linux-jiao-cheng","en-us:2024-03-30-linux-jiao-cheng","/en-us/wiki/2024-03-30-linux-jiao-cheng","Linux教程","md","wiki/2024-03-30-Linux教程/ch7-QEMU-KVM虚拟机",false,null,"en-US","en-us",{},{"title":5,"description":12},"/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","_i18n/en-us/wiki/2024-03-30-Linux教程/ch7-QEMU-KVM虚拟机","tUS4ZlT4Bph4ogiq4Hp9Gmp7tQFiKaBSO-SEFoI8Vsk",[1357,1362,1367,1373,1379,1385,1391,1392,1398,1403],{"path":1358,"stem":1359,"title":1360,"date":1340,"chapter":534,"chapterSort":1361,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch1-fa-xing-ban-tui-jian","_i18n/en-us/wiki/2024-03-30-Linux教程/ch1-发行版推荐","Distribution Recommendations",1000000,{"path":1363,"stem":1364,"title":1365,"date":1340,"chapter":509,"chapterSort":1366,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch2-linux-zhuang-ji-jiao-cheng","_i18n/en-us/wiki/2024-03-30-Linux教程/ch2-Linux装机教程","Linux Installation Tutorial",2000000,{"path":1368,"stem":1369,"title":1370,"date":1340,"chapter":1371,"chapterSort":1372,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch3-an-zhuang-bi-bei-pei-zhi","_i18n/en-us/wiki/2024-03-30-Linux教程/ch3-安装必备配置","Install required configuration","3",3000000,{"path":1374,"stem":1375,"title":1376,"date":1340,"chapter":1377,"chapterSort":1378,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch4-ming-ling-jiao-cheng-chang-qi-ji-lei","_i18n/en-us/wiki/2024-03-30-Linux教程/ch4-命令教程(长期积累)","Command Tutorial (Long-Term Accumulation)","4",4000000,{"path":1380,"stem":1381,"title":1382,"date":1340,"chapter":1383,"chapterSort":1384,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch5-ge-zhong-huan-jing-pei-zhi","_i18n/en-us/wiki/2024-03-30-Linux教程/ch5-各种环境配置","Various environment configurations","5",5000000,{"path":1386,"stem":1387,"title":1388,"date":1340,"chapter":1389,"chapterSort":1390,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch6-qi-ta-ke-xuan-pei-zhi","_i18n/en-us/wiki/2024-03-30-Linux教程/ch6-其他可选配置","Other optional configurations","6",6000000,{"path":1337,"stem":1354,"title":5,"date":1340,"chapter":1338,"chapterSort":1339,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},{"path":1393,"stem":1394,"title":1395,"date":1340,"chapter":1396,"chapterSort":1397,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch8-tuo-zhan-gong-neng","_i18n/en-us/wiki/2024-03-30-Linux教程/ch8-拓展功能","Extended Features","8",8000000,{"path":1399,"stem":1400,"title":828,"date":1340,"chapter":1401,"chapterSort":1402,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":1347},"/en-us/wiki/2024-03-30-linux-jiao-cheng/ch9-qi-ta-cao-zuo","_i18n/en-us/wiki/2024-03-30-Linux教程/ch9-其他操作","9",9000000,{"path":1343,"stem":1404,"title":1405,"date":1340,"chapter":1348,"chapterSort":1406,"docKey":1342,"docRoot":1343,"docTitle":1344,"isWikiDoc":214,"isWikiIndex":214},"_i18n/en-us/wiki/2024-03-30-Linux教程/index","Linux tutorial",0,{"variants":1408},[1409,1410,1413,1416,1419],{"path":1337,"localeSlug":1350,"i18nKey":1346},{"path":1411,"localeSlug":1412,"i18nKey":1346},"/zh-hant/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","zh-hant",{"path":1414,"localeSlug":1415,"i18nKey":1346},"/zh-hk/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","zh-hk",{"path":1417,"localeSlug":1418,"i18nKey":1346},"/zh-tw/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","zh-tw",{"path":1420,"localeSlug":1421,"i18nKey":1346},"/zh-cn/wiki/2024-03-30-linux-jiao-cheng/ch7-qemu-kvm-xu-ni-ji","zh-cn",[1337,1353,1411,1353,1414,1353,1417,1353,1420,1353],1780671796471]