Maintained by Thijmen Heuvelink

Enhancing GPU Passthrough on Proxmox: A Comprehensive Guide for Nvidia GPUs Across Multiple LXCs with Shared GPU Access

Guide for Nvidia GPU Integration

System Specifications

Motherboard: Asrock B550M Pro4
CPU: Ryzen 5 5600G
RAM: 2x32GB 3200 DDR4
GPU: Nvidia 750 Ti (2GB)
Proxmox: 8.1.10

Acknowledgements

This guide benefited from various sources, including:

Introduction

This comprehensive guide aims to streamline the integration process of Nvidia GPUs with Proxmox and LXC containers. It condenses knowledge from various sources into a practical, step-by-step format for ease of implementation.

Installing Nvidia Drivers on the Proxmox Host

Download and Install Driver

  1. Visit Nvidia's Driver download page and select the appropriate driver for your GPU.

  2. Copy the download link and execute the following commands:

    wget <YOUR_DRIVER_DOWNLOAD_LINK> -O driver.run
    chmod +x ./driver.run
    sudo ./driver.run
    
  3. Follow on-screen prompts, selecting defaults as necessary. If prompted to overwrite X defaults, choose "yes."

Verification

Ensure the driver installation was successful by running:

nvidia-smi

The output should look similiar to this:

Output of nvidia-smi

Making the GPU Available to LXC Containers on Proxmox (Host Configuration)

For a detailed understanding of device and group identification, refer to Jim's video.

Identify Device Numbers

ls -l /dev/dri

Identify Group Numbers

cat /etc/group

Update Subgid

Edit the subgid file:

nano /etc/subgid

Replace values with those obtained earlier.

Edit LXC Configuration

Edit the LXC configuration file:

nano /etc/pve/lxc/<lxc-id>.conf

Add the following lines:

lxc.cgroup2.devices.allow: c 226:0 rwm
lxc.cgroup2.devices.allow: c 226:128 rwm
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
lxc.idmap: u 0 100000 65536
lxc.idmap: g 0 100000 44
lxc.idmap: g 44 44 1
lxc.idmap: g 45 100045 62
lxc.idmap: g 107 104 1
lxc.idmap: g 108 100108 65428
lxc.mount.entry: /dev/nvidia0 dev/nvidia0 none bind,optional,create=file
lxc.mount.entry: /dev/nvidiactl dev/nvidiactl none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-uvm dev/nvidia-uvm none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-modeset dev/nvidia-modeset none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file

Add Root to Groups

Grant root user access to necessary groups:

usermod -aG render,video root

Setting up Your LXC

System Specifications

OS: Ubuntu 22.04

Install Nvidia Docker Container Toolkit

Follow the installation guide here, adapting steps as necessary.

Installing Nvidia Driver (LXC)

Ensure consistency of Nvidia driver versions between Proxmox host and LXC.

  1. Download and install the driver:

    wget <YOUR_DRIVER_DOWNLOAD_LINK> -O driver.run
    chmod +x ./driver.run
    sudo ./driver.run --no-kernel-module
    
  2. Follow prompts, using default settings. Use the flag "--no-kernel-module" to prevent kernel reinstallation.

Verification

Confirm driver installation within LXC:

nvidia-smi

The output should look similiar to this:

Output of nvidia-smi

Conclusion

Your LXC container is now configured to utilize the Nvidia GPU effectively. For scaling to additional LXCs, repeat the configuration steps outlined above.

For further inquiries or assistance, feel free to reach out:

This knowledge base serves as a valuable tool to simplify installations, troubleshoot common problems and to enhance the overall developer / admin experience. mail@thijmenheuvelink.nl - all rights reserved