You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Proxmox中合并Bash与Perl虚拟机钩子脚本?

Merged Proxmox Hook Script: GPU Passthrough + Virtio-FS Setup

Here's a single Bash script combining both your GPU reset logic and virtio-fs setup, handling all hook phases from your original scripts:

#!/bin/bash

# Merged Proxmox hook script: GPU reset + virtio-fs initialization
echo "GUEST HOOK: $*"

VMID="$1"
PHASE="$2"

case "$PHASE" in
    pre-start)
        # Reset GPU for passthrough
        echo "gpu-hookscript: Resetting GPU for Virtual Machine $VMID"
        echo 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove
        echo 1 > /sys/bus/pci/rescan
        
        # Start virtio-fs daemon
        echo "$VMID is starting, doing preparations."
        /var/lib/vz/snippets/launch-virtio-daemon.sh
        ;;
    post-start)
        echo "$VMID started successfully."
        ;;
    pre-stop)
        echo "$VMID will be stopped."
        ;;
    post-stop)
        echo "$VMID stopped. Doing cleanup."
        ;;
    *)
        echo "Error: unknown phase '$PHASE'" >&2
        exit 1
        ;;
esac

exit 0

Setup Steps

  1. Save the script: Copy the code above into a file named merged-hookscript.sh in your Proxmox snippets directory (typically /var/lib/vz/snippets/).
  2. Make it executable: Run this command in your Proxmox shell:
    chmod +x /var/lib/vz/snippets/merged-hookscript.sh
    
  3. Assign to your VM: Replace <VMID> with your actual virtual machine number and run:
    qm set <VMID> -hookscript local:snippets/merged-hookscript.sh
    

Notes

  • Verify your GPU's PCI address (0000:01:00.0) is correct by running lspci in your Proxmox shell. Adjust the path in the script if needed.
  • Ensure the launch-virtio-daemon.sh script exists at /var/lib/vz/snippets/ and is also executable.

内容的提问来源于stack exchange,提问作者alpha754293

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 16:01:29