Virtualizing artificial intelligence workloads in enterprise and homelab virtualization clusters presents a classic architectural dilemma: should you deploy inference engines like Ollama inside a full Hardware Virtual Machine (KVM) using direct PCIe GPU passthrough, or should you containerize within a lightweight Linux Container (LXC)? While running a full VM isolates guest operating systems, it introduces substantial overhead: 100% of guest RAM must be pre-allocated and pinned, GPU resources are monopolized by a solitary guest, and boot times take minutes. In Proxmox VE 9 and 8, running Ollama inside an unprivileged or privileged LXC container with direct host GPU render node sharing provides the holy grail: bare-metal inference execution, instantaneous container restarts, dynamic host memory allocation, and the ability to share a single Nvidia GPU across multiple containers simultaneously.
Running Ollama inside a Proxmox LXC container eliminates hypervisor CPU and memory virtualization overhead, achieving 100% identical token generation speeds to bare-metal Linux. By installing the Nvidia proprietary driver on the Proxmox host and passing character device nodes (/dev/nvidia* and /dev/dri/renderD128) into the container without kernel driver modules inside the guest, multiple LXC containers (such as Ollama, Plex, and Tdarr) can share the same GPU silicon without expensive enterprise vGPU licenses.
LXC Container vs. KVM Virtual Machine for AI Inference
The operational benefits of deploying Ollama in an LXC container compared to a VM include:
- Zero Memory Pinning: In a VM with GPU passthrough, if you assign 32GB of RAM, Proxmox locks all 32GB in host DDR5 memory permanently. In an LXC, Ollama consumes only the RAM it actively needs; when idle, unused memory is instantly returned to the Proxmox host ARC or other services.
- Multi-Container GPU Sharing: In a VM, passing through an RTX 4090 locks the card exclusively to that VM. With LXC device node mapping, your Ollama AI container, your Plex media transcoder, and your Whisper speech-to-text service can utilize the GPU concurrently.
- Near-Instantaneous Backups: Because an LXC container is simply a thin root filesystem on your ZFS pool, Proxmox can snapshot and replicate the container across backup nodes in under 4 seconds without freezing GPU compute queues.
Step-by-Step Deployment Blueprint: Nvidia Drivers on Proxmox 9 Host
Because the LXC container shares the host kernel, the Nvidia proprietary driver must be installed directly on the bare-metal Proxmox VE host first:
Step 1: Install Host Build Headers and Drivers
# Update repositories and install Proxmox kernel headers
apt update && apt install -y pve-headers-$(uname -r) build-essential dkms
# Blacklist open-source nouveau drivers
cat <<EOF > /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
EOF
update-initramfs -u
# Download and install official Nvidia Linux driver (e.g., version 550.x)
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/550.54.14/NVIDIA-Linux-x86_64-550.54.14.run
chmod +x NVIDIA-Linux-x86_64-550.54.14.run
./NVIDIA-Linux-x86_64-550.54.14.run --dkms -s --no-opengl-files
# Verify GPU detection on host
nvidia-smi
Step 2: Provision the Debian 12 LXC Container
In the Proxmox Web GUI, create a standard Debian 12 LXC container (CT ID 105). Allocate 8 CPU cores, 16GB RAM, and 50GB storage on your fastest NVMe pool. Tip: While unprivileged containers can be mapped with custom UID/GID mappings, creating a privileged container or setting idmap 0 100000 65536 simplifies device node permissions for CUDA access.
Step 3: Map Nvidia Device Nodes into the Container
Find the major and minor character numbers for your Nvidia devices on the Proxmox host using ls -l /dev/nv* and ls -l /dev/dri/. Standard Nvidia installations use major number 195 (for GPU devices) and 236/237 (for Nvidia UVM):
# Edit the container configuration file (/etc/pve/lxc/105.conf)
nano /etc/pve/lxc/105.conf
# Append the following passthrough directives:
lxc.cgroup2.devices.allow: c 195:* rwm
lxc.cgroup2.devices.allow: c 234:* rwm
lxc.cgroup2.devices.allow: c 236:* rwm
lxc.cgroup2.devices.allow: c 226:* rwm
# Bind mount device nodes
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-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
Step 4: Install Matching User-Space CUDA Libraries Inside LXC
Start the container and enter its shell: pct start 105 && pct enter 105. Inside the container, execute the exact same Nvidia installer script, but pass the --no-kernel-module flag to install only user-space CUDA runtime libraries without compiling kernel drivers:
# Inside the LXC container:
./NVIDIA-Linux-x86_64-550.54.14.run --no-kernel-module -s --no-opengl-files
# Verify CUDA communication inside container:
nvidia-smi
# Install Ollama native Linux binary:
curl -fsSL https://ollama.com/install.sh | sh
Production Hardening: Tuning Ollama Systemd Environment
By default, Ollama initializes with conservative single-user defaults. To turn your Proxmox LXC into a resilient network service accessible to all workstations on your LAN, customize the systemd unit file inside the container:
# In /etc/systemd/system/ollama.service.d/override.conf:
mkdir -p /etc/systemd/system/ollama.service.d
cat <<EOF > /etc/systemd/system/ollama.service.d/override.conf
[Service]
# Listen on all network interfaces
Environment="OLLAMA_HOST=0.0.0.0:11434"
# Allow cross-origin requests from web frontends
Environment="OLLAMA_ORIGINS=*"
# Keep loaded models resident in VRAM indefinitely
Environment="OLLAMA_KEEP_ALIVE=24h"
# Enable Flash Attention for 20% faster inference and lower VRAM usage
Environment="OLLAMA_FLASH_ATTENTION=1"
# Handle multiple concurrent client prompts
Environment="OLLAMA_NUM_PARALLEL=4"
EOF
systemctl daemon-reload
systemctl restart ollama
Monitoring and Benchmarking Inference Throughput
Jay Tech’s Proxmox AI Performance Checklist
- Verify Flash Attention Activation: Check container system logs using
journalctl -u ollama -e. Confirm that Ollama logs: “Flash attention enabled: true”, which dramatically reduces VRAM usage for deep context windows. - Monitor Real-Time GPU Compute & Thermals: Run
nvidia-smi dmon -s pucmton the Proxmox host. Monitor GPU power draw and PCIe bus utilization during sustained prompt processing. - ZFS Storage Dataset Allocation: Store the Ollama model cache (
/usr/share/ollama/.ollama/models) on an uncompressed ZFS dataset withrecordsize=1M. Model weights are large pre-compressed binary blobs; a 1MB record size matches sequential streaming reads, accelerating model loading times by 3x.
When deploying Ollama in production Proxmox environments, always bind the API service to internal bridge interfaces rather than public virtual network adapters. Implementing host-level iptables or UFW firewall rules ensures that only authorized internal IP subnets can trigger GPU inference tasks, protecting expensive compute resources from unauthorized third-party network requests.
Memory Ballooning and Kernel Samepage Merging in Proxmox AI Hosts
While LXC containers do not utilize traditional hypervisor memory ballooning drivers (such as virtio-balloon in KVM), managing host Linux page cache efficiency is vital when running high-throughput inference backends alongside other containers. By default, Linux aggressively caches disk reads in RAM. When Ollama reads a 40GB model file from storage into GPU VRAM, host page cache usage surges, occasionally triggering aggressive swap thrashing if host memory is tight.
To optimize Linux memory behavior on Proxmox VE AI nodes, configure vm.swappiness = 10 and vm.vfs_cache_pressure = 50 in /etc/sysctl.conf. This instructs the Linux kernel to favor keeping cached model pages in RAM while avoiding unnecessary page swapping to disk. If running multiple identical instances of Ollama across containers, Kernel Samepage Merging (KSM) can be enabled to deduplicate identical shared memory pages, though dedicated GPU VRAM remains untouched by CPU memory deduplication mechanisms.
Low-Level Troubleshooting: Character Devices and cgroup2 Permissions
The primary hurdle when passing Nvidia GPUs to Proxmox LXC containers is understanding Linux character device permissions. In Linux, graphics hardware is not represented as standard files; it is exposed through character devices in /dev/ assigned specific major and minor device node numbers. The core Nvidia driver stack requires five distinct device nodes:
/dev/nvidia0(Major 195, Minor 0): Direct communication with physical GPU 0./dev/nvidiactl(Major 195, Minor 255): Global Nvidia controller and telemetry interface./dev/nvidia-uvm(Major 236/234, Minor 0): Unified Virtual Memory interface, essential for CUDA memory allocation and tensor operations./dev/nvidia-uvm-tools(Major 236/234, Minor 1): UVM profiling and diagnostic hooks./dev/dri/renderD128(Major 226, Minor 128): Direct Rendering Infrastructure (DRI) node used by OpenCL and hardware video transcoders.
If any single one of these character devices is omitted from your container configuration (/etc/pve/lxc/<vmid>.conf) or lacks proper read/write permissions (rwm), Ollama will silently fail to detect CUDA, falling back to agonizingly slow CPU inference. If nvidia-smi inside the container reports “NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver,” verify that the major number in lxc.cgroup2.devices.allow matches the exact major number reported by ls -l /dev/nvidia-uvm on your Proxmox host.
Multi-Process Service (MPS): Concurrent Multi-Tenant Inference
When multiple containers or applications share an Nvidia GPU, Nvidia’s default driver model utilizes time-sliced context switching. If Ollama is generating tokens for one user, a secondary container (such as a local Whisper transcription bot) must wait for compute time-slices, introducing latency bubbles. In high-concurrency environments, enabling Nvidia Multi-Process Service (MPS) on the Proxmox host unlocks true spatial multitasking:
# Start Nvidia MPS Control Daemon on Proxmox Host:
export CUDA_MPS_PIPE_DIRECTORY=/tmp/nvidia-mps
export CUDA_MPS_LOG_DIRECTORY=/tmp/nvidia-log
nvidia-cuda-mps-control -d
# Verify MPS daemon is running:
ps aux | grep nvidia-cuda-mps
With MPS active, the GPU hardware scheduler merges CUDA kernels from multiple LXC containers into a single context, allowing simultaneous execution across available SMs (Streaming Multiprocessors) and eliminating context-switching penalties.
Automated Systemd Health Watchdog and VRAM Reclamation
In 24/7 homelab environments, complex multi-turn prompts or memory fragmentation can occasionally cause inference daemons to hang. Deploy an automated systemd watchdog inside your container by configuring WatchdogSec=30s in /etc/systemd/system/ollama.service and scheduling a daily VRAM cleanup script that unloads idle models via the Ollama API (curl http://localhost:11434/api/generate -d '{"model": "llama3.1", "keep_alive": 0}'), ensuring pristine memory pools for scheduled overnight batch tasks.

