How to set Nvidia GPU “Not” a primary GPU on Linux

Jetsada Malaisirirat
2 min readAug 11, 2022

--

ในบางระบบนั้นเราต้องการให้ GPU ที่ติดตั้งนั้นทำงานแค่ประมวลผลเท่านั้น ไม่ต้องแสดงผลออกหน้าจอ ส่วนหน้าจอจะให้ GPU on board ทำงานแสดงผลไป แต่เวลาเราติดตั้ง Driver ของ GPU Nvidia นั้น ตัว Driver จะตั้งค่าให้ GPU ของ Nvidia เป็น Primary GPU เช่นการติดตั้งบน Rocky Linux 8.6

ซึ่งปัญหาที่พบ ถ้าติดตั้งบน Physical host ก็จะต้องย้ายจอ Monitor ไปต่อกับการ์ดจอ Nvidia แทน แต่ถ้าบนระบบ Virtualization ที่ทำ GPU Passthrough ไปให้ VM เช่นบน Proxmox นั้น จะพบปัญหาที่ปวดหัวมากกว่านั่นก็คือ การแสดงผล Display หน้าจอนั้นจะถูกย้ายไปที่ GPU กลายเป็นหน้าจอแสดงผลหลักแทน ต้องต่อจอกับ GPU โดยตรงเพื่อแสดงผลหน้าจอ และหน้าจอที่ console remote จะเป็นหน้าจอดำ black screen การแก้ไขก็ต้องไม่ให้ GPU Nvidia เป็น Primary GPU

โดยเราจะติดตั้ง Driver Nvidia GPU ก่อน โดยติดตั้งผ่าน dnf จะเป็นวิธีที่ง่ายที่สุด ตามขั้นตอน ดังนี้

  1. Enable epel repo กับ CentOS-PowerTools
    # yum install -y epel-release
    # yum install dnf-plugins-core
    # yum config-manager — set-enabled powertools
  2. เขียนไฟล์ cuda-rhel8.repo
    # vi /etc/yum.repos.d/cuda-rhel8.repo

    [cuda-rhel8]
    name=cuda-rhel8-x86_64
    baseurl=https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64
    enabled=1
    gpgcheck=0
  3. ติดตั้ง Driver Nvidia
    # dnf -y module install nvidia-driver:latest-dkms

หลังจากติดตั้ง Driver เรียบร้อยแล้วให้แก้ไขไฟล์ /etc/X11/xorg.conf.d/10-nvidia.conf
บรรทัด Option “PrimaryGPU” จาก “yes” เป็น “no”
# vi /etc/X11/xorg.conf.d/10-nvidia.conf

Section “OutputClass”
Identifier “nvidia”
MatchDriver “nvidia-drm”
Driver “nvidia”
Option “AllowEmptyInitialConfiguration”
Option “PrimaryGPU” “no”
Option “SLI” “Auto”
Option “BaseMosaic” “on”
EndSection
Section “OutputClass”
Identifier “intel”
MatchDriver “i915”
Driver “modesetting”
EndSection

จากนั้น reboot เพื่อให้ระบบทำงานใหม่ การแสดงผลผ่าน remote console ที่เป็น GUI จะกลับมาแสดงผลได้ปกติ

สั่งคำสั่ง inxi -G จะแสดงว่า GPU หลักเป็นตัวอื่นที่ไม่ไช่ Nvidia GPU จากตัวอย่างจะเป็น gpu: bochs-drm

--

--